-
Notifications
You must be signed in to change notification settings - Fork 5
/
StyleClass.java
66 lines (54 loc) · 2.49 KB
/
StyleClass.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
package org.genericsystem.reactor.annotations;
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.function.BiConsumer;
import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.ExtendedAnnotationsManager.IGenericAnnotationProcessor;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.annotations.StyleClass.StyleClassGenericProcessor;
import org.genericsystem.reactor.annotations.StyleClass.StyleClassProcessor;
import org.genericsystem.reactor.annotations.StyleClass.StyleClasses;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.GTag;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.GTagAnnotation;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.GTagAnnotationContent;
import org.genericsystem.reactor.gscomponents.TagImpl;
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@Repeatable(StyleClasses.class)
@Process(StyleClassProcessor.class)
@GenericProcess(StyleClassGenericProcessor.class)
public @interface StyleClass {
Class<? extends TagImpl>[] path() default {};
String[] value();
int[] pos() default {};
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
public @interface StyleClasses {
StyleClass[] value();
}
public static class StyleClassProcessor implements BiConsumer<Annotation, Tag> {
@Override
public void accept(Annotation annotation, Tag tag) {
tag.getRootTag().processStyleClass(tag, ((StyleClass) annotation).value());
}
}
public static class StyleClassGenericProcessor implements IGenericAnnotationProcessor {
@Override
public void setAnnotation(GTag gTag, Annotation annotation) {
gTag.setArrayValueAnnotation(StyleClass.class, null, ((StyleClass) annotation).value(), ((StyleClass) annotation).path(), ((StyleClass) annotation).pos());
}
@Override
public void onRemove(Tag tag, Context context, GTagAnnotation gTagAnnotation, GTagAnnotationContent annotationContent) {
for (String styleClass : annotationContent.getContentJSonArray().stream().toArray(String[]::new))
tag.removeStyleClass(context, styleClass);
}
@Override
public void onAdd(Tag tag, Context context, GTagAnnotation gTagAnnotation, GTagAnnotationContent annotationContent) {
tag.getRootTag().processStyleClass(tag, context, annotationContent.getStringArrayContent());
}
}
}