Skip to content

Commit

Permalink
gs-reactor: Use SELECTION constant only in SelectionDefaults
Browse files Browse the repository at this point in the history
  • Loading branch information
fducroquet committed Aug 9, 2016
1 parent 3d3b45c commit f682d40
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.genericsystem.carcolor.model.Power;
import org.genericsystem.common.Generic;
import org.genericsystem.common.Root;
import org.genericsystem.reactor.ReactorStatics;
import org.genericsystem.reactor.annotations.DependsOnModel;
import org.genericsystem.reactor.annotations.RunScript;
import org.genericsystem.reactor.appserver.ApplicationServer;
Expand All @@ -17,6 +16,7 @@
import org.genericsystem.reactor.gs.GSEditor;
import org.genericsystem.reactor.gs.GSMonitor;
import org.genericsystem.reactor.gs.GSTable;
import org.genericsystem.reactor.gs.SelectionDefaults;

import io.vertx.core.http.ServerWebSocket;

Expand All @@ -26,15 +26,15 @@
*/
@RunScript(CarColorScript.class)
@DependsOnModel({ Car.class, Power.class, Color.class, CarColor.class })
public class CarColorApp extends GSApp {
public class CarColorApp extends GSApp implements SelectionDefaults {

public static void main(String[] mainArgs) {
ApplicationServer.sartSimpleGenericApp(mainArgs, CarColorApp.class, "/cars");
}

public CarColorApp(Root engine, ServerWebSocket webSocket) {
super(webSocket);
createNewProperty(ReactorStatics.SELECTION);
createSelectionProperty();
addStyle("background-color", "#3393ff");

new GSHeader(this, "Generic System Reactor Live Demo", null, "", GSUserGuide::new, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public GSModal(GSTag parent, Consumer<GSTag> contentTagConsumer) {
public GSModal(GSTag parent, FlexDirection direction, Consumer<GSTag> contentTagConsumer) {
super(parent, direction);
addStyleClass("modal");
bindStyle(ReactorStatics.DISPLAY, ReactorStatics.DISPLAY, model -> Bindings.createStringBinding(() -> getSelectionProperty(model).getValue() != null ? "flex" : "none", this.getProperty(ReactorStatics.SELECTION, model)));
bindStyle(ReactorStatics.DISPLAY, ReactorStatics.DISPLAY, model -> Bindings.createStringBinding(() -> getSelectionProperty(model).getValue() != null ? "flex" : "none", getSelectionProperty(model)));

new GSSection(this, FlexDirection.COLUMN) {
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class ReactorStatics {
public static final String INVALID = "invalid";
public static final String INVALID_LIST = "invalidList";
public static final String NEW_INSTANCE = "newInstance";
public static final String SELECTION = "selection";
public static final String SELECTION_INDEX = "selectionIndex";
public static final String SELECTION_SHIFT = "selectionShift";
public static final String SELECTION_STRING = "selectionString";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,8 @@ public ColorCompositeRadio(GSTag parent, FlexDirection flexDirection) {
createSelectionProperty();
storeProperty(ReactorStatics.SELECTION_INDEX, model -> model.getSelectionIndex(this));
bindBiDirectionalSelection(flexSubElement);
storeProperty(
ReactorStatics.SELECTION_STRING,
model -> Bindings.createStringBinding(() -> StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(getSelectionProperty(model).getValue() != null ? getSelectionProperty(model).getValue().getGeneric() : null),
getProperty(ReactorStatics.SELECTION, model)));
storeProperty(ReactorStatics.SELECTION_STRING,
model -> Bindings.createStringBinding(() -> StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(getSelectionProperty(model).getValue() != null ? getSelectionProperty(model).getValue().getGeneric() : null), getSelectionProperty(model)));
bindStyle("background-color", ReactorStatics.SELECTION_STRING);
addStyle("padding", "4px");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import org.genericsystem.reactor.ReactorStatics;
import org.genericsystem.reactor.gstag.GSOption;
import org.genericsystem.reactor.model.GenericModel;
import org.genericsystem.reactor.model.ObservableListExtractor;
import org.genericsystem.reactor.model.StringExtractor;

Expand All @@ -23,8 +22,8 @@ private GSSelect(GSTag parent) {
createSelectionProperty();
storeProperty(ReactorStatics.SELECTION_INDEX, model -> model.getSelectionIndex(this));
bindBiDirectionalSelection(optionElement);
storeProperty(ReactorStatics.SELECTION_STRING, model -> Bindings.createStringBinding(
() -> StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(getSelectionProperty(model).getValue() != null ? ((GenericModel) getProperty(ReactorStatics.SELECTION, model).getValue()).getGeneric() : null), getSelectionProperty(model)));
storeProperty(ReactorStatics.SELECTION_STRING,
model -> Bindings.createStringBinding(() -> StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(getSelectionProperty(model).getValue() != null ? getSelectionProperty(model).getValue().getGeneric() : null), getSelectionProperty(model)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public GSSingleLinkComponentEditor(GSTag parent, GSSelectConstructor constructor
select.addPostfixBinding(model -> {
Property<List<Property<GenericModel>>> selectedComponents = getProperty(ReactorStatics.COMPONENTS, model.getParent());
if (selectedComponents != null)
selectedComponents.getValue().add(select.getProperty(ReactorStatics.SELECTION, model));
selectedComponents.getValue().add(select.getSelectionProperty(model));
});
new GSLabelDisplayer(this) {
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
public interface SelectionDefaults {

public static final String SELECTION = "selection";

// void addPrefixBinding(Consumer<GenericModel> consumer);

void addPostfixBinding(Consumer<GenericModel> consumer);
Expand All @@ -29,11 +31,11 @@ public interface SelectionDefaults {
<T> Property<T> getProperty(String property, Model model);

default void createSelectionProperty() {
createNewProperty(ReactorStatics.SELECTION);
createNewProperty(SELECTION);
}

default Property<GenericModel> getSelectionProperty(GenericModel model) {
return getProperty(ReactorStatics.SELECTION, model);
return getProperty(SELECTION, model);
}

default void bindBiDirectionalSelection(Tag<GenericModel> subElement) {
Expand Down

0 comments on commit f682d40

Please sign in to comment.