-
Notifications
You must be signed in to change notification settings - Fork 5
/
InstanceEditor.java
171 lines (156 loc) · 8.88 KB
/
InstanceEditor.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package org.genericsystem.reactor.az3;
import java.util.List;
import java.util.stream.Collectors;
import org.genericsystem.api.core.exceptions.RollbackException;
import org.genericsystem.common.Generic;
import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.annotations.ForEach;
import org.genericsystem.reactor.annotations.ReactorDependencies;
import org.genericsystem.reactor.annotations.Select;
import org.genericsystem.reactor.annotations.Select.SelectModel;
import org.genericsystem.reactor.annotations.Styles;
import org.genericsystem.reactor.annotations.Styles.BackgroundColor;
import org.genericsystem.reactor.annotations.Styles.Flex;
import org.genericsystem.reactor.annotations.Styles.Height;
import org.genericsystem.reactor.annotations.Styles.JustifyContent;
import org.genericsystem.reactor.annotations.Styles.Style;
import org.genericsystem.reactor.annotations.Styles.Width;
import org.genericsystem.reactor.az.GSCheckBoxWithValue;
import org.genericsystem.reactor.az.GSCheckBoxWithValue.GSCheckBoxEditor;
import org.genericsystem.reactor.az.GSInputTextWithConversion;
import org.genericsystem.reactor.az.GSInputTextWithConversion.GSInputTextEditorWithConversion;
import org.genericsystem.reactor.az.GSSelect.CompositeSelectWithEmptyEntry;
import org.genericsystem.reactor.az.GSSelect.InstanceCompositeSelect;
import org.genericsystem.reactor.az3.GSComposite.Content;
import org.genericsystem.reactor.az3.GSComposite.Header;
import org.genericsystem.reactor.az3.InstanceEditor.GSHoldersEditor;
import org.genericsystem.reactor.az3.InstanceEditor.GSValueComponentsEditor;
import org.genericsystem.reactor.az3.InstanceEditor.RemovalLink;
import org.genericsystem.reactor.az3.InstancesTable.GSHolders;
import org.genericsystem.reactor.az3.InstancesTable.GSValueComponents;
import org.genericsystem.reactor.az3.Table.ContentRow;
import org.genericsystem.reactor.az3.Table.HeaderRow;
import org.genericsystem.reactor.gstag.HtmlHyperLink;
import org.genericsystem.reactor.gstag.HtmlLabel.GSLabelDisplayer;
import org.genericsystem.reactor.model.ObservableListExtractor;
import org.genericsystem.reactor.model.ObservableListExtractor.NO_FOR_EACH;
import org.genericsystem.reactor.model.ObservableModelSelector.REMOVABLE_HOLDER_SELECTOR;
import org.genericsystem.reactor.model.ObservableValueSelector;
import org.genericsystem.reactor.model.ObservableValueSelector.DIRECT_RELATION_SELECTOR;
import org.genericsystem.reactor.model.ObservableValueSelector.REVERSED_RELATION_SELECTOR;
import org.genericsystem.reactor.modelproperties.ComponentsDefaults;
import org.genericsystem.reactor.modelproperties.SelectionDefaults;
import javafx.beans.property.Property;
import javafx.beans.value.ChangeListener;
@Flex(path = HeaderRow.class, value = "0.3")
@Styles.Color(path = HeaderRow.class, value = "white")
@BackgroundColor(path = { HeaderRow.class, GSValueComponents.class, Content.class }, value = "#ea0084")
@BackgroundColor(path = { HeaderRow.class, GSValueComponents.class, Header.class }, value = "#ea0084")
@BackgroundColor(path = { HeaderRow.class, Content.class, GSValueComponents.class, Content.class }, value = "#ea0084")
@BackgroundColor(path = { HeaderRow.class, Content.class, GSValueComponents.class, Header.class }, value = "#ea0084")
@ReactorDependencies({ HeaderRow.class, ContentRow.class })
@ReactorDependencies(path = HeaderRow.class, value = { GSValueComponents.class, Content.class })
@ReactorDependencies(path = { HeaderRow.class, Content.class }, value = GSValueComponents.class)
@ReactorDependencies(path = ContentRow.class, value = { GSValueComponentsEditor.class, GSHoldersEditor.class })
@ReactorDependencies(path = { ContentRow.class, GSHoldersEditor.class, GSValueComponentsEditor.class }, value = { Header.class, Content.class, RemovalLink.class })
@ForEach(path = { HeaderRow.class, Content.class }, value = ObservableListExtractor.ATTRIBUTES_OF_INSTANCES.class)
@ForEach(path = { HeaderRow.class, Content.class, GSValueComponents.class, Content.class }, value = ObservableListExtractor.OTHER_COMPONENTS_2.class)
@ForEach(path = { ContentRow.class, GSHolders.class }, value = ObservableListExtractor.ATTRIBUTES_OF_INSTANCES.class)
@ForEach(path = { ContentRow.class, GSValueComponents.class, Content.class }, value = ObservableListExtractor.OTHER_COMPONENTS_2.class)
@SelectModel(path = { ContentRow.class, GSHoldersEditor.class, GSValueComponentsEditor.class, RemovalLink.class }, value = REMOVABLE_HOLDER_SELECTOR.class)
public class InstanceEditor extends Table implements SelectionDefaults {
@Flex(path = { Header.class, GSInputTextEditorWithConversion.class }, value = "1")
@Width(path = { Header.class, GSInputTextEditorWithConversion.class }, value = "100%")
@ReactorDependencies(path = Header.class, value = GSInputTextEditorWithConversion.class)
@ReactorDependencies(path = Content.class, value = { DirectRelationComponentEditor.class, GSLabelDisplayer.class })
@Select(path = { Content.class, DirectRelationComponentEditor.class }, value = DIRECT_RELATION_SELECTOR.class)
@Select(path = { Content.class, GSLabelDisplayer.class }, value = REVERSED_RELATION_SELECTOR.class)
public static class GSValueComponentsEditor extends GSValueComponents implements ComponentsDefaults {
}
@ReactorDependencies(value = { GSValueComponentsEditor.class, GSHolderAdder.class })
@ReactorDependencies(path = { GSValueComponentsEditor.class, Header.class }, value = { GSInputTextEditorWithConversion.class, GSCheckBoxEditor.class })
@ReactorDependencies(path = { GSHolderAdder.class, Header.class }, value = { HolderAdderInput.class, BooleanHolderAdderInput.class })
@ForEach(path = GSHolderAdder.class, value = NO_FOR_EACH.class)
@Select(path = { GSValueComponents.class, Header.class, GSInputTextEditorWithConversion.class }, value = ObservableValueSelector.LABEL_DISPLAYER.class)
@Select(path = { GSValueComponents.class, Header.class, GSCheckBoxEditor.class }, value = ObservableValueSelector.CHECK_BOX_DISPLAYER.class)
public static class GSHoldersEditor extends GSHolders {
}
@Flex("1")
@Width("100%")
public static class DirectRelationComponentEditor extends InstanceCompositeSelect {
@Override
public void init() {
addPostfixBinding(model -> {
Property<List<Property<Context>>> selectedComponents = getComponentsProperty(model);
if (selectedComponents != null)
selectedComponents.getValue().add(getSelectionProperty(model));
});
}
}
@JustifyContent("center")
@Height("100%")
@Style(name = "text-decoration", value = "none")
public static class RemovalLink extends HtmlHyperLink {
@Override
public void init() {
setText("×");
bindAction(Context::remove);
}
}
@Flex(path = { Header.class, GSInputTextWithConversion.class }, value = "1")
@Width(path = { Header.class, GSInputTextWithConversion.class }, value = "100%")
@ReactorDependencies(path = Header.class, value = { HolderAdderInput.class, BooleanHolderAdderInput.class })
@ReactorDependencies(path = Content.class, value = ComponentAdderSelect.class)
public static class GSHolderAdder extends GSValueComponents implements ComponentsDefaults {
@Override
public void init() {
createComponentsListProperty();
addPostfixBinding(model -> {
Property<List<Property<Context>>> selectedComponents = getComponentsProperty(model);
ChangeListener<Context> listener = (o, v, nva) -> {
List<Generic> selectedGenerics = selectedComponents.getValue().stream().filter(obs -> obs.getValue() != null).map(obs -> obs.getValue().getGeneric()).filter(gen -> gen != null).collect(Collectors.toList());
if (selectedGenerics.size() + 1 == model.getGeneric().getComponents().size()) {
selectedComponents.getValue().stream().forEach(sel -> sel.setValue(null));
try {
model.getGenerics()[1].setHolder(model.getGeneric(), null, selectedGenerics.stream().toArray(Generic[]::new));
} catch (RollbackException e) {
e.printStackTrace();
}
}
};
selectedComponents.getValue().forEach(component -> component.addListener(listener));
});
}
}
public static class HolderAdderInput extends GSInputTextWithConversion {
@Override
public void init() {
addConvertedValueChangeListener((model, nva) -> {
if (nva != null)
model.getGenerics()[1].addHolder(model.getGeneric(), nva);
});
}
}
public static class BooleanHolderAdderInput extends GSCheckBoxWithValue {
@Override
public void init() {
addConvertedValueChangeListener((model, nva) -> {
if (nva != null)
model.getGenerics()[1].addHolder(model.getGeneric(), nva);
});
}
}
@Flex("1")
@Width("100%")
public static class ComponentAdderSelect extends CompositeSelectWithEmptyEntry {
@Override
public void init() {
// select(gs -> gs[1].isReferentialIntegrityEnabled(gs[1].getComponents().indexOf(gs[0])) ? gs[0] : null);
addPostfixBinding(model -> {
Property<List<Property<Context>>> selectedComponents = getComponentsProperty(model);
if (selectedComponents != null)
selectedComponents.getValue().add(getSelectionProperty(model));
});
}
}
}