-
Notifications
You must be signed in to change notification settings - Fork 5
/
GSHolderEditor.java
94 lines (80 loc) · 2.92 KB
/
GSHolderEditor.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
package org.genericsystem.reactor.gs;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.genericsystem.common.Generic;
import org.genericsystem.reactor.ReactorStatics;
import org.genericsystem.reactor.gs.GSInputTextWithConversion.GSInputTextEditorWithConversion;
import org.genericsystem.reactor.gstag.GSHyperLink;
import org.genericsystem.reactor.model.GenericModel;
import javafx.beans.property.Property;
import javafx.beans.value.ObservableValue;
public class GSHolderEditor extends GSSection {
protected GSInputTextWithConversion<?> input;
public GSHolderEditor(GSTag parent) {
this(parent, GSInputTextEditorWithConversion::new);
}
public GSHolderEditor(GSTag parent, GSInputTextConstructor constructor) {
super(parent, FlexDirection.ROW);
addStyle("flex", "1");
addStyle("width", "100%");
addStyle("height", "100%");
input = constructor.build(this);
}
@FunctionalInterface
public interface GSInputTextConstructor {
GSInputTextWithConversion<?> build(GSTag parent);
}
public static class GSHolderEditorWithRemoval extends GSHolderEditor {
public GSHolderEditorWithRemoval(GSTag parent) {
super(parent);
new GSHyperLink(this) {
{
addStyle("justify-content", "center");
addStyle("text-decoration", "none");
addStyle("height", "100%");
setText("×");
bindAction(GenericModel::remove);
}
};
}
}
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");
addStyle("text-decoration", "none");
addStyle("height", "100%");
setText("+");
bindAction(model -> {
Property<Serializable> observable = input.getProperty(ReactorStatics.VALUE, model);
if (observable.getValue() != null) {
Serializable newValue = observable.getValue();
observable.setValue(null);
model.getGenerics()[1].addHolder(model.getGeneric(), newValue);
}
});
}
};
}
}
public static class GSHolderBuilder extends GSHolderEditor {
public GSHolderBuilder(GSTag parent) {
super(parent, GSInputTextWithConversion::new);
if (parent != null && parent.getParent() != null && parent.getParent().getParent() instanceof GSInstanceBuilder) {
input.addPrefixBinding(model -> {
Property<Map<Generic, Property<Serializable>>> holders = getProperty(ReactorStatics.HOLDERS_MAP, model);
holders.getValue().put(model.getGeneric(), input.getProperty(ReactorStatics.VALUE, model));
Property<List<ObservableValue<Boolean>>> invalids = getProperty(ReactorStatics.INVALID_LIST, model);
invalids.getValue().add(input.getObservableValue(ReactorStatics.INVALID, model));
});
}
}
}
}