Skip to content

Commit

Permalink
fix pb with previous in switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
nfeybesse committed Jan 12, 2017
1 parent 6caefae commit f25a2f0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
13 changes: 7 additions & 6 deletions gs-quiz/src/main/java/org/genericsystem/quiz/app/SwitchApp.java
Expand Up @@ -12,6 +12,7 @@
import org.genericsystem.reactor.annotations.Children;
import org.genericsystem.reactor.annotations.ForEach;
import org.genericsystem.reactor.annotations.RunScript;
import org.genericsystem.reactor.annotations.SetText;
import org.genericsystem.reactor.annotations.Step;
import org.genericsystem.reactor.annotations.Switch;
import org.genericsystem.reactor.annotations.Switcher;
Expand Down Expand Up @@ -56,28 +57,28 @@ public static class StepDiv extends HtmlDiv {

}

@Step(nextClass = SwitchDiv2.class)
@Step(next = SwitchDiv2.class)
public static class SwitchDiv1 extends StepDiv {

}

@Step(nextClass = SwitchDiv3.class)
@Step(next = SwitchDiv3.class)
public static class SwitchDiv2 extends StepDiv {

}

@Step(nextClass = SwitchDiv4.class)
@Step(next = SwitchDiv4.class)
public static class SwitchDiv3 extends StepDiv {

}

@Step(nextClass = SwitchDiv5.class)
@ForEach(ObservableListExtractor.COMPONENTS.class)
@Step(next = SwitchDiv5.class)
@ForEach(ObservableListExtractor.INSTANCES.class)
public static class SwitchDiv4 extends StepDiv {

}

@Step(nextClass = SwitchDiv5.class)
@Step(next = SwitchDiv5.class)
@ForEach(ObservableListExtractor.INSTANCES.class)
public static class SwitchDiv5 extends StepDiv {

Expand Down
Expand Up @@ -8,6 +8,12 @@
import java.util.function.BiConsumer;
import java.util.function.Function;

import javafx.beans.binding.Bindings;
import javafx.beans.binding.ListBinding;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import org.genericsystem.defaults.tools.BindingsTools;
import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.Tag;
Expand All @@ -16,12 +22,6 @@
import org.genericsystem.reactor.gscomponents.Controller.SwitchStep;
import org.genericsystem.reactor.gscomponents.TagImpl;

import javafx.beans.binding.Bindings;
import javafx.beans.binding.ListBinding;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@Process(StepProcessor.class)
Expand All @@ -30,7 +30,7 @@

int[] pos() default {};

Class<? extends TagImpl> nextClass();
Class<? extends TagImpl> next();

String prevText() default "<<";

Expand All @@ -45,7 +45,7 @@ public void accept(Annotation annotation, Tag tag) {
Controller controller = Controller.get(tag, context);
SwitchStep subSteps = controller.getSwitchStep(tag);
if (subSteps == null)
subSteps = controller.addSwitchStep(tag, new SimpleIntegerProperty(1), ((Step) annotation).nextClass(), ((Step) annotation).prevText(), ((Step) annotation).nextText());
subSteps = controller.addSwitchStep(tag, new SimpleIntegerProperty(1), ((Step) annotation).next(), ((Step) annotation).prevText(), ((Step) annotation).nextText());
});
} else {
Function<Context, ObservableList<Object>> contextOl = tag.getMetaBinding().getBetweenChildren();
Expand All @@ -54,7 +54,7 @@ public void accept(Annotation annotation, Tag tag) {
Controller controller = Controller.get(tag, context);
SwitchStep subSteps = controller.getSwitchStep(tag);
if (subSteps == null)
subSteps = controller.addSwitchStep(tag, Bindings.size(ol), ((Step) annotation).nextClass(), ((Step) annotation).prevText(), ((Step) annotation).nextText());
subSteps = controller.addSwitchStep(tag, Bindings.size(ol), ((Step) annotation).next(), ((Step) annotation).prevText(), ((Step) annotation).nextText());
SimpleIntegerProperty indexProperty = subSteps.getIndexProperty();
return BindingsTools.transmitSuccessiveInvalidations(new ListBinding() {
{
Expand Down
Expand Up @@ -2,13 +2,6 @@

import java.util.Map.Entry;

import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.annotations.Switcher;
import org.genericsystem.reactor.context.ContextAction;
import org.genericsystem.reactor.context.TagSwitcher;
import org.genericsystem.reactor.context.TextBinding;

import javafx.beans.binding.Bindings;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleIntegerProperty;
Expand All @@ -18,6 +11,13 @@
import javafx.collections.FXCollections;
import javafx.collections.ObservableMap;

import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.annotations.Switcher;
import org.genericsystem.reactor.context.ContextAction;
import org.genericsystem.reactor.context.TagSwitcher;
import org.genericsystem.reactor.context.TextBinding;

public class Controller {
private final Class<? extends TagImpl> firstClass;
private final Property<Class<? extends Tag>> classProperty;
Expand Down Expand Up @@ -79,7 +79,7 @@ public SwitchStep getStep(Class<? extends TagImpl> clazz) {

public SwitchStep getPreviousStep(Class<? extends Tag> clazz) {
for (Entry<Tag, SwitchStep> entry : switcherSteps.entrySet())
if (entry.getValue().getNextClass().equals(clazz))
if (entry.getValue().getNextClass().equals(clazz) && !entry.getValue().getNextClass().equals(entry.getValue().getTag().getClass()))
return entry.getValue();
return null;
}
Expand Down Expand Up @@ -114,7 +114,7 @@ public SwitchStep(Tag tag, ObservableIntegerValue observableSize, Class<? extend
this.observableSize = observableSize;
this.nextClass = nextClass;
this.hasPrev = Bindings.createBooleanBinding(() -> {
return /* !tag.getClass().equals(previousClass) || */ (getIndexProperty().get() > 0);
return getPreviousStep(tag.getClass()) != null || (getIndexProperty().get() > 0);
}, getIndexProperty());
this.hasNext = Bindings.createBooleanBinding(() -> {
return !tag.getClass().equals(nextClass) || (getIndexProperty().get() + 1 < getObservableSize().get());
Expand Down

0 comments on commit f25a2f0

Please sign in to comment.