-
Notifications
You must be signed in to change notification settings - Fork 5
/
GSSubcellDisplayer.java
344 lines (296 loc) · 9.72 KB
/
GSSubcellDisplayer.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
package org.genericsystem.reactor.az;
import java.io.Serializable;
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.Tag;
import org.genericsystem.reactor.az.GSBooleanHolderEditor.GSBooleanHolderBuilder;
import org.genericsystem.reactor.az.GSCheckBoxWithValue.GSCheckBoxDisplayer;
import org.genericsystem.reactor.az.GSHolderEditor.GSHolderBuilder;
import org.genericsystem.reactor.az.GSLinkEditor.GSLinkBuilder;
import org.genericsystem.reactor.az.GSSingleLinkComponentEditor.GSLinkComponentAdder;
import org.genericsystem.reactor.gstag.HtmlHyperLink;
import org.genericsystem.reactor.gstag.HtmlLabel.GSLabelDisplayer;
import org.genericsystem.reactor.model.ObservableListExtractor;
import org.genericsystem.reactor.modelproperties.ConvertedValueDefaults;
import javafx.beans.property.Property;
import javafx.beans.value.ChangeListener;
public class GSSubcellDisplayer extends GSDiv {
private final boolean needMeta;
public GSSubcellDisplayer(Tag parent) {
this(parent, FlexDirection.ROW);
}
public GSSubcellDisplayer(Tag parent, FlexDirection direction) {
this(parent, direction, true);
}
public GSSubcellDisplayer(Tag parent, FlexDirection direction, boolean needMeta) {
super(parent, direction);
this.needMeta = needMeta;
addStyle("flex", "1");
content();
}
public void content() {
new GSDiv(this, this.getDirection()) {
{
subCellStyle(this);
if (needMeta)
select(gs -> gs[0].getComponents().size() < 2 && !Boolean.class.equals(gs[0].getMeta().getInstanceValueClassConstraint()) ? gs[0] : null);
else
select(gs -> gs[0].getComponents().size() < 2 && !Boolean.class.equals(gs[0].getInstanceValueClassConstraint()) ? gs[0] : null);
getHolderDisplayerConstructor().build(this);
}
};
new GSDiv(this, this.getDirection()) {
{
subCellStyle(this);
if (needMeta)
select(gs -> gs[0].getComponents().size() < 2 && Boolean.class.equals(gs[0].getMeta().getInstanceValueClassConstraint()) ? gs[0] : null);
else
select(gs -> gs[0].getComponents().size() < 2 && Boolean.class.equals(gs[0].getInstanceValueClassConstraint()) ? gs[0] : null);
getBooleanHolderDisplayerConstructor().build(this);
}
};
new GSDiv(this, this.getDirection()) {
{
addStyle("flex", "1");
select(gs -> gs[0].getComponents().size() >= 2 ? gs[0] : null);
Tag components = getLinkDisplayerConstructor().build(this);
subCellStyle(components);
}
};
}
public TagConstructor getHolderDisplayerConstructor() {
return GSLabelDisplayer::new;
}
public TagConstructor getBooleanHolderDisplayerConstructor() {
return GSCheckBoxDisplayer::new;
}
public TagConstructor getLinkDisplayerConstructor() {
return tag -> new GSDiv(tag, ((GSDiv) tag).getDirection()) {
{
forEach((ObservableListExtractor) gs -> ObservableListExtractor.COMPONENTS.apply(gs).filtered(g -> !g.equals(gs[2])));
new GSLabelDisplayer(this);
}
};
}
public void subCellStyle(Tag tag) {
tag.addStyle("justify-content", "center");
tag.addStyle("align-items", "center");
tag.addStyle("flex", "1");
tag.addStyle("margin-right", "1px");
tag.addStyle("margin-bottom", "1px");
}
@FunctionalInterface
public interface TagConstructor {
Tag build(Tag parent);
}
public static class GSSubcellEditor extends GSSubcellDisplayer {
public GSSubcellEditor(Tag parent) {
this(parent, FlexDirection.ROW);
}
public GSSubcellEditor(Tag parent, FlexDirection direction) {
super(parent, direction, false);
}
@Override
public TagConstructor getHolderDisplayerConstructor() {
return GSHolderEditor::new;
}
@Override
public TagConstructor getBooleanHolderDisplayerConstructor() {
return GSBooleanHolderEditor::new;
}
@Override
public TagConstructor getLinkDisplayerConstructor() {
return GSLinkEditor::new;
}
@Override
public void subCellStyle(Tag tag) {
super.subCellStyle(tag);
tag.addStyle("color", "#ffffff");
tag.addStyle("justify-content", "flex-start");
tag.addStyle("align-items", "stretch");
}
}
public static class GSSubcellEditorWithRemoval extends GSSubcellEditor {
public GSSubcellEditorWithRemoval(Tag parent) {
this(parent, FlexDirection.ROW);
}
public GSSubcellEditorWithRemoval(Tag parent, FlexDirection direction) {
super(parent, direction);
}
@Override
public TagConstructor getHolderDisplayerConstructor() {
return tag -> new GSHolderEditor(tag) {
{
removalLink(this);
}
};
}
@Override
public TagConstructor getBooleanHolderDisplayerConstructor() {
return tag -> new GSBooleanHolderEditor(tag) {
{
removalLink(this);
}
};
}
@Override
public TagConstructor getLinkDisplayerConstructor() {
return tag -> new GSLinkEditor(tag) {
{
removalLink(this);
}
};
}
private void removalLink(Tag tag) {
new HtmlHyperLink(tag) {
{
addStyle("justify-content", "center");
addStyle("text-decoration", "none");
addStyle("height", "100%");
setText("×");
bindAction(Context::remove);
}
};
}
}
public static class GSSubcellAdder extends GSSubcellEditor {
public GSSubcellAdder(Tag parent) {
this(parent, FlexDirection.ROW);
}
public GSSubcellAdder(Tag parent, FlexDirection direction) {
super(parent, direction);
}
@Override
public TagConstructor getHolderDisplayerConstructor() {
return tag -> new GSHolderEditor(tag, GSInputTextWithConversion::new) {
{
input.addConvertedValueChangeListener((model, nva) -> {
if (nva != null)
model.getGenerics()[1].addHolder(model.getGeneric(), nva);
});
new HtmlHyperLink(this) {
{
addStyle("justify-content", "center");
addStyle("text-decoration", "none");
addStyle("height", "100%");
setText("+");
bindAction(context -> addHolder(context, input));
}
};
}
};
}
@Override
public TagConstructor getBooleanHolderDisplayerConstructor() {
return tag -> new GSBooleanHolderEditor(tag, GSCheckBoxWithValue::new) {
{
checkbox.addConvertedValueChangeListener((model, nva) -> {
if (nva != null)
model.getGenerics()[1].addHolder(model.getGeneric(), nva);
});
new HtmlHyperLink(this) {
{
addStyle("justify-content", "center");
addStyle("text-decoration", "none");
setText("+");
bindAction(context -> addHolder(context, checkbox));
}
};
}
};
}
@Override
public TagConstructor getLinkDisplayerConstructor() {
return tag -> new GSLinkEditor(tag, GSLinkComponentAdder::new) {
{
addStyle("height", "100%");
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));
});
}
};
}
private void addHolder(Context context, ConvertedValueDefaults tag) {
Property<Serializable> observable = tag.getConvertedValueProperty(context);
if (observable.getValue() != null) {
Serializable newValue = observable.getValue();
observable.setValue(null);
context.getGenerics()[1].addHolder(context.getGeneric(), newValue);
}
}
}
public static class LinkTitleDisplayer extends GSSubcellDisplayer {
public LinkTitleDisplayer(Tag parent) {
super(parent, FlexDirection.ROW);
}
@Override
public TagConstructor getLinkDisplayerConstructor() {
return tag -> new GSDiv(tag, ((GSDiv) tag).getDirection()) {
{
forEach((ObservableListExtractor) gs -> ObservableListExtractor.COMPONENTS.apply(gs).filtered(g -> !g.equals(gs[1])));
new GSLabelDisplayer(this);
}
};
}
@Override
public void subCellStyle(Tag tag) {
super.subCellStyle(tag);
tag.addStyle("color", "#ffffff");
tag.addStyle("background-color", "#ea0084");
}
}
public static class InstanceLinkTitleDisplayer extends LinkTitleDisplayer {
public InstanceLinkTitleDisplayer(Tag parent) {
super(parent);
}
@Override
public TagConstructor getLinkDisplayerConstructor() {
return tag -> new GSDiv(tag, ((GSDiv) tag).getDirection()) {
{
forEach((ObservableListExtractor) gs -> ObservableListExtractor.COMPONENTS.apply(gs).filtered(g -> !g.equals(gs[2])));
new GSLabelDisplayer(this);
}
};
}
}
public static class GSAttributeBuilder extends GSSubcellEditor {
public GSAttributeBuilder(Tag parent, FlexDirection direction) {
super(parent, direction);
}
@Override
public TagConstructor getHolderDisplayerConstructor() {
return GSHolderBuilder::new;
}
@Override
public TagConstructor getBooleanHolderDisplayerConstructor() {
return GSBooleanHolderBuilder::new;
}
@Override
public TagConstructor getLinkDisplayerConstructor() {
return GSLinkBuilder::new;
}
@Override
public void subCellStyle(Tag tag) {
tag.addStyle("flex", "1");
tag.addStyle("color", "#ffffff");
tag.addStyle("background-color", "#e5ed00");
tag.addStyle("margin-right", "1px");
tag.addStyle("margin-bottom", "1px");
}
}
}