1 15 16 package com.jdon.strutsutil.treeview; 17 18 import java.io.Serializable ; 19 import java.util.*; 20 21 43 44 public class ViewNode implements Serializable { 45 46 private boolean last = false; 48 private boolean leaf = false; 50 51 private boolean selected = false; 53 private boolean expanded = false; 55 56 private ViewNode parent = null; 58 private int depth = 0; 60 61 private TreeControl tree = null; 63 private List children = new ArrayList(); 65 66 protected String key = null; 68 protected String label = null; 70 71 protected boolean root = false; 73 75 public boolean isLast() { 76 return (this.last); 77 } 78 public void setLast(boolean last) { 79 this.last = last; 80 } 81 82 public boolean isLeaf() { 83 return (this.leaf); 84 } 85 public void setTree(TreeControl tree) { 86 this.tree = tree; 87 } 88 public void clearChildren() { 89 children.clear(); 90 } 91 92 95 public ViewNode[] findChildren() { 96 synchronized (children) { 97 ViewNode results[] = new ViewNode[children.size()]; 98 return ( (ViewNode[]) children.toArray(results)); 99 } 100 } 101 102 107 public void addChild(ViewNode child) throws IllegalArgumentException { 108 tree.addNode(child); 109 child.setParent(this); 110 this.leaf = false; int n = children.size(); 112 if (n > 0) { 113 ViewNode node = (ViewNode) children.get(n - 1); 114 node.setLast(false); 115 } 116 child.setLast(true); 117 children.add(child); 118 } 119 120 public ViewNode getParent() { 121 return (this.parent); 122 } 123 124 public void setParent(ViewNode parent) { 125 this.parent = parent; 126 if (parent == null) 127 depth = 1; 128 else 129 depth = parent.getDepth() + 1; 130 } 131 132 public int getDepth() { 133 return depth; 134 } 135 136 138 140 public boolean isSelected() { 141 return (this.selected); 142 } 143 144 public void setSelected(boolean selected) { 145 this.selected = selected; 146 } 147 148 public boolean isExpanded() { 149 return (this.expanded); 150 } 151 152 public void setExpanded(boolean expanded) { 153 this.expanded = expanded; 154 } 155 156 158 160 public String getKey() { 161 return (this.key); 162 } 163 164 public String getLabel() { 165 return (this.label); 166 } 167 public boolean isRoot() { 168 return root; 169 } 170 public void setRoot(boolean root) { 171 this.root = root; 172 } 173 174 176 public ViewNode(String key, String label, boolean leaf) { 177 super(); 178 this.key = key; 179 this.label = label; 180 this.leaf = leaf; 181 } 182 183 } 184 | Popular Tags |