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