-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gs-reactor: Beginning of step by step edition of an instance
- Loading branch information
1 parent
de8b52c
commit 80ada71
Showing
4 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
gs-reactor/src/main/java/org/genericsystem/reactor/gs/GSStepEditor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.genericsystem.reactor.gs; | ||
|
||
import org.genericsystem.reactor.gs.GSSubcellDisplayer.InstanceLinkTitleDisplayer; | ||
import org.genericsystem.reactor.gstag.GSHyperLink; | ||
|
||
public class GSStepEditor extends GSEditor implements SwitchDefaults { | ||
|
||
private GSTag switchedTag; | ||
|
||
public GSStepEditor(GSTag parent) { | ||
this(parent, FlexDirection.COLUMN); | ||
} | ||
|
||
public GSStepEditor(GSTag parent, FlexDirection direction) { | ||
super(parent, direction); | ||
} | ||
|
||
@Override | ||
public GSTag getSwitchedTag() { | ||
return switchedTag; | ||
} | ||
|
||
@Override | ||
protected void sections() { | ||
switchedTag = new GSSection(this, getDirection()) { | ||
{ | ||
addStyle("flex", "1"); | ||
new InstanceLinkTitleDisplayer(this).addStyle("flex", "0.3"); | ||
new GSAttributeOfInstanceEditor(this); | ||
new GSSection(this, getReverseDirection()) { | ||
{ | ||
addStyle("justify-content", "space-between"); | ||
new GSHyperLink(this) { | ||
{ | ||
setText("<"); | ||
bindAction(model -> prev(model)); | ||
} | ||
}; | ||
new GSHyperLink(this) { | ||
{ | ||
setText(">"); | ||
bindAction(model -> next(model)); | ||
} | ||
}; | ||
} | ||
}; | ||
} | ||
}; | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
gs-reactor/src/main/java/org/genericsystem/reactor/gs/SwitchDefaults.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.genericsystem.reactor.gs; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
import org.genericsystem.reactor.Model; | ||
import org.genericsystem.reactor.model.GenericModel; | ||
import org.genericsystem.reactor.model.ObservableListExtractor; | ||
|
||
import javafx.beans.property.Property; | ||
import javafx.beans.property.ReadOnlyIntegerWrapper; | ||
import javafx.beans.property.SimpleObjectProperty; | ||
import javafx.beans.value.ObservableValue; | ||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
|
||
public interface SwitchDefaults { | ||
|
||
public static final String SUBMODELS = "subModels"; | ||
public static final String INDEX = "index"; | ||
public static final String CURRENT_MODEL = "currentModel"; | ||
|
||
void addPrefixBinding(Consumer<GenericModel> consumer); | ||
|
||
<T> void storePropertyWithoutCheck(String propertyName, GenericModel model, Function<GenericModel, ObservableValue<T>> applyOnModel); | ||
|
||
<T> Property<T> getProperty(String property, Model model); | ||
|
||
GSTag getSwitchedTag(); | ||
|
||
default ObservableList<GenericModel> getSwitchModels(GenericModel model) { | ||
Property<ObservableList<GenericModel>> modelsProperty = getProperty(SUBMODELS, model); | ||
return modelsProperty != null ? modelsProperty.getValue() : null; | ||
} | ||
|
||
default Property<GenericModel> getCurrentModel(GenericModel model) { | ||
return getProperty(CURRENT_MODEL, model); | ||
} | ||
|
||
default Property<Integer> getIteratorIndexProperty(GenericModel model) { | ||
return getProperty(INDEX, model); | ||
} | ||
|
||
default void switcher_(ObservableListExtractor observableListExtractor) { | ||
switcher(model -> FXCollections.observableArrayList(observableListExtractor.apply(model.getGenerics()).stream().map(g -> new GenericModel(model, GenericModel.addToGenerics(g, model.getGenerics()))).collect(Collectors.toList()))); | ||
} | ||
|
||
default void switcher(Function<GenericModel, ObservableList<GenericModel>> applyOnModel) { | ||
addPrefixBinding(model -> { | ||
storePropertyWithoutCheck(SUBMODELS, model, m -> new SimpleObjectProperty<>(applyOnModel.apply(model))); | ||
storePropertyWithoutCheck(CURRENT_MODEL, model, m -> new SimpleObjectProperty<>(getSwitchModels(model).get(0))); | ||
storePropertyWithoutCheck(INDEX, model, m -> new ReadOnlyIntegerWrapper(0)); | ||
}); | ||
getSwitchedTag().select_(model -> getCurrentModel(model)); | ||
} | ||
|
||
default void next(GenericModel model) { | ||
Property<Integer> index = getIteratorIndexProperty(model); | ||
ObservableList<GenericModel> models = getSwitchModels(model); | ||
if (index.getValue() + 1 < models.size()) { | ||
index.setValue(index.getValue() + 1); | ||
getCurrentModel(model).setValue(models.get(index.getValue())); | ||
} | ||
} | ||
|
||
default void prev(GenericModel model) { | ||
Property<Integer> index = getIteratorIndexProperty(model); | ||
ObservableList<GenericModel> models = getSwitchModels(model); | ||
if (index.getValue() > 0) { | ||
index.setValue(index.getValue() - 1); | ||
getCurrentModel(model).setValue(models.get(index.getValue())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters