1 | package com.framsticks.test; |
---|
2 | |
---|
3 | import java.util.Map; |
---|
4 | |
---|
5 | import org.apache.logging.log4j.Logger; |
---|
6 | import org.apache.logging.log4j.LogManager; |
---|
7 | |
---|
8 | import com.framsticks.params.EventListener; |
---|
9 | import com.framsticks.params.SimplePrimitive; |
---|
10 | import com.framsticks.params.SimpleUniqueList; |
---|
11 | import com.framsticks.params.annotations.AutoAppendAnnotation; |
---|
12 | import com.framsticks.params.annotations.FramsClassAnnotation; |
---|
13 | import com.framsticks.params.annotations.ParamAnnotation; |
---|
14 | import com.framsticks.params.types.ProcedureParam; |
---|
15 | import com.framsticks.structure.messages.ListChange; |
---|
16 | import com.framsticks.structure.messages.ValueChange; |
---|
17 | |
---|
18 | @FramsClassAnnotation( |
---|
19 | order = { |
---|
20 | "name", |
---|
21 | "history", |
---|
22 | "history_changed", |
---|
23 | "appendHistory", |
---|
24 | "resetHistory", |
---|
25 | "children", |
---|
26 | "createChild", |
---|
27 | "children_changed" |
---|
28 | } |
---|
29 | ) |
---|
30 | public class TestClass { |
---|
31 | private static final Logger log = LogManager.getLogger(TestClass.class); |
---|
32 | |
---|
33 | |
---|
34 | protected String name = "test"; |
---|
35 | protected final SimplePrimitive<String> history = new SimplePrimitive<>("initial|"); |
---|
36 | |
---|
37 | protected final SimpleUniqueList<TestChild> children = new SimpleUniqueList<>(TestChild.class, 'c'); |
---|
38 | |
---|
39 | /** |
---|
40 | * |
---|
41 | */ |
---|
42 | public TestClass() { |
---|
43 | } |
---|
44 | |
---|
45 | /** |
---|
46 | * @return the name |
---|
47 | */ |
---|
48 | @ParamAnnotation |
---|
49 | public String getName() { |
---|
50 | return name; |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * @param name the name to set |
---|
55 | */ |
---|
56 | @ParamAnnotation |
---|
57 | public void setName(String name) { |
---|
58 | this.name = name; |
---|
59 | } |
---|
60 | |
---|
61 | /** |
---|
62 | * @return the history |
---|
63 | */ |
---|
64 | @ParamAnnotation |
---|
65 | public String getHistory() { |
---|
66 | return history.get(); |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * @param history the history to set |
---|
71 | */ |
---|
72 | @ParamAnnotation |
---|
73 | public void setHistory(String history) { |
---|
74 | this.history.set(history); |
---|
75 | } |
---|
76 | |
---|
77 | /** |
---|
78 | * @return the children |
---|
79 | */ |
---|
80 | @ParamAnnotation |
---|
81 | public Map<String, TestChild> getChildren() { |
---|
82 | return children.getMap(); |
---|
83 | } |
---|
84 | |
---|
85 | @ParamAnnotation(paramType = ProcedureParam.class) |
---|
86 | public int appendHistory(String line) { |
---|
87 | log.debug("appending '{}'", line); |
---|
88 | history.set(history.get() + line + "|"); |
---|
89 | // fireHistoryChange(); |
---|
90 | return history.get().length(); |
---|
91 | } |
---|
92 | |
---|
93 | @ParamAnnotation(paramType = ProcedureParam.class) |
---|
94 | public void resetHistory() { |
---|
95 | log.debug("reseting"); |
---|
96 | history.set(""); |
---|
97 | } |
---|
98 | |
---|
99 | @ParamAnnotation(paramType = ProcedureParam.class) |
---|
100 | public void createChild(String name) { |
---|
101 | TestChild child = new TestChild(); |
---|
102 | child.name = name; |
---|
103 | addChild(child); |
---|
104 | } |
---|
105 | |
---|
106 | @AutoAppendAnnotation |
---|
107 | public void addChild(TestChild child) { |
---|
108 | child.parent = this; |
---|
109 | children.add(child); |
---|
110 | } |
---|
111 | |
---|
112 | @ParamAnnotation(id = "history_changed") |
---|
113 | public void addHistoryListener(EventListener<ValueChange> listener) { |
---|
114 | history.addListener(listener); |
---|
115 | } |
---|
116 | |
---|
117 | @ParamAnnotation(id = "history_changed") |
---|
118 | public void removeHistoryListener(EventListener<ValueChange> listener) { |
---|
119 | history.removeListener(listener); |
---|
120 | } |
---|
121 | |
---|
122 | @ParamAnnotation(id = "children_changed") |
---|
123 | public void addChildrenListener(EventListener<ListChange> listener) { |
---|
124 | children.addListener(listener); |
---|
125 | } |
---|
126 | |
---|
127 | @ParamAnnotation(id = "children_changed") |
---|
128 | public void removeChildrenListener(EventListener<ListChange> listener) { |
---|
129 | children.removeListener(listener); |
---|
130 | } |
---|
131 | |
---|
132 | @Override |
---|
133 | public String toString() { |
---|
134 | return "test class " + history; |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | } |
---|