-
Notifications
You must be signed in to change notification settings - Fork 5
/
GSBooleanHolderEditor.java
91 lines (77 loc) · 2.7 KB
/
GSBooleanHolderEditor.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
package org.genericsystem.reactor.gs;
import java.io.Serializable;
import java.util.Map;
import org.genericsystem.common.Generic;
import org.genericsystem.reactor.ReactorStatics;
import org.genericsystem.reactor.gs.GSCheckBoxWithValue.GSCheckBoxEditor;
import org.genericsystem.reactor.gstag.GSCheckBox;
import org.genericsystem.reactor.gstag.GSHyperLink;
import org.genericsystem.reactor.model.GenericModel;
import javafx.beans.property.Property;
public class GSBooleanHolderEditor extends GSSection {
protected GSCheckBox checkbox;
public GSBooleanHolderEditor(GSTag parent) {
this(parent, GSCheckBoxEditor::new);
}
public GSBooleanHolderEditor(GSTag parent, GSCheckBoxConstructor constructor) {
super(parent, FlexDirection.ROW);
addStyle("flex", "1");
new GSSection(this, FlexDirection.ROW) {
{
addStyle("flex", "1");
addStyle("justify-content", "center");
addStyle("align-items", "center");
checkbox = constructor.build(this);
}
};
}
@FunctionalInterface
public interface GSCheckBoxConstructor {
GSCheckBox build(GSTag parent);
}
public static class GSBooleanHolderEditorWithRemoval extends GSBooleanHolderEditor {
public GSBooleanHolderEditorWithRemoval(GSTag parent) {
super(parent);
new GSHyperLink(this) {
{
addStyle("justify-content", "center");
addStyle("text-decoration", "none");
setText("×");
bindAction(GenericModel::remove);
}
};
}
}
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");
addStyle("text-decoration", "none");
setText("+");
bindAction(model -> {
Property<Boolean> observable = checkbox.getProperty(ReactorStatics.VALUE, model);
Boolean newValue = observable.getValue();
observable.setValue(null);
model.getGenerics()[1].addHolder(model.getGeneric(), newValue);
});
}
};
}
}
public static class GSBooleanHolderBuilder extends GSBooleanHolderEditor {
public GSBooleanHolderBuilder(GSTag parent) {
super(parent, GSCheckBoxWithValue::new);
if (parent != null && parent.getParent() != null && parent.getParent().getParent() instanceof GSInstanceBuilder)
checkbox.addPrefixBinding(model -> {
Property<Map<Generic, Property<Serializable>>> holders = getProperty(ReactorStatics.HOLDERS_MAP, model);
holders.getValue().put(model.getGeneric(), checkbox.getProperty(ReactorStatics.VALUE, model));
});
}
}
}