1 | package de.ugoe.cs.eventbench.windows.data;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import de.ugoe.cs.util.StringTools;
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * <p>
|
---|
10 | * This class implements a node in the {@link WindowTree} that is maintained
|
---|
11 | * during parsing a session.
|
---|
12 | * </p>
|
---|
13 | * <p>
|
---|
14 | * The window tree is structure that contains the hierarchy of the windows of a
|
---|
15 | * application as well as basic information about each window: the hwnd; its
|
---|
16 | * name; its resource id; its class name.
|
---|
17 | * </p>
|
---|
18 | *
|
---|
19 | * @author Steffen Herbold
|
---|
20 | */
|
---|
21 | public class WindowTreeNode {
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * <p>
|
---|
25 | * Name of the window. May change over time.
|
---|
26 | * </p>
|
---|
27 | */
|
---|
28 | private String windowName;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * <p>
|
---|
32 | * Handle of the window. Used as unique identifier during its existence.
|
---|
33 | * </p>
|
---|
34 | */
|
---|
35 | private final int hwnd;
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * <p>
|
---|
39 | * Resource id of the window.
|
---|
40 | * </p>
|
---|
41 | */
|
---|
42 | private final int resourceId;
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * <p>
|
---|
46 | * Class name of the window.
|
---|
47 | * </p>
|
---|
48 | */
|
---|
49 | private final String className;
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * <p>
|
---|
53 | * True, if the window is modal.
|
---|
54 | * </p>
|
---|
55 | */
|
---|
56 | private final boolean isModal;
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * <p>
|
---|
60 | * Parent of the window. <code>null</code> if the window has no parent.
|
---|
61 | * </p>
|
---|
62 | */
|
---|
63 | private WindowTreeNode parent;
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * <p>
|
---|
67 | * List of the windows children. May be empty.
|
---|
68 | * </p>
|
---|
69 | */
|
---|
70 | private List<WindowTreeNode> children;
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * <p>
|
---|
74 | * Creates a new WindowTreeNode.
|
---|
75 | * </p>
|
---|
76 | * <p>
|
---|
77 | * The constructor is protected WindowTreeNode may only be created from the
|
---|
78 | * WindowTree.
|
---|
79 | * </p>
|
---|
80 | *
|
---|
81 | * @param hwnd
|
---|
82 | * hwnd of the window
|
---|
83 | * @param parent
|
---|
84 | * reference to the parent's WindowTreeNode
|
---|
85 | * @param windowName
|
---|
86 | * name of the window
|
---|
87 | * @param resourceId
|
---|
88 | * resource id of the window
|
---|
89 | * @param className
|
---|
90 | * class name of the window
|
---|
91 | * @param isModal
|
---|
92 | * modality of the window
|
---|
93 | */
|
---|
94 | protected WindowTreeNode(int hwnd, WindowTreeNode parent,
|
---|
95 | String windowName, int resourceId, String className, boolean isModal) {
|
---|
96 | this.hwnd = hwnd;
|
---|
97 | this.parent = parent;
|
---|
98 | this.windowName = windowName;
|
---|
99 | this.resourceId = resourceId;
|
---|
100 | this.className = className;
|
---|
101 | this.isModal = isModal;
|
---|
102 | children = new ArrayList<WindowTreeNode>();
|
---|
103 | }
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * <p>
|
---|
107 | * Returns a reference to the WindowTreeNode of the parent.
|
---|
108 | * </p>
|
---|
109 | *
|
---|
110 | * @return WindowTreeNode of the parent
|
---|
111 | */
|
---|
112 | public WindowTreeNode getParent() {
|
---|
113 | return parent;
|
---|
114 | }
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * <p>
|
---|
118 | * Returns the list of the windows children.
|
---|
119 | * </p>
|
---|
120 | *
|
---|
121 | * @return list of the windows children
|
---|
122 | */
|
---|
123 | public List<WindowTreeNode> getChildren() {
|
---|
124 | return children;
|
---|
125 | }
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * <p>
|
---|
129 | * Returns the name of the window.
|
---|
130 | * </p>
|
---|
131 | *
|
---|
132 | * @return name of the window
|
---|
133 | */
|
---|
134 | public String getName() {
|
---|
135 | return windowName;
|
---|
136 | }
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * <p>
|
---|
140 | * Returns the hwnd of the window.
|
---|
141 | * </p>
|
---|
142 | *
|
---|
143 | * @return hwnd of the window
|
---|
144 | */
|
---|
145 | public int getHwnd() {
|
---|
146 | return hwnd;
|
---|
147 | }
|
---|
148 |
|
---|
149 | /**
|
---|
150 | * <p>
|
---|
151 | * Returns the resource id of the window.
|
---|
152 | * </p>
|
---|
153 | *
|
---|
154 | * @return resource id of the window
|
---|
155 | */
|
---|
156 | public int getResourceId() {
|
---|
157 | return resourceId;
|
---|
158 | }
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * <p>
|
---|
162 | * Returns the class name of the window.
|
---|
163 | * </p>
|
---|
164 | *
|
---|
165 | * @return
|
---|
166 | */
|
---|
167 | public String getClassName() {
|
---|
168 | return className;
|
---|
169 | }
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * <p>
|
---|
173 | * Sets the name of the window.
|
---|
174 | * </p>
|
---|
175 | *
|
---|
176 | * @param text
|
---|
177 | * new name of the window
|
---|
178 | */
|
---|
179 | public void setName(String text) {
|
---|
180 | windowName = text;
|
---|
181 | }
|
---|
182 |
|
---|
183 | /**
|
---|
184 | * <p>
|
---|
185 | * Removes a the window and all its children from the {@link WindowTree}.
|
---|
186 | * </p>
|
---|
187 | *
|
---|
188 | * @return list of the children of the window for further clean up.
|
---|
189 | */
|
---|
190 | public List<WindowTreeNode> remove() {
|
---|
191 | if (parent != null) {
|
---|
192 | parent.removeChild(this);
|
---|
193 | }
|
---|
194 | return children;
|
---|
195 | }
|
---|
196 |
|
---|
197 | /**
|
---|
198 | * <p>
|
---|
199 | * Removes a child window.
|
---|
200 | * </p>
|
---|
201 | *
|
---|
202 | * @param child
|
---|
203 | * reference to the child window to be removed
|
---|
204 | */
|
---|
205 | public void removeChild(WindowTreeNode child) {
|
---|
206 | children.remove(child);
|
---|
207 | }
|
---|
208 |
|
---|
209 | /**
|
---|
210 | * <p>
|
---|
211 | * Adds a new child window and creates WindowTreeNode for it.
|
---|
212 | * </p>
|
---|
213 | *
|
---|
214 | * @param childHwnd
|
---|
215 | * hwnd of the child window
|
---|
216 | * @param childWindowName
|
---|
217 | * name of the child window
|
---|
218 | * @param resourceId
|
---|
219 | * resource id of the child window
|
---|
220 | * @param className
|
---|
221 | * class name of the child window
|
---|
222 | * @param isModal
|
---|
223 | * modality of the child window
|
---|
224 | * @return reference to the WindowTreeNode created for the child window
|
---|
225 | */
|
---|
226 | public WindowTreeNode addChild(int childHwnd, String childWindowName,
|
---|
227 | int resourceId, String className, boolean isModal) {
|
---|
228 | WindowTreeNode child = new WindowTreeNode(childHwnd, this,
|
---|
229 | childWindowName, resourceId, className, isModal);
|
---|
230 | children.add(child);
|
---|
231 | return child;
|
---|
232 | }
|
---|
233 |
|
---|
234 | /**
|
---|
235 | * <p>
|
---|
236 | * Returns a string identfier of the window:<br>
|
---|
237 | * {@code [resourceId;"windowName";"className";modality]}
|
---|
238 | * </p>
|
---|
239 | *
|
---|
240 | * @return identifier string of the window
|
---|
241 | */
|
---|
242 | @Override
|
---|
243 | public String toString() {
|
---|
244 | return "[" + resourceId + ";\"" + windowName + "\";\"" + className
|
---|
245 | + "\";" + isModal + "]";
|
---|
246 | }
|
---|
247 |
|
---|
248 | /**
|
---|
249 | * <p>
|
---|
250 | * Returns an XML representation of the window, including its parents. It is
|
---|
251 | * defined as follows:<br>
|
---|
252 | * <code>
|
---|
253 | * parent#xmlRepresentation()<br>
|
---|
254 | * <window name="this.windowname" class="this.className" resourceId="this.resourceId" isModal="this.isModel"/>
|
---|
255 | * </code>
|
---|
256 | * </p>
|
---|
257 | *
|
---|
258 | * @return xml representation of the window
|
---|
259 | */
|
---|
260 | public String xmlRepresentation() {
|
---|
261 | String xmlString = "";
|
---|
262 | if (parent != null) {
|
---|
263 | xmlString = parent.xmlRepresentation();
|
---|
264 | }
|
---|
265 | xmlString += "<window name=\"" + StringTools.xmlEntityReplacement(windowName) + "\" class=\""
|
---|
266 | + StringTools.xmlEntityReplacement(className) + "\" resourceId=\"" + resourceId + "\" isModal=\""
|
---|
267 | + isModal + "\"/>";
|
---|
268 | return xmlString;
|
---|
269 | }
|
---|
270 |
|
---|
271 | public String getParentNames() {
|
---|
272 | String parentNames = "";
|
---|
273 | if (parent != null ) {
|
---|
274 | parentNames = parent.getParentNames()+".";
|
---|
275 | }
|
---|
276 | parentNames += windowName;
|
---|
277 | return parentNames;
|
---|
278 | }
|
---|
279 |
|
---|
280 | }
|
---|