-
Notifications
You must be signed in to change notification settings - Fork 5
/
GSSelect.java
69 lines (60 loc) · 2.98 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
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.annotations.BindText;
import org.genericsystem.reactor.annotations.Children;
import org.genericsystem.reactor.annotations.ForEach;
import org.genericsystem.reactor.annotations.Style.GenericValueBackgroundColor;
import org.genericsystem.reactor.gscomponents.GSSelect.HtmlRepeatedOption;
import org.genericsystem.reactor.model.ObservableListExtractor;
import org.genericsystem.reactor.model.StringExtractor;
@Children(HtmlRepeatedOption.class)
@BindText(path = HtmlRepeatedOption.class)
@ForEach(path = HtmlRepeatedOption.class, value = ObservableListExtractor.SUBINSTANCES.class)
@GenericValueBackgroundColor(path = HtmlOption.class, value = "")
public class GSSelect extends HtmlSelect implements SelectionDefaults, ComponentsDefaults {
public static class HtmlRepeatedOption extends HtmlOption {
}
@Override
public void init() {
createSelectionProperty();
bindBiDirectionalSelection(find(HtmlOption.class));
addPrefixBinding(context -> {
if ("Color".equals(StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(context.getGeneric()))) {
getSelectionString(context).addListener((o, old, newValue) -> addStyle(context, "background-color", newValue));
addStyle(context, "background-color", getSelectionString(context).getValue());
}
});
}
@Children({ HtmlOption.class, HtmlRepeatedOption.class })
@ForEach(path = HtmlOption.class, pos = 0, value = ObservableListExtractor.NO_FOR_EACH.class)
@ForEach(path = HtmlOption.class, pos = 1, value = ObservableListExtractor.SUBINSTANCES.class)
public static class GSSelectWithEmptyEntry extends GSSelect {
@Override
public void init() {
setSelectionShift(1);
createSelectionProperty();
bindBiDirectionalSelection(find(HtmlOption.class, 1));
addPrefixBinding(context -> {
if ("Color".equals(StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(context.getGeneric()))) {
getSelectionString(context).addListener((o, old, newValue) -> addStyle(context, "background-color", newValue));
addStyle(context, "background-color", getSelectionString(context).getValue());
}
});
}
}
@ForEach(path = HtmlOption.class, value = ObservableListExtractor.SUBINSTANCES_OF_META.class)
public static class InstanceCompositeSelect extends GSSelect {
@Override
public void init() {
super.init();
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()))));
}
}
}