-
Notifications
You must be signed in to change notification settings - Fork 5
/
InstanceEditor.java
256 lines (234 loc) · 13.9 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
package org.genericsystem.reactor.gscomponents3;
import org.genericsystem.reactor.modelproperties.ComponentsDefaults;
import org.genericsystem.reactor.modelproperties.ConvertedValueDefaults;
import org.genericsystem.reactor.modelproperties.SelectionDefaults;
import org.genericsystem.reactor.htmltag.HtmlLabel.GSLabelDisplayer;
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.BindAction;
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.SetText;
import org.genericsystem.reactor.annotations.Styles.AlignItems;
import org.genericsystem.reactor.annotations.Styles.Flex;
import org.genericsystem.reactor.annotations.Styles.FlexDirectionStyle;
import org.genericsystem.reactor.annotations.Styles.FlexWrap;
import org.genericsystem.reactor.annotations.Styles.GenericValueBackgroundColor;
import org.genericsystem.reactor.annotations.Styles.JustifyContent;
import org.genericsystem.reactor.annotations.Styles.Overflow;
import org.genericsystem.reactor.annotations.Styles.Style;
import org.genericsystem.reactor.gscomponents.FlexDirection;
import org.genericsystem.reactor.gscomponents.GSCheckBoxWithValue;
import org.genericsystem.reactor.gscomponents.GSCheckBoxWithValue.GSCheckBoxEditor;
import org.genericsystem.reactor.gscomponents.GSDiv;
import org.genericsystem.reactor.gscomponents.GSInputTextWithConversion;
import org.genericsystem.reactor.gscomponents.GSInputTextWithConversion.GSInputTextEditorWithConversion;
import org.genericsystem.reactor.gscomponents.GSSelect.CompositeSelectWithEmptyEntry;
import org.genericsystem.reactor.gscomponents.GSSelect.InstanceCompositeSelect;
import org.genericsystem.reactor.gscomponents2.GSCellDiv.GSActionLink;
import org.genericsystem.reactor.gscomponents3.GSComposite.Content;
import org.genericsystem.reactor.gscomponents3.GSComposite.Header;
import org.genericsystem.reactor.gscomponents3.InstanceEditor.AttributeContent;
import org.genericsystem.reactor.gscomponents3.InstanceEditor.GSHoldersEditor;
import org.genericsystem.reactor.gscomponents3.InstanceEditor.GSMultiCheckbox;
import org.genericsystem.reactor.gscomponents3.InstanceEditor.GSValueComponentsEditor;
import org.genericsystem.reactor.gscomponents3.InstancesTable.GSHolders;
import org.genericsystem.reactor.gscomponents3.InstancesTable.GSValueComponents;
import org.genericsystem.reactor.gscomponents3.Table.ContentRow;
import org.genericsystem.reactor.gscomponents3.Table.HeaderRow;
import org.genericsystem.reactor.model.ContextAction.ADD_HOLDER;
import org.genericsystem.reactor.model.ContextAction.REMOVE;
import org.genericsystem.reactor.model.ObservableListExtractor;
import org.genericsystem.reactor.model.ObservableListExtractor.NO_FOR_EACH;
import org.genericsystem.reactor.model.ObservableListExtractor.SUBINSTANCES_OF_LINK_COMPONENT;
import org.genericsystem.reactor.model.ObservableModelSelector.HOLDER_ADDITION_ENABLED_SELECTOR;
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.MULTICHECKBOX_SELECTOR;
import org.genericsystem.reactor.model.ObservableValueSelector.NON_MULTICHECKBOX_SELECTOR;
import org.genericsystem.reactor.model.ObservableValueSelector.REVERSED_RELATION_SELECTOR;
import org.genericsystem.reactor.model.ObservableValueSelector.STRICT_ATTRIBUTE_SELECTOR;
import org.genericsystem.reactor.model.ObservableValueSelector.TYPE_SELECTOR;
import org.genericsystem.reactor.model.StringExtractor;
import javafx.beans.binding.Bindings;
import javafx.beans.property.Property;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
@Style(path = HeaderRow.class, name = "flex", value = "0.3")
@Style(path = ContentRow.class, name = "flex", value = "1")
@Style(path = HeaderRow.class, name = "color", value = "white")
@GenericValueBackgroundColor(path = { HeaderRow.class, GSValueComponents.class, Content.class }, value = "#ea0084")
@GenericValueBackgroundColor(path = { HeaderRow.class, GSValueComponents.class, Header.class }, value = "#ea0084")
@GenericValueBackgroundColor(path = { HeaderRow.class, Content.class, GSValueComponents.class, Content.class }, value = "#ea0084")
@GenericValueBackgroundColor(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, AttributeContent.class })
@ReactorDependencies(path = { ContentRow.class, GSValueComponentsEditor.class }, value = { Header.class, Content.class })
@ReactorDependencies(path = { ContentRow.class, Content.class }, value = { GSHoldersEditor.class, GSMultiCheckbox.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, GSValueComponents.class, Content.class }, value = ObservableListExtractor.OTHER_COMPONENTS_2.class)
@Select(path = { HeaderRow.class, GSValueComponents.class }, value = TYPE_SELECTOR.class)
public class InstanceEditor extends Table implements SelectionDefaults {
@ReactorDependencies({ GSHoldersEditor.class, GSMultiCheckbox.class })
@ForEach(ObservableListExtractor.ATTRIBUTES_OF_INSTANCES.class)
@Select(path = GSHoldersEditor.class, value = NON_MULTICHECKBOX_SELECTOR.class)
@Select(path = GSMultiCheckbox.class, value = MULTICHECKBOX_SELECTOR.class)
public static class AttributeContent extends Content {
}
@ReactorDependencies(CheckboxLabel.class)
@ForEach(path = CheckboxLabel.class, value = SUBINSTANCES_OF_LINK_COMPONENT.class)
@FlexWrap("wrap")
@Overflow("auto")
public static class GSMultiCheckbox extends GSDiv {
}
@Flex("1 0 auto")
@JustifyContent("center")
@AlignItems("center")
@Style(name = "text-align", value = "center")
@ReactorDependencies(Checkbox.class)
public static class CheckboxLabel extends org.genericsystem.reactor.htmltag.HtmlLabel {
@Override
public void init() {
bindText();
addPrefixBinding(model -> {
if ("Color".equals(StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(model.getGeneric().getMeta())))
addStyle(model, "background-color", getGenericStringProperty(model).getValue());
});
}
}
@Style(name = "float", value = "left")
@Style(name = "vertical-align", value = "middle")
@Style(name = "margin", value = "4px")
public static class Checkbox extends GSCheckBoxWithValue {
@Override
public void init() {
initValueProperty(context -> context.getGenerics()[2].getLink(context.getGenerics()[1], context.getGeneric()) != null ? true : false);
storeProperty("exists", context -> {
ObservableValue<Boolean> exists = Bindings.createBooleanBinding(() -> context.getGenerics()[2].getObservableLink(context.getGenerics()[1], context.getGeneric()).getValue() != null ? true : false,
context.getGenerics()[2].getObservableLink(context.getGenerics()[1], context.getGeneric()));
exists.addListener((o, v, nva) -> {
if (!context.isDestroyed())
getConvertedValueProperty(context).setValue(nva);
});
return exists;
});
addConvertedValueChangeListener((context, nva) -> {
if (Boolean.TRUE.equals(nva))
context.getGenerics()[2].setHolder(context.getGenerics()[1], null, context.getGeneric());
if (Boolean.FALSE.equals(nva)) {
Generic link = context.getGenerics()[2].getLink(context.getGenerics()[1], context.getGeneric());
if (link != null)
link.remove();
}
});
}
}
@Style(path = { Header.class, GSInputTextEditorWithConversion.class }, name = "flex", value = "1")
@Style(path = { Header.class, GSInputTextEditorWithConversion.class }, name = "width", value = "100%")
@ReactorDependencies({ Header.class, Content.class, GSActionLink.class })
@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)
@SelectModel(path = GSActionLink.class, value = REMOVABLE_HOLDER_SELECTOR.class)
@SetText(path = GSActionLink.class, value = "×")
@BindAction(path = GSActionLink.class, value = REMOVE.class)
public static class GSValueComponentsEditor extends GSValueComponents implements ComponentsDefaults {
}
@Flex(path = GSValueComponentsEditor.class, value = "1 0 auto")
@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)
@SelectModel(path = GSHolderAdder.class, value = HOLDER_ADDITION_ENABLED_SELECTOR.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)
@FlexDirectionStyle(FlexDirection.COLUMN)
@Style(name = "flex-wrap", value = "wrap")
@Style(name = "overflow", value = "auto")
public static class GSHoldersEditor extends GSHolders {
}
@Style(name = "flex", value = "1")
@Style(name = "width", value = "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));
});
}
}
@Style(name = "flex", value = "1 0 auto")
@Style(path = { Header.class, GSInputTextWithConversion.class }, name = "flex", value = "1")
@Style(path = { Header.class, GSInputTextWithConversion.class }, name = "width", value = "100%")
@ReactorDependencies({ Header.class, Content.class, GSActionLink.class })
@ReactorDependencies(path = Header.class, value = { HolderAdderInput.class, BooleanHolderAdderInput.class })
@ReactorDependencies(path = Content.class, value = ComponentAdderSelect.class)
@Select(path = GSActionLink.class, value = STRICT_ATTRIBUTE_SELECTOR.class)
@Select(path = { Header.class, HolderAdderInput.class }, value = ObservableValueSelector.LABEL_DISPLAYER_ATTRIBUTE.class)
@Select(path = { Header.class, BooleanHolderAdderInput.class }, value = ObservableValueSelector.CHECK_BOX_DISPLAYER_ATTRIBUTE.class)
@SetText(path = GSActionLink.class, value = "+")
@BindAction(path = GSActionLink.class, value = ADD_HOLDER.class)
public static class GSHolderAdder extends GSValueComponents implements ComponentsDefaults, ConvertedValueDefaults {
@Override
public void init() {
createComponentsListProperty();
createConvertedValueProperty();
addConvertedValueChangeListener((context, nva) -> {
if (nva != null)
context.getGenerics()[1].addHolder(context.getGeneric(), nva);
});
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((context, nva) -> ((ConvertedValueDefaults) getParent().getParent()).getConvertedValueProperty(context.getParent().getParent()).setValue(nva));
}
}
public static class BooleanHolderAdderInput extends GSCheckBoxWithValue {
@Override
public void init() {
addConvertedValueChangeListener((context, nva) -> ((ConvertedValueDefaults) getParent().getParent()).getConvertedValueProperty(context.getParent().getParent()).setValue(nva));
}
}
@Style(name = "flex", value = "1")
@Style(name = "width", value = "100%")
@Select(DIRECT_RELATION_SELECTOR.class)
public static class ComponentAdderSelect extends CompositeSelectWithEmptyEntry {
@Override
public void init() {
addPostfixBinding(model -> {
Property<List<Property<Context>>> selectedComponents = getComponentsProperty(model);
if (selectedComponents != null)
selectedComponents.getValue().add(getSelectionProperty(model));
});
}
}
}