1 16 17 18 package org.apache.webapp.admin; 19 20 21 import java.io.Serializable ; 22 import java.util.ArrayList ; 23 24 25 34 35 public class TreeControlNode implements Serializable { 36 37 38 40 41 59 public TreeControlNode(String name, 60 String icon, String label, 61 String action, String target, 62 boolean expanded, String domain) { 63 64 super(); 65 this.name = name; 66 this.icon = icon; 67 this.label = label; 68 this.action = action; 69 this.target = target; 70 this.expanded = expanded; 71 this.domain = domain; 72 73 } 74 75 76 78 79 83 protected ArrayList children = new ArrayList (); 84 85 86 88 89 93 protected String action = null; 94 95 public String getAction() { 96 return (this.action); 97 } 98 99 102 protected String domain = null; 103 104 public String getDomain() { 105 return (this.domain); 106 } 107 108 111 protected boolean expanded = false; 112 113 public boolean isExpanded() { 114 return (this.expanded); 115 } 116 117 public void setExpanded(boolean expanded) { 118 this.expanded = expanded; 119 } 120 121 122 126 protected String icon = null; 127 128 public String getIcon() { 129 return (this.icon); 130 } 131 132 133 136 protected String label = null; 137 138 public String getLabel() { 139 return (this.label); 140 } 141 142 143 146 protected boolean last = false; 147 148 public boolean isLast() { 149 return (this.last); 150 } 151 152 void setLast(boolean last) { 153 this.last = last; 154 } 155 156 157 160 public boolean isLeaf() { 161 synchronized (children) { 162 return (children.size() < 1); 163 } 164 } 165 166 167 170 protected String name = null; 171 172 public String getName() { 173 return (this.name); 174 } 175 176 177 181 protected TreeControlNode parent = null; 182 183 public TreeControlNode getParent() { 184 return (this.parent); 185 } 186 187 void setParent(TreeControlNode parent) { 188 this.parent = parent; 189 if (parent == null) 190 width = 1; 191 else 192 width = parent.getWidth() + 1; 193 } 194 195 196 199 protected boolean selected = false; 200 201 public boolean isSelected() { 202 return (this.selected); 203 } 204 205 public void setSelected(boolean selected) { 206 this.selected = selected; 207 } 208 209 210 215 protected String target = null; 216 217 public String getTarget() { 218 return (this.target); 219 } 220 221 222 226 protected TreeControl tree = null; 227 228 public TreeControl getTree() { 229 return (this.tree); 230 } 231 232 void setTree(TreeControl tree) { 233 this.tree = tree; 234 } 235 236 237 242 protected int width = 0; 243 244 public int getWidth() { 245 return (this.width); 246 } 247 248 249 251 252 260 public void addChild(TreeControlNode child) 261 throws IllegalArgumentException { 262 263 tree.addNode(child); 264 child.setParent(this); 265 synchronized (children) { 266 int n = children.size(); 267 if (n > 0) { 268 TreeControlNode node = (TreeControlNode) children.get(n - 1); 269 node.setLast(false); 270 } 271 child.setLast(true); 272 children.add(child); 273 } 274 275 } 276 277 278 288 public void addChild(int offset, TreeControlNode child) 289 throws IllegalArgumentException { 290 291 tree.addNode(child); 292 child.setParent(this); 293 synchronized (children) { 294 children.add(offset, child); 295 } 296 297 } 298 299 300 303 public TreeControlNode[] findChildren() { 304 305 synchronized (children) { 306 TreeControlNode results[] = new TreeControlNode[children.size()]; 307 return ((TreeControlNode[]) children.toArray(results)); 308 } 309 310 } 311 312 313 316 public void remove() { 317 318 if (tree != null) { 319 tree.removeNode(this); 320 } 321 322 } 323 324 325 332 public void removeChild(int offset) { 333 334 synchronized (children) { 335 TreeControlNode child = 336 (TreeControlNode) children.get(offset); 337 tree.removeNode(child); 338 child.setParent(null); 339 children.remove(offset); 340 } 341 342 } 343 344 345 347 348 354 void removeChild(TreeControlNode child) { 355 356 if (child == null) { 357 return; 358 } 359 synchronized (children) { 360 int n = children.size(); 361 for (int i = 0; i < n; i++) { 362 if (child == (TreeControlNode) children.get(i)) { 363 children.remove(i); 364 return; 365 } 366 } 367 } 368 369 } 370 371 372 } 373 | Popular Tags |