Skip to content

Commit

Permalink
gs-reactor: Improve TextPropertyDefaults and GenericStringDefaults
Browse files Browse the repository at this point in the history
  • Loading branch information
fducroquet committed Aug 17, 2016
1 parent c170416 commit 784ecca
Show file tree
Hide file tree
Showing 24 changed files with 108 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public GSModal(GSTag parent, FlexDirection direction, Consumer<GSTag> contentTag
new GSHyperLink(this) {
{
addStyleClass("close");
setText(this, "×");
setText("×");
bindAction(model -> getSelectionProperty(model).setValue(null));
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,55 +31,55 @@ public GSUserGuide(GSTag parent) {
new HtmlHyperLink<GenericModel>(this) {
{
addStyleClass("close");
setText(this, "×");
setText("×");
bindAction(model -> {
this.getParent().getProperty(ReactorStatics.DISPLAY, model).setValue("none");
});
}
};
new GSSection(this, FlexDirection.COLUMN) {
{
setText(this, "How to use CarColor Demo");
setText("How to use CarColor Demo");
new GSUl(this) {
{
setText(this, "Car(s) Managment");
setText("Car(s) Managment");
GSLi li1 = new GSLi(this);
GSLi li2 = new GSLi(this);
GSLi li3 = new GSLi(this);
setText(li1, "Insert Car model");
setText(li2, "Select color in the ComboBox");
setText(li3, "Use \"add Button\" to update data");
li1.setText("Insert Car model");
li2.setText("Select color in the ComboBox");
li3.setText("Use \"add Button\" to update data");
}
};
new GSUl(this) {
{
setText(this, "Color Managment");
setText("Color Managment");
GSLi li1 = new GSLi(this);
GSLi li2 = new GSLi(this);
GSLi li3 = new GSLi(this);
setText(li1, "Add new color");
setText(li2, "Select car in the ComboBox");
setText(li3, "Use \"add Button\" to update data");
li1.setText("Add new color");
li2.setText("Select car in the ComboBox");
li3.setText("Use \"add Button\" to update data");
}
};
new GSUl(this) {
{
setText(this, "Global Tips");
setText("Global Tips");
GSLi li1 = new GSLi(this);
GSLi li2 = new GSLi(this);
GSLi li3 = new GSLi(this);
GSLi li4 = new GSLi(this);
setText(li1, "Use \"Add Button\" to add an entry in the cache");
setText(li2, "Use the \"Remove Button\" to delete the entry in your cache");
setText(li3, "Use \"Save Button\" to persist the cache");
setText(li4, "Use \"Cancel Button\" to release the cache");
li1.setText("Use \"Add Button\" to add an entry in the cache");
li2.setText("Use the \"Remove Button\" to delete the entry in your cache");
li3.setText("Use \"Save Button\" to persist the cache");
li4.setText("Use \"Cancel Button\" to release the cache");

}
};
new GSSection(this, FlexDirection.COLUMN) {
{
addStyle("text-align", "center");
setText(this, "To plenty enjoy the power of GS-REACTOR, go to Learning / Get Started");
setText("To plenty enjoy the power of GS-REACTOR, go to Learning / Get Started");
}
};
}
Expand All @@ -91,7 +91,7 @@ public GSUserGuide(GSTag parent) {

new GSButton(this) {
{
setText(this, "User Guide");
setText("User Guide");
addStyleClass("buttonUser");
addStyle("flex", "1/3");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ public Collection<Map<String, ObservableValue<Object>>> getPropertiesMaps() {
return propertiesMap.values();
}

public void storeProperty(Tag<?> tag, String propertyName, ObservableValue<?> value) {
protected void storeProperty(Tag<?> tag, String propertyName, ObservableValue<?> value) {
assert viewContextsMap.keySet().contains(tag);
if (getProperties(tag).containsKey(propertyName))
throw new IllegalStateException("Unable to store an already used property : " + propertyName);
getProperties(tag).put(propertyName, (ObservableValue) value);
}

protected <T> void storePropertyWithoutCheck(Tag<?> tag, String propertyName, ObservableValue<T> value) {
assert viewContextsMap.keySet().contains(tag);
getProperties(tag).put(propertyName, (ObservableValue) value);
}

public List<Model> subContexts() {
return subModelsMap.values().stream().flatMap(list -> list.stream()).collect(Collectors.toList());
}
Expand Down
12 changes: 12 additions & 0 deletions gs-reactor/src/main/java/org/genericsystem/reactor/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public ServerWebSocket getWebSocket() {
return getParent().getWebSocket();
}

@Override
public void addPrefixBinding(Consumer<M> consumer) {
preFixedBindings.add((modelContext, node) -> consumer.accept((M) modelContext));
}
Expand Down Expand Up @@ -146,6 +147,7 @@ protected <SUBMODEL extends Model> void setSubModels(Model model, Tag<?> child,
model.setSubContexts(child, subModels);
}

@Override
public <T> Property<T> getProperty(String propertyName, Model model) {
return getProperty(propertyName, new Model[] { model });
}
Expand Down Expand Up @@ -244,6 +246,11 @@ public <T> void storeProperty(String propertyName, Function<M, ObservableValue<T
addPrefixBinding(modelContext -> modelContext.storeProperty(this, propertyName, applyOnModel.apply(modelContext)));
}

@Override
public <T> void storePropertyWithoutCheck(String propertyName, M model, Function<M, ObservableValue<T>> applyOnModel) {
model.storePropertyWithoutCheck(this, propertyName, applyOnModel.apply(model));
}

public void addStyle(String propertyName, String value) {
addPrefixBinding(model -> model.getObservableStyles(this).put(propertyName, value));
}
Expand Down Expand Up @@ -309,6 +316,11 @@ public Boolean fromString(String string) {
});
}

@Override
public ViewContext getViewContext(M model) {
return model.getViewContext(this);
}

protected abstract HtmlDomNode createNode(String parentId);

protected List<Tag<?>> getChildren() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public GSBooleanHolderEditorWithRemoval(GSTag parent) {
addStyle("justify-content", "center");
addStyle("text-decoration", "none");
addStyle("height", "100%");
setText(this, "×");
setText("×");
bindAction(GenericModel::remove);
}
};
Expand All @@ -70,7 +70,7 @@ public GSBooleanHolderAdder(GSTag parent) {
addStyle("justify-content", "center");
addStyle("text-decoration", "none");
addStyle("height", "100%");
setText(this, "+");
setText("+");
bindAction(model -> {
Property<Boolean> observable = checkbox.getProperty(ReactorStatics.VALUE, model);
Boolean newValue = observable.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected void sections() {
forEach(GSComposite.this);
new GSLabel(this) {
{
bindGenericText(this);
bindGenericText();
}
};
}
Expand Down Expand Up @@ -63,8 +63,8 @@ protected void header() {
addStyle("background-color", "#ffa500");
new GSH1(this) {
{
setStringExtractor(this, StringExtractor.MANAGEMENT);
bindGenericText(this);
setStringExtractor(StringExtractor.MANAGEMENT);
bindGenericText();
}
};
};
Expand All @@ -86,11 +86,11 @@ public ColorTitleCompositeFlexElement(GSTag parent) {
protected void sections() {
new GSSection(this, ColorTitleCompositeFlexElement.this.getReverseDirection()) {
{
bindStyle("background-color", ReactorStatics.BACKGROUND, model -> getGenericStringProperty(this, model));
bindStyle("background-color", ReactorStatics.BACKGROUND, model -> getGenericStringProperty(model));
forEach(ColorTitleCompositeFlexElement.this);
new GSLabel(this) {
{
bindGenericText(this);
bindGenericText();
}
};
}
Expand All @@ -112,7 +112,7 @@ protected void sections() {
new GSRadio(this);
new GSLabel(this) {
{
bindGenericText(this);
bindGenericText();
}
};
}
Expand Down Expand Up @@ -146,11 +146,11 @@ protected void sections() {
flexSubElement = new GSSection(this, ColorCompositeRadio.this.getReverseDirection()) {
{
forEach(ColorCompositeRadio.this);
bindStyle("background-color", ReactorStatics.BACKGROUND, model -> getGenericStringProperty(this, model));
bindStyle("background-color", ReactorStatics.BACKGROUND, model -> getGenericStringProperty(model));
new GSRadio(this);
new GSLabel(this) {
{
bindGenericText(this);
bindGenericText();
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ protected void header() {
addStyle("align-items", "center");
new GSH1(this) {
{
setStringExtractor(this, StringExtractor.TYPE_INSTANCE_EXTRACTOR);
bindGenericText(this);
setStringExtractor(StringExtractor.TYPE_INSTANCE_EXTRACTOR);
bindGenericText();
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public GSHolderEditorWithRemoval(GSTag parent) {
addStyle("justify-content", "center");
addStyle("text-decoration", "none");
addStyle("height", "100%");
setText(this, "×");
setText("×");
bindAction(GenericModel::remove);
}
};
Expand All @@ -63,7 +63,7 @@ public GSHolderAdder(GSTag parent) {
addStyle("justify-content", "center");
addStyle("text-decoration", "none");
addStyle("height", "100%");
setText(this, "+");
setText("+");
bindAction(model -> {
Property<Serializable> observable = input.getProperty(ReactorStatics.VALUE, model);
if (observable.getValue() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected void footer() {
}
instanceValueInput.input.getProperty(ReactorStatics.VALUE, model).setValue(null);
});
setText(this, "Add");
setText("Add");
addStyle("width", "100%");
addStyle("height", "100%");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public GSLinkEditorWithRemoval(GSTag parent) {
addStyle("justify-content", "center");
addStyle("text-decoration", "none");
addStyle("height", "100%");
setText(this, "×");
setText("×");
bindAction(GenericModel::remove);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public GSMonitor(GSTag parent, FlexDirection direction) {
addStyle("padding", "10px");
new GSButton(this) {
{
setText(this, "Save");
setText("Save");
bindAction(GenericModel::flush);
}
};
new GSButton(this) {
{
setText(this, "Cancel");
setText("Cancel");
bindAction(GenericModel::cancel);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected SelectableHtmlDomNode createNode(String parentId) {
protected void options() {
optionElement = new GSOption(this) {
{
bindGenericText(this);
bindGenericText();
forEach(GSSelect.this);
}
};
Expand All @@ -59,7 +59,7 @@ public CompositeSelectWithEmptyEntry(GSTag parent) {
});
optionElement.addPrefixBinding(model -> {
if ("Color".equals(StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(model.getGeneric().getMeta())))
model.getObservableStyles(optionElement).put("background-color", getGenericStringProperty(optionElement, model).getValue());
model.getObservableStyles(optionElement).put("background-color", optionElement.getGenericStringProperty(model).getValue());
});
}

Expand All @@ -80,7 +80,7 @@ public static class ColorsSelect extends GSSelect {
public ColorsSelect(GSTag parent) {
super(parent);
bindStyle("background-color", ReactorStatics.SELECTION_STRING);
optionElement.bindStyle("background-color", ReactorStatics.BACKGROUND, model -> getGenericStringProperty(optionElement, model));
optionElement.bindStyle("background-color", ReactorStatics.BACKGROUND, model -> optionElement.getGenericStringProperty(model));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public GSSingleLinkComponentEditor(GSTag parent, GSSelectConstructor constructor
});
select.optionElement.addPrefixBinding(model -> {
if ("Color".equals(StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(model.getGeneric().getMeta())))
model.getObservableStyles(select.optionElement).put("background-color", getGenericStringProperty(select.optionElement, model).getValue());
model.getObservableStyles(select.optionElement).put("background-color", select.optionElement.getGenericStringProperty(model).getValue());
});
select.addStyle("width", "100%");
select.addStyle("height", "100%");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public GSInstanceSubcellDisplayer(GSTag parent) {
public void style(GSTag tag) {
super.style(tag);
tag.addPrefixBinding(modelContext -> ((Model) modelContext).getObservableStyles(tag).put("background-color",
"Color".equals(StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(modelContext.getGeneric().getMeta())) ? getGenericStringProperty(tag, modelContext).getValue() : "#dda5e2"));
"Color".equals(StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(modelContext.getGeneric().getMeta())) ? tag.getGenericStringProperty(modelContext).getValue() : "#dda5e2"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ protected void titleHeader() {
addStyle("justify-content", "center");
new GSH1(this) {
{
setStringExtractor(this, StringExtractor.MANAGEMENT);
bindGenericText(this);
setStringExtractor(StringExtractor.MANAGEMENT);
bindGenericText();
}
};
}
Expand All @@ -67,7 +67,7 @@ protected void header() {
addStyle("align-items", "center");
new GSLabel(this) {
{
bindGenericText(this);
bindGenericText();
}
};

Expand Down Expand Up @@ -125,10 +125,10 @@ protected void header() {
addStyle("margin-bottom", "1px");
addStyle("overflow", "hidden");
addPrefixBinding(modelContext -> modelContext.getObservableStyles(this).put("background-color",
"Color".equals(StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(modelContext.getGeneric().getMeta())) ? getGenericStringProperty(this, modelContext).getValue() : "#bba5ff"));
"Color".equals(StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(modelContext.getGeneric().getMeta())) ? getGenericStringProperty(modelContext).getValue() : "#bba5ff"));
new GSHyperLink(this) {
{
bindGenericText(this);
bindGenericText();
bindAction(model -> getSelectionProperty(model).setValue(model));
}
};
Expand Down Expand Up @@ -168,7 +168,7 @@ protected void footer() {
addStyle("margin-bottom", "1px");
new GSButton(this) {
{
setText(this, "Remove");
setText("Remove");
bindAction(GenericModel::remove);
addStyle("width", "100%");
addStyle("height", "100%");
Expand Down
Loading

0 comments on commit 784ecca

Please sign in to comment.