-
Notifications
You must be signed in to change notification settings - Fork 5
/
RootTag.java
224 lines (182 loc) · 8 KB
/
RootTag.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
package org.genericsystem.reactor;
import org.genericsystem.reactor.HtmlDomNode.RootHtmlDomNode;
import org.genericsystem.reactor.HtmlDomNode.Sender;
import org.genericsystem.reactor.context.ContextAction;
import org.genericsystem.reactor.context.StringExtractor;
import org.genericsystem.reactor.context.TextBinding;
import org.genericsystem.reactor.context.TextBinding.GENERIC_STRING;
import org.genericsystem.reactor.contextproperties.ActionDefaults;
import org.genericsystem.reactor.contextproperties.FlexDirectionDefaults;
import org.genericsystem.reactor.contextproperties.GenericStringDefaults;
import org.genericsystem.reactor.contextproperties.TextPropertyDefaults;
import org.genericsystem.reactor.gscomponents.FlexDirection;
import org.genericsystem.reactor.gscomponents.TagImpl;
public interface RootTag extends Tag {
default RootHtmlDomNode init(Context rootModelContext, String rootId, Sender send) {
return new RootHtmlDomNode(rootModelContext, this, rootId, send);
}
@Override
default RootTag getRootTag() {
return this;
}
AnnotationsManager getAnnotationsManager();
default void processAnnotations(Tag tag) {
getAnnotationsManager().processAnnotations(tag);
}
TagNode buildTagNode(Tag child);
default void processChildren(Tag tag, Class<? extends TagImpl>[] classes) {
for (Class<? extends TagImpl> clazz : classes) {
TagImpl result = createChild(tag, clazz);
result.setTagNode(buildTagNode(result));
}
}
default <T extends TagImpl> TagImpl createChild(Tag tag, Class<T> clazz) {
T result = null;
try {
result = clazz.newInstance();
} catch (IllegalAccessException | InstantiationException e) {
throw new IllegalStateException(e);
}
result.setParent(tag);
return result;
}
default void processStyle(Tag tag, String name, String value) {
tag.addPrefixBinding(context -> processStyle(tag, context, name, value));
}
default void processStyle(Tag tag, Context context, String name, String value) {
tag.addStyle(context, name, value);
}
default void removeStyle(Tag tag, Context context, String name) {
tag.getDomNodeStyles(context).remove(name);
}
default void processAttribute(Tag tag, String name, String value) {
tag.addPrefixBinding(context -> processAttribute(tag, context, name, value));
}
default void processAttribute(Tag tag, Context context, String name, String value) {
tag.addAttribute(context, name, value);
}
default void removeAttribute(Tag tag, Context context, String name) {
tag.getDomNodeAttributes(context).remove(name);
}
default void processGenericValueBackgroundColor(Tag tag, String value) {
tag.addPrefixBinding(context -> processGenericValueBackgroundColor(tag, context, value));
}
default void processGenericValueBackgroundColor(Tag tag, Context context, String value) {
tag.addStyle(context, "background-color", "Color".equals(StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(context.getGeneric().getMeta())) ? ((GenericStringDefaults) tag).getGenericStringProperty(context).getValue() : value);
}
default void removeGenericValueBackgroundColor(Tag tag, Context context) {
tag.getDomNodeStyles(context).remove("background-color");
}
default void processFlexDirectionStyle(Tag tag, FlexDirection flexDirection) {
tag.addPrefixBinding(context -> processFlexDirectionStyle(tag, context, flexDirection));
}
default void processFlexDirectionStyle(Tag tag, Context context, FlexDirection flexDirection) {
if (FlexDirectionDefaults.class.isAssignableFrom(tag.getClass()))
((FlexDirectionDefaults) tag).setDirection(context, flexDirection);
else
log.warn("Warning: FlexDirection is applicable only to classes implementing FlexDirectionDefaults.");
}
default void removeFlexDirectionStyle(Tag tag, Context context) {
if (FlexDirectionDefaults.class.isAssignableFrom(tag.getClass()))
((FlexDirectionDefaults) tag).setDirection(context, null);
else
log.warn("Warning: FlexDirection is applicable only to classes implementing FlexDirectionDefaults.");
}
default void processReverseFlexDirection(Tag tag) {
tag.addPrefixBinding(context -> processReverseFlexDirection(tag, context));
}
default void processReverseFlexDirection(Tag tag, Context context) {
if (FlexDirectionDefaults.class.isAssignableFrom(tag.getClass()))
((FlexDirectionDefaults) tag).reverseDirection(context);
else
log.warn("Warning: ReverseFlexDirection is applicable only to classes implementing FlexDirectionDefaults.");
}
default void removeDirectionTracking(Tag tag, Context context) {
((FlexDirectionDefaults) tag).stopTrackingDirection(context);
}
default void processKeepFlexDirection(Tag tag) {
tag.addPrefixBinding(context -> processKeepFlexDirection(tag, context));
}
default void processKeepFlexDirection(Tag tag, Context context) {
if (FlexDirectionDefaults.class.isAssignableFrom(tag.getClass()))
((FlexDirectionDefaults) tag).keepDirection(context);
else
log.warn("Warning: KeepFlexDirection is applicable only to classes implementing FlexDirectionDefaults.");
}
default void processStyleClass(Tag tag, String[] classes) {
tag.addPrefixBinding(context -> processStyleClass(tag, context, classes));
}
default void processStyleClass(Tag tag, Context context, String[] classes) {
for (String sc : classes)
tag.addStyleClass(context, sc);
}
default void removeStyleClass(Tag tag, Context context, String[] classes) {
for (String styleClass : classes)
tag.removeStyleClass(context, styleClass);
}
default void processSetText(Tag tag, Class<?>[] path, String[] texts) {
tag.addPrefixBinding(context -> processSetText(tag, context, path, texts));
}
default void processSetText(Tag tag, Context context, Class<?>[] path, String[] texts) {
if (texts.length == 1)
tag.setText(context, texts[0]);
else
tag.setText(context, texts[AnnotationsManager.position(tag, path[path.length - 1])]);
}
default void removeSetText(Tag tag, Context context) {
tag.setText(context, "");
}
default void processBindText(Tag tag, Class<? extends TextBinding> value) {
tag.addPrefixBinding(context -> processBindText(tag, context, value));
}
default void processBindText(Tag tag, Context context, Class<? extends TextBinding> value) {
if (GENERIC_STRING.class.equals(value))
tag.bindText(context);
else
tag.bindText(context, context_ -> {
try {
return value.newInstance().apply(context_, tag);
} catch (InstantiationException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
});
}
default void removeBindText(Tag tag, Context context) {
tag.getDomNodeTextProperty(context).unbind();
context.getPropertiesMaps(tag).remove(TextPropertyDefaults.TEXT_BINDING);
tag.getDomNodeTextProperty(context).setValue(null);
}
default void processBindAction(Tag tag, Class<? extends ContextAction> value) {
tag.addPrefixBinding(context -> processBindAction(tag, context, value));
}
default void processBindAction(Tag tag, Context context, Class<? extends ContextAction> value) {
if (ActionDefaults.class.isAssignableFrom(tag.getClass()))
((ActionDefaults) tag).bindAction(context, context_ -> {
try {
value.newInstance().accept(context_, tag);
} catch (InstantiationException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
});
else
log.warn("BindAction is applicable only to tags implementing ActionDefaults.");
}
default void removeBindAction(Tag tag, Context context) {
context.getPropertiesMaps(tag).remove(ActionDefaults.ACTION);
}
default void processSetStringExtractor(Tag tag, Class<? extends StringExtractor> value) {
tag.addPrefixBinding(context -> processSetStringExtractor(tag, context, value));
}
default void processSetStringExtractor(Tag tag, Context context, Class<? extends StringExtractor> value) {
try {
tag.setStringExtractor(context, value.newInstance());
} catch (InstantiationException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
}
default void removeStringExtractor(Tag tag, Context context) {
tag.getStringExtractorProperty(context).setValue(null);
}
default void initDomNode(HtmlDomNode domNode) {
}
}