-
Notifications
You must be signed in to change notification settings - Fork 5
/
GSSubcellDisplayer.java
201 lines (166 loc) · 7.92 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
package org.genericsystem.reactor.gs;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.gs.GSBooleanHolderEditor.GSBooleanHolderAdder;
import org.genericsystem.reactor.gs.GSBooleanHolderEditor.GSBooleanHolderBuilder;
import org.genericsystem.reactor.gs.GSBooleanHolderEditor.GSBooleanHolderEditorWithRemoval;
import org.genericsystem.reactor.gs.GSCheckBoxWithValue.GSCheckBoxDisplayer;
import org.genericsystem.reactor.gs.GSHolderEditor.GSHolderAdder;
import org.genericsystem.reactor.gs.GSHolderEditor.GSHolderBuilder;
import org.genericsystem.reactor.gs.GSHolderEditor.GSHolderEditorWithRemoval;
import org.genericsystem.reactor.gs.GSLinkEditor.GSLinkAdder;
import org.genericsystem.reactor.gs.GSLinkEditor.GSLinkBuilder;
import org.genericsystem.reactor.gs.GSLinkEditor.GSLinkEditorWithRemoval;
import org.genericsystem.reactor.gs.GSSingleLinkComponentDisplayer.GSInstanceLinkComponentsTitleDisplayer;
import org.genericsystem.reactor.gs.GSSingleLinkComponentDisplayer.GSLinkComponentsDisplayer;
import org.genericsystem.reactor.gs.GSSingleLinkComponentDisplayer.GSLinkComponentsTitleDisplayer;
import org.genericsystem.reactor.gstag.HtmlLabel.GSLabelDisplayer;
import org.genericsystem.reactor.model.StringExtractor;
public class GSSubcellDisplayer extends GSDiv {
protected final TagConstructor holderDisplayerConstructor;
protected final TagConstructor booleanHolderDisplayerConstructor;
protected final TagConstructor linkDisplayerConstructor;
private final boolean needMeta;
public GSSubcellDisplayer(Tag parent, TagConstructor holderDisplayerConstructor, TagConstructor booleanHolderDisplayerConstructor, TagConstructor linkDisplayerConstructor) {
this(parent, FlexDirection.ROW, holderDisplayerConstructor, booleanHolderDisplayerConstructor, linkDisplayerConstructor);
}
public GSSubcellDisplayer(Tag parent, FlexDirection direction, TagConstructor holderDisplayerConstructor, TagConstructor booleanHolderDisplayerConstructor, TagConstructor linkDisplayerConstructor) {
this(parent, direction, holderDisplayerConstructor, booleanHolderDisplayerConstructor, linkDisplayerConstructor, true);
}
public GSSubcellDisplayer(Tag parent, FlexDirection direction, TagConstructor holderDisplayerConstructor, TagConstructor booleanHolderDisplayerConstructor, TagConstructor linkDisplayerConstructor, boolean needMeta) {
super(parent, direction);
this.holderDisplayerConstructor = holderDisplayerConstructor;
this.booleanHolderDisplayerConstructor = booleanHolderDisplayerConstructor;
this.linkDisplayerConstructor = linkDisplayerConstructor;
this.needMeta = needMeta;
addStyle("flex", "1");
content();
}
public void content() {
new GSDiv(this, this.getDirection()) {
{
style(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);
holderDisplayerConstructor.build(this);
}
};
new GSDiv(this, this.getDirection()) {
{
style(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);
booleanHolderDisplayerConstructor.build(this);
}
};
new GSDiv(this, this.getDirection()) {
{
addStyle("flex", "1");
select(gs -> gs[0].getComponents().size() >= 2 ? gs[0] : null);
Tag components = linkDisplayerConstructor.build(this);
style(components);
}
};
}
public void style(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");
}
public static class GSSubcellEditor extends GSSubcellDisplayer {
public GSSubcellEditor(Tag parent) {
this(parent, FlexDirection.ROW);
}
public GSSubcellEditor(Tag parent, FlexDirection direction) {
this(parent, direction, GSHolderEditor::new, GSBooleanHolderEditor::new, GSLinkEditor::new);
}
public GSSubcellEditor(Tag parent, TagConstructor holderEditorConstructor, TagConstructor booleanHolderEditorConstructor, TagConstructor linkEditorConstructor) {
this(parent, FlexDirection.ROW, holderEditorConstructor, booleanHolderEditorConstructor, linkEditorConstructor);
}
public GSSubcellEditor(Tag parent, FlexDirection direction, TagConstructor holderEditorConstructor, TagConstructor booleanHolderEditorConstructor, TagConstructor linkEditorConstructor) {
super(parent, direction, holderEditorConstructor, booleanHolderEditorConstructor, linkEditorConstructor, false);
}
@Override
public void style(Tag tag) {
super.style(tag);
tag.addStyle("color", "#ffffff");
tag.addStyle("background-color", "#dda5e2");
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, GSHolderEditorWithRemoval::new, GSBooleanHolderEditorWithRemoval::new, GSLinkEditorWithRemoval::new);
}
}
public static class GSSubcellAdder extends GSSubcellEditor {
public GSSubcellAdder(Tag parent) {
this(parent, FlexDirection.ROW);
}
public GSSubcellAdder(Tag parent, FlexDirection direction) {
super(parent, direction, GSHolderAdder::new, GSBooleanHolderAdder::new, GSLinkAdder::new);
}
}
public static class GSInstanceSubcellDisplayer extends GSSubcellDisplayer {
public GSInstanceSubcellDisplayer(Tag parent) {
super(parent, GSLabelDisplayer::new, GSCheckBoxDisplayer::new, GSLinkComponentsDisplayer::new);
}
@Override
public void style(Tag tag) {
super.style(tag);
tag.addPrefixBinding(modelContext -> tag.getDomNodeStyles(modelContext).put("background-color",
"Color".equals(StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(modelContext.getGeneric().getMeta())) ? tag.getGenericStringProperty(modelContext).getValue() : "#dda5e2"));
}
}
public static class LinkTitleDisplayer extends GSSubcellDisplayer {
public LinkTitleDisplayer(Tag parent) {
this(parent, GSLabelDisplayer::new, GSCheckBoxDisplayer::new, GSLinkComponentsTitleDisplayer::new);
}
public LinkTitleDisplayer(Tag parent, TagConstructor holderDisplayerConstructor, TagConstructor booleanHolderDisplayerConstructor, TagConstructor linkDisplayerConstructor) {
super(parent, FlexDirection.ROW, holderDisplayerConstructor, booleanHolderDisplayerConstructor, linkDisplayerConstructor);
}
@Override
public void style(Tag tag) {
super.style(tag);
tag.addStyle("color", "#ffffff");
tag.addStyle("background-color", "#ffa5a5");
}
}
public static class InstanceTitleDisplayer extends InstanceLinkTitleDisplayer {
public InstanceTitleDisplayer(Tag parent) {
super(parent);
select(gs -> gs[0].getMeta());
}
}
public static class InstanceLinkTitleDisplayer extends LinkTitleDisplayer {
public InstanceLinkTitleDisplayer(Tag parent) {
super(parent, GSLabelDisplayer::new, GSCheckBoxDisplayer::new, GSInstanceLinkComponentsTitleDisplayer::new);
}
}
@FunctionalInterface
public interface TagConstructor {
Tag build(Tag parent);
}
public static class GSAttributeBuilder extends GSSubcellEditor {
public GSAttributeBuilder(Tag parent, FlexDirection direction) {
super(parent, direction, GSHolderBuilder::new, GSBooleanHolderBuilder::new, GSLinkBuilder::new);
}
@Override
public void style(Tag tag) {
tag.addStyle("flex", "1");
tag.addStyle("color", "#ffffff");
tag.addStyle("background-color", "#dda5a5");
tag.addStyle("margin-right", "1px");
tag.addStyle("margin-bottom", "1px");
}
}
}