-
Notifications
You must be signed in to change notification settings - Fork 5
/
GSInstanceBuilder.java
95 lines (84 loc) · 3.61 KB
/
GSInstanceBuilder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package org.genericsystem.reactor.gs;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.genericsystem.common.Generic;
import org.genericsystem.reactor.ReactorStatics;
import org.genericsystem.reactor.gs.GSHolderEditor.GSHolderBuilder;
import org.genericsystem.reactor.gs.GSSubcellDisplayer.GSAttributeBuilder;
import org.genericsystem.reactor.gstag.GSButton;
import org.genericsystem.reactor.model.GenericModel;
import org.genericsystem.reactor.model.ObservableListExtractor;
import javafx.beans.binding.Bindings;
import javafx.beans.property.Property;
import javafx.beans.value.ObservableValue;
public class GSInstanceBuilder extends GSComposite {
private GSHolderEditor instanceValueInput;
public GSInstanceBuilder(GSTag parent, FlexDirection flexDirection) {
super(parent, flexDirection);
createNewInitializedProperty(ReactorStatics.HOLDERS_MAP, model -> new HashMap<Generic, Property<Serializable>>());
createNewInitializedProperty(ReactorStatics.COMPONENTS_MAP, model -> new HashMap<Generic, List<Property<GenericModel>>>());
createNewInitializedProperty(ReactorStatics.INVALID_LIST, model -> new ArrayList<ObservableValue<Boolean>>());
}
@Override
protected void header() {
instanceValueInput = new GSHolderBuilder(this) {
{
addStyle("margin-right", "1px");
addStyle("margin-bottom", "1px");
}
};
}
@Override
protected void sections() {
new GSAttributeBuilder(this, FlexDirection.ROW) {
{
forEach_(ObservableListExtractor.ATTRIBUTES_OF_TYPE);
}
};
}
@Override
protected void footer() {
new GSSection(this, this.getDirection()) {
{
if (this.getDirection().equals(FlexDirection.ROW)) {
addStyle("flex", "0");
addStyle("min-width", "100px");
} else {
addStyle("flex", "1");
}
addStyle("background-color", "#dda5a5");
addStyle("margin-right", "1px");
addStyle("margin-bottom", "1px");
new GSButton(this) {
{
bindAttribute(ReactorStatics.DISABLED, ReactorStatics.DISABLED, model -> Bindings.createStringBinding(
() -> Boolean.TRUE.equals(getInvalidList(model).stream().map(input -> input.getValue()).filter(bool -> bool != null).reduce(false, (a, b) -> a || b)) ? ReactorStatics.DISABLED : "",
getInvalidList(model).stream().toArray(ObservableValue[]::new)));
bindAction(model -> {
Generic newInstance = model.getGeneric().setInstance((Serializable) instanceValueInput.input.getProperty(ReactorStatics.VALUE, model).getValue());
for (Entry<Generic, Property<Serializable>> entry : getHoldersMap(model).entrySet())
if (entry.getValue().getValue() != null) {
newInstance.setHolder(entry.getKey(), entry.getValue().getValue());
entry.getValue().setValue(null);
}
for (Entry<Generic, List<Property<GenericModel>>> entry : getComponentsMap(model).entrySet()) {
List<Generic> selectedGenerics = entry.getValue().stream().filter(obs -> obs.getValue() != null).map(obs -> obs.getValue().getGeneric()).filter(gen -> gen != null).collect(Collectors.toList());
if (!selectedGenerics.isEmpty() && selectedGenerics.size() + 1 == entry.getKey().getComponents().size())
newInstance.setHolder(entry.getKey(), null, selectedGenerics.stream().toArray(Generic[]::new));
entry.getValue().stream().forEach(sel -> sel.setValue(null));
}
instanceValueInput.input.getProperty(ReactorStatics.VALUE, model).setValue(null);
});
setText("Add");
addStyle("width", "100%");
addStyle("height", "100%");
}
};
}
};
}
}