-
Notifications
You must be signed in to change notification settings - Fork 5
/
GSSelect.java
104 lines (82 loc) · 2.8 KB
/
GSSelect.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
package org.genericsystem.reactor.gscomponents;
import org.genericsystem.reactor.modelproperties.ComponentsDefaults;
import org.genericsystem.reactor.modelproperties.SelectionDefaults;
import org.genericsystem.reactor.htmltag.HtmlOption;
import org.genericsystem.reactor.htmltag.HtmlSelect;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.model.ObservableListExtractor;
import org.genericsystem.reactor.model.StringExtractor;
import javafx.beans.value.ObservableValue;
public class GSSelect extends HtmlSelect implements SelectionDefaults, ComponentsDefaults {
public HtmlOption optionElement;
public GSSelect() {
initSelect();
}
private GSSelect(Tag parent) {
super(parent);
initSelect();
}
protected void initSelect() {
options();
initProperties();
createSelectionProperty();
bindBiDirectionalSelection(optionElement);
addPrefixBinding(model -> {
if ("Color".equals(StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(model.getGeneric()))) {
ObservableValue<String> observable = getSelectionString(model);
observable.addListener((o, old, newValue) -> addStyle(model, "background-color", newValue));
addStyle(model, "background-color", observable.getValue());
}
});
optionElement.addPrefixBinding(model -> {
if ("Color".equals(StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(model.getGeneric().getMeta())))
optionElement.addStyle(model, "background-color", optionElement.getGenericStringProperty(model).getValue());
});
}
protected void options() {
optionElement = new HtmlOption(this) {
{
bindText();
forEach(GSSelect.this);
}
};
}
protected void initProperties() {
}
public static class CompositeSelectWithEmptyEntry extends GSSelect {
public CompositeSelectWithEmptyEntry() {
}
public CompositeSelectWithEmptyEntry(Tag parent) {
super(parent);
}
@Override
protected void options() {
new HtmlOption(this);
super.options();
}
@Override
protected void initProperties() {
setSelectionShift(1);
}
}
public static class InstanceCompositeSelect extends GSSelect {
public InstanceCompositeSelect() {
}
public InstanceCompositeSelect(Tag parent) {
super(parent);
}
@Override
protected void initSelect() {
super.initSelect();
addPostfixBinding(model -> {
if ("Color".equals(StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(model.getGeneric().getMeta())))
addStyle(model, "background-color", getSelectionString(model).getValue());
});
addPostfixBinding(model -> getSelectionProperty(model).addListener((ov, ova, nva) -> model.getGenerics()[1].updateComponent(nva.getGeneric(), model.getGenerics()[1].getComponents().indexOf(model.getGeneric()))));
}
@Override
public ObservableListExtractor getObservableListExtractor() {
return ObservableListExtractor.SUBINSTANCES_OF_META;
}
}
}