1 61 62 package org.objectweb.jonas.webapp.taglib; 63 64 import java.io.Serializable ; 65 import java.util.ArrayList ; 66 67 68 77 78 public class TreeControlNode implements Serializable { 79 80 82 100 public TreeControlNode(String name, String icon, String label, String action, String target 101 , boolean expanded) { 102 103 super(); 104 this.name = name; 105 this.icon = icon; 106 this.label = label; 107 this.action = action; 108 this.target = target; 109 this.expanded = expanded; 110 111 } 112 113 public TreeControlNode(TreeControlNode p_Node) { 114 super(); 115 this.name = p_Node.getName(); 116 this.icon = p_Node.getIcon(); 117 this.label = p_Node.getLabel(); 118 this.action = p_Node.getAction(); 119 this.target = p_Node.getTarget(); 120 this.expanded = p_Node.isExpanded(); 121 } 122 123 125 129 protected ArrayList children = new ArrayList (); 130 131 133 137 protected String action = null; 138 139 public String getAction() { 140 return (this.action); 141 } 142 143 146 protected boolean expanded = false; 147 148 public boolean isExpanded() { 149 return (this.expanded); 150 } 151 152 public void setExpanded(boolean expanded) { 153 this.expanded = expanded; 154 } 155 156 160 protected String icon = null; 161 162 public String getIcon() { 163 return (this.icon); 164 } 165 166 169 protected String label = null; 170 171 public String getLabel() { 172 return (this.label); 173 } 174 175 178 protected boolean last = false; 179 180 public boolean isLast() { 181 return (this.last); 182 } 183 184 void setLast(boolean last) { 185 this.last = last; 186 } 187 188 191 public boolean isLeaf() { 192 synchronized (children) { 193 return (children.size() < 1); 194 } 195 } 196 197 200 protected String name = null; 201 202 public String getName() { 203 return (this.name); 204 } 205 206 210 protected TreeControlNode parent = null; 211 212 public TreeControlNode getParent() { 213 return (this.parent); 214 } 215 216 void setParent(TreeControlNode parent) { 217 this.parent = parent; 218 if (parent == null) { 219 width = 1; 220 } 221 else { 222 width = parent.getWidth() + 1; 223 } 224 } 225 226 229 protected boolean selected = false; 230 231 public boolean isSelected() { 232 return (this.selected); 233 } 234 235 public void setSelected(boolean selected) { 236 this.selected = selected; 237 } 238 239 244 protected String target = null; 245 246 public String getTarget() { 247 return (this.target); 248 } 249 250 254 protected TreeControl tree = null; 255 256 public TreeControl getTree() { 257 return (this.tree); 258 } 259 260 void setTree(TreeControl tree) { 261 this.tree = tree; 262 } 263 264 269 protected int width = 0; 270 271 public int getWidth() { 272 return (this.width); 273 } 274 275 277 285 public void addChild(TreeControlNode child) 286 throws IllegalArgumentException { 287 288 tree.addNode(child); 289 child.setParent(this); 290 synchronized (children) { 291 int n = children.size(); 292 if (n > 0) { 293 TreeControlNode node = (TreeControlNode) children.get(n - 1); 294 node.setLast(false); 295 } 296 child.setLast(true); 297 children.add(child); 298 } 299 300 } 301 302 312 public void addChild(int offset, TreeControlNode child) 313 throws IllegalArgumentException { 314 315 tree.addNode(child); 316 child.setParent(this); 317 synchronized (children) { 318 children.add(offset, child); 319 } 320 321 } 322 323 326 public TreeControlNode[] findChildren() { 327 328 synchronized (children) { 329 TreeControlNode results[] = new TreeControlNode[children.size()]; 330 return ((TreeControlNode[]) children.toArray(results)); 331 } 332 333 } 334 335 338 public void remove() { 339 340 if (tree != null) { 341 tree.removeNode(this); 342 } 343 344 } 345 346 353 public void removeChild(int offset) { 354 355 synchronized (children) { 356 TreeControlNode child = (TreeControlNode) children.get(offset); 357 tree.removeNode(child); 358 child.setParent(null); 359 children.remove(offset); 360 } 361 362 } 363 364 365 public String toString() { 366 StringBuffer sb = new StringBuffer (); 367 sb.append(getName()); 368 sb.append(" - "); 369 sb.append(isExpanded()); 370 371 return sb.toString(); 372 } 373 374 376 382 void removeChild(TreeControlNode child) { 383 384 if (child == null) { 385 return; 386 } 387 synchronized (children) { 388 int n = children.size(); 389 for (int i = 0; i < n; i++) { 390 if (child == (TreeControlNode) children.get(i)) { 391 children.remove(i); 392 return; 393 } 394 } 395 } 396 397 } 398 399 } 400 | Popular Tags |