-
Notifications
You must be signed in to change notification settings - Fork 5
/
RootTag.java
155 lines (133 loc) · 5.3 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
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.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 -> tag.getDomNodeStyles(context).put(name, value));
}
default void processGenericValueBackgroundColor(Tag tag, String value) {
tag.addPrefixBinding(
context -> tag.addStyle(context, "background-color", "Color".equals(StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(context.getGeneric().getMeta())) ? ((GenericStringDefaults) tag).getGenericStringProperty(context).getValue() : value));
}
default void processFlexDirectionStyle(Tag tag, FlexDirection flexDirection) {
if (FlexDirectionDefaults.class.isAssignableFrom(tag.getClass()))
((FlexDirectionDefaults) tag).setDirection(flexDirection);
else
log.warn("Warning: FlexDirection is applicable only to classes implementing FlexDirectionDefaults.");
}
default void processReverseFlexDirection(Tag tag) {
if (FlexDirectionDefaults.class.isAssignableFrom(tag.getClass()))
((FlexDirectionDefaults) tag).reverseDirection();
else
log.warn("Warning: ReverseFlexDirection is applicable only to classes implementing FlexDirectionDefaults.");
}
default void processKeepFlexDirection(Tag tag) {
if (FlexDirectionDefaults.class.isAssignableFrom(tag.getClass()))
((FlexDirectionDefaults) tag).keepDirection();
else
log.warn("Warning: KeepFlexDirection is applicable only to classes implementing FlexDirectionDefaults.");
}
default void processStyleClass(Tag tag, String[] classes) {
for (String sc : classes)
tag.addStyleClass(sc);
}
default void processSetText(Tag tag, Class<?>[] path, String[] texts) {
if (texts.length == 1)
tag.setText(texts[0]);
else
tag.setText(texts[AnnotationsManager.position(tag, path[path.length - 1])]);
}
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 processBindText(Tag tag, Class<? extends TextBinding> value) {
if (GENERIC_STRING.class.equals(value))
tag.bindText();
else
tag.bindText(context -> {
try {
return value.newInstance().apply(context, tag);
} catch (InstantiationException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
});
}
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 processBindAction(Tag tag, Class<? extends ContextAction> value) {
if (ActionDefaults.class.isAssignableFrom(tag.getClass()))
((ActionDefaults) tag).bindAction(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 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 initDomNode(HtmlDomNode htmlDomNode) {
}
}