-
Notifications
You must be signed in to change notification settings - Fork 5
/
GSInstanceBuilder.java
130 lines (116 loc) · 4.56 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package org.genericsystem.reactor.ca_gscomponents;
import java.io.Serializable;
import java.util.List;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.genericsystem.common.Generic;
import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.ReactorStatics;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.aa_modelproperties.GSBuilderDefaults;
import org.genericsystem.reactor.aa_modelproperties.SwitchDefaults;
import org.genericsystem.reactor.ba_htmltag.HtmlButton;
import org.genericsystem.reactor.ca_gscomponents.GSSubcellDisplayer.GSAttributeBuilder;
import org.genericsystem.reactor.ca_gscomponents.GSSubcellDisplayer.LinkTitleDisplayer;
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 implements GSBuilderDefaults {
protected GSHolderEditor instanceValueInput;
public GSInstanceBuilder(Tag parent, FlexDirection flexDirection) {
super(parent, flexDirection);
createHoldersMapProperty();
createComponentsMapProperty();
createInvalidListProperty();
}
@Override
protected void header() {
instanceValueInput = new GSHolderEditor(this, GSInputTextWithConversion::new) {
{
addStyle("margin-right", "1px");
addStyle("margin-bottom", "1px");
addStyle("overflow", "hidden");
}
};
}
@Override
protected void sections() {
new GSAttributeBuilder(this, FlexDirection.ROW) {
{
forEach(ObservableListExtractor.ATTRIBUTES_OF_TYPE);
addStyle("overflow", "hidden");
}
};
}
@Override
protected void footer() {
new GSDiv(this, this.getDirection()) {
{
if (this.getDirection().equals(FlexDirection.ROW)) {
addStyle("flex", "0");
addStyle("min-width", "100px");
} else {
addStyle("flex", "1");
}
addStyle("margin-right", "1px");
addStyle("margin-bottom", "1px");
new HtmlButton(this) {
{
bindAttribute(ReactorStatics.DISABLED, ReactorStatics.DISABLED,
model -> Bindings.createStringBinding(
() -> Boolean.TRUE.equals(getInvalidListProperty(model).getValue().stream().map(input -> input.getValue()).filter(bool -> bool != null).reduce(false, (a, b) -> a || b)) ? ReactorStatics.DISABLED : "",
getInvalidListProperty(model).getValue().stream().toArray(ObservableValue[]::new)));
bindAction(model -> {
Generic newInstance = model.getGeneric().setInstance(instanceValueInput.input.getConvertedValueProperty(model).getValue());
for (Entry<Generic, Property<Serializable>> entry : getHoldersMapProperty(model).getValue().entrySet())
if (entry.getValue().getValue() != null) {
newInstance.setHolder(entry.getKey(), entry.getValue().getValue());
entry.getValue().setValue(null);
}
for (Entry<Generic, List<Property<Context>>> entry : getComponentsMapProperty(model).getValue().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.getConvertedValueProperty(model).setValue(null);
});
setText("Add");
addStyle("width", "100%");
addStyle("height", "100%");
}
};
}
};
}
public static class GSStepInstanceBuilder extends GSInstanceBuilder implements SwitchDefaults {
protected Tag switchedTag;
protected Tag instanceNameTag;
public GSStepInstanceBuilder(Tag parent, FlexDirection flexDirection) {
super(parent, flexDirection);
}
@Override
protected void header() {
instanceNameTag = new GSDiv(this, getDirection()) {
{
addStyle("flex", "1");
new LinkTitleDisplayer(this).addStyle("flex", "0.3");
instanceValueInput = new GSHolderEditor(this, GSInputTextWithConversion::new);
new StepNavigator(this, getReverseDirection());
}
};
}
@Override
protected void sections() {
switchedTag = new GSDiv(this, getDirection()) {
{
addStyle("flex", "1");
new LinkTitleDisplayer(this).addStyle("flex", "0.3");
new GSAttributeBuilder(this, FlexDirection.ROW);
new StepNavigator(this, getReverseDirection());
}
};
}
}
}