Skip to content

Commit

Permalink
gs-reactor: Add new holders/links automatically
Browse files Browse the repository at this point in the history
Add boolean holders on value change, other holders on enter and onblur events.
Add links as soon as all the components are selected.
Delete the “+” hyperlink to create links since it is never shown.
  • Loading branch information
fducroquet committed Aug 10, 2016
1 parent b233957 commit efc4484
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public static class GSBooleanHolderAdder extends GSBooleanHolderEditor {

public GSBooleanHolderAdder(GSTag parent) {
super(parent, GSCheckBoxWithValue::new);
checkbox.addPropertyChangeListener(ReactorStatics.VALUE, (model, nva) -> {
if (nva != null)
model.getGenerics()[1].addHolder(model.getGeneric(), nva);
});
new GSHyperLink(this) {
{
addStyle("justify-content", "center");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public static class GSHolderAdder extends GSHolderEditor {

public GSHolderAdder(GSTag parent) {
super(parent, GSInputTextWithConversion::new);
input.addPropertyChangeListener(ReactorStatics.VALUE, (model, nva) -> {
if (nva != null)
model.getGenerics()[1].addHolder(model.getGeneric(), nva);
});
new GSHyperLink(this) {
{
addStyle("justify-content", "center");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import org.genericsystem.reactor.gstag.GSHyperLink;
import org.genericsystem.reactor.model.GenericModel;

import javafx.beans.binding.Bindings;
import javafx.beans.property.Property;
import javafx.beans.value.ChangeListener;

public class GSLinkEditor extends GSSection {

Expand Down Expand Up @@ -74,31 +74,21 @@ public static class GSLinkAdder extends GSLinkBuilder {
public GSLinkAdder(GSTag parent) {
super(parent, GSLinkComponentAdder::new);
addStyle("height", "100%");
new GSHyperLink(this) {
{
addStyle("justify-content", "center");
addStyle("text-decoration", "none");
addStyle("height", "100%");
setText("+");
bindStyle(ReactorStatics.DISPLAY, ReactorStatics.DISPLAY, model -> {
Property<List<Property<GenericModel>>> componentsList = getProperty(ReactorStatics.COMPONENTS, model);
return Bindings.createStringBinding(() -> {
List<Generic> selectedGenerics = componentsList.getValue().stream().filter(obs -> obs.getValue() != null).map(obs -> obs.getValue().getGeneric()).filter(gen -> gen != null).collect(Collectors.toList());
return selectedGenerics.size() + 1 == model.getGeneric().getComponents().size() ? "flex" : "none";
}, componentsList.getValue().stream().toArray(Property[]::new));
});
bindAction(model -> {
addPostfixBinding(model -> {
Property<List<Property<GenericModel>>> selectedComponents = getProperty(ReactorStatics.COMPONENTS, model);
ChangeListener<GenericModel> listener = (o, v, nva) -> {
List<Generic> selectedGenerics = selectedComponents.getValue().stream().filter(obs -> obs.getValue() != null).map(obs -> obs.getValue().getGeneric()).filter(gen -> gen != null).collect(Collectors.toList());
if (selectedGenerics.size() + 1 == model.getGeneric().getComponents().size()) {
selectedComponents.getValue().stream().forEach(sel -> sel.setValue(null));
try {
Property<List<Property<GenericModel>>> selectedComponents = getProperty(ReactorStatics.COMPONENTS, model);
List<Generic> selectedGenerics = selectedComponents.getValue().stream().filter(obs -> obs.getValue() != null).map(obs -> obs.getValue().getGeneric()).filter(gen -> gen != null).collect(Collectors.toList());
selectedComponents.getValue().stream().forEach(sel -> sel.setValue(null));
model.getGenerics()[1].setHolder(model.getGeneric(), null, selectedGenerics.stream().toArray(Generic[]::new));
} catch (RollbackException e) {
e.printStackTrace();
}
});
}
};
}
};
selectedComponents.getValue().forEach(component -> component.addListener(listener));
});
}
}
}

0 comments on commit efc4484

Please sign in to comment.