1 61 62 package org.nextime.ion.backoffice.tree; 63 64 import java.io.Serializable ; 65 import java.util.ArrayList ; 66 67 76 77 public class TreeControlNode implements Serializable { 78 79 81 99 public TreeControlNode( 100 String name, 101 String icon, 102 String label, 103 String action, 104 String target, 105 boolean expanded) { 106 107 super(); 108 this.name = name; 109 this.icon = icon; 110 this.label = label; 111 this.action = action; 112 this.target = target; 113 this.expanded = expanded; 114 115 } 116 117 119 123 protected ArrayList children = new ArrayList (); 124 125 127 131 protected String action = null; 132 133 public String getAction() { 134 return (this.action); 135 } 136 137 140 protected boolean expanded = false; 141 142 public boolean isExpanded() { 143 return (this.expanded); 144 } 145 146 public void setExpanded(boolean expanded) { 147 this.expanded = expanded; 148 } 149 150 154 protected String icon = null; 155 156 public String getIcon() { 157 return (this.icon); 158 } 159 160 163 protected String label = null; 164 165 public String getLabel() { 166 return (this.label); 167 } 168 169 172 protected boolean last = false; 173 174 public boolean isLast() { 175 return (this.last); 176 } 177 178 void setLast(boolean last) { 179 this.last = last; 180 } 181 182 185 public boolean isLeaf() { 186 synchronized (children) { 187 return (children.size() < 1); 188 } 189 } 190 191 public void up() { 192 TreeControlNode parent = getParent(); 193 ArrayList brothers = parent.children; 194 int myIndex = brothers.indexOf(this); 195 if (myIndex<brothers.size()-1) { 196 TreeControlNode nextOne = 197 (TreeControlNode) brothers.get(myIndex + 1); 198 brothers.set(myIndex, nextOne); 199 brothers.set(myIndex + 1, this); 200 } 201 rebuildLast(brothers); 202 } 203 204 protected void rebuildLast( ArrayList nodes ) { 205 for( int i=1; i<=nodes.size(); i++ ) { 206 TreeControlNode node = (TreeControlNode)nodes.get(i-1); 207 if( i==nodes.size() ) { 208 node.setLast(true); 209 } else { 210 node.setLast(false); 211 } 212 } 213 } 214 215 public void rebuildLast() { 216 ArrayList brothers = parent.children; 217 rebuildLast(brothers); 218 } 219 220 public void rebuildLastChildren() { 221 ArrayList brothers = children; 222 rebuildLast(brothers); 223 } 224 225 public void down() { 226 TreeControlNode parent = getParent(); 227 ArrayList brothers = parent.children; 228 int myIndex = brothers.indexOf(this); 229 if (myIndex>0) { 230 TreeControlNode nextOne = 231 (TreeControlNode) brothers.get(myIndex - 1); 232 brothers.set(myIndex, nextOne); 233 brothers.set(myIndex - 1, this); 234 } 235 rebuildLast(brothers); 236 } 237 238 239 242 protected String name = null; 243 244 public String getName() { 245 return (this.name); 246 } 247 248 252 protected TreeControlNode parent = null; 253 254 public TreeControlNode getParent() { 255 return (this.parent); 256 } 257 258 void setParent(TreeControlNode parent) { 259 this.parent = parent; 260 if (parent == null) 261 width = 1; 262 else 263 width = parent.getWidth() + 1; 264 } 265 266 269 protected boolean selected = false; 270 271 public boolean isSelected() { 272 return (this.selected); 273 } 274 275 public void setSelected(boolean selected) { 276 this.selected = selected; 277 } 278 279 284 protected String target = null; 285 286 public String getTarget() { 287 return (this.target); 288 } 289 290 294 protected TreeControl tree = null; 295 296 public TreeControl getTree() { 297 return (this.tree); 298 } 299 300 void setTree(TreeControl tree) { 301 this.tree = tree; 302 } 303 304 309 protected int width = 0; 310 311 public int getWidth() { 312 return (this.width); 313 } 314 315 317 325 public void addChild(TreeControlNode child) 326 throws IllegalArgumentException { 327 328 tree.addNode(child); 329 child.setParent(this); 330 synchronized (children) { 331 int n = children.size(); 332 if (n > 0) { 333 TreeControlNode node = (TreeControlNode) children.get(n - 1); 334 node.setLast(false); 335 } 336 child.setLast(true); 337 children.add(child); 338 } 339 340 } 341 342 352 public void addChild(int offset, TreeControlNode child) 353 throws IllegalArgumentException { 354 355 tree.addNode(child); 356 child.setParent(this); 357 synchronized (children) { 358 children.add(offset, child); 359 } 360 361 } 362 363 366 public TreeControlNode[] findChildren() { 367 368 synchronized (children) { 369 TreeControlNode results[] = new TreeControlNode[children.size()]; 370 return ((TreeControlNode[]) children.toArray(results)); 371 } 372 373 } 374 375 378 public void remove() { 379 380 if (tree != null) { 381 tree.removeNode(this); 382 } 383 384 } 385 386 393 public void removeChild(int offset) { 394 395 synchronized (children) { 396 TreeControlNode child = (TreeControlNode) children.get(offset); 397 tree.removeNode(child); 398 child.setParent(null); 399 children.remove(offset); 400 } 401 402 } 403 404 406 412 void removeChild(TreeControlNode child) { 413 414 if (child == null) { 415 return; 416 } 417 synchronized (children) { 418 int n = children.size(); 419 for (int i = 0; i < n; i++) { 420 if (child == (TreeControlNode) children.get(i)) { 421 children.remove(i); 422 return; 423 } 424 } 425 } 426 427 } 428 429 433 public void setLabel(String label) { 434 this.label = label; 435 } 436 437 438 442 public void setIcon(String icon) { 443 this.icon = icon; 444 } 445 446 447 } 448 | Popular Tags |