00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 package org.objectweb.jonas.webapp.taglib;
00063
00064 import java.io.Serializable;
00065 import java.util.ArrayList;
00066
00067
00078 public class TreeControlNode implements Serializable {
00079
00080
00081
00100 public TreeControlNode(String name, String icon, String label, String action, String target
00101 , boolean expanded) {
00102
00103 super();
00104 this.name = name;
00105 this.icon = icon;
00106 this.label = label;
00107 this.action = action;
00108 this.target = target;
00109 this.expanded = expanded;
00110
00111 }
00112
00113 public TreeControlNode(TreeControlNode p_Node) {
00114 super();
00115 this.name = p_Node.getName();
00116 this.icon = p_Node.getIcon();
00117 this.label = p_Node.getLabel();
00118 this.action = p_Node.getAction();
00119 this.target = p_Node.getTarget();
00120 this.expanded = p_Node.isExpanded();
00121 }
00122
00123
00124
00129 protected ArrayList children = new ArrayList();
00130
00131
00132
00137 protected String action = null;
00138
00139 public String getAction() {
00140 return (this.action);
00141 }
00142
00146 protected boolean expanded = false;
00147
00148 public boolean isExpanded() {
00149 return (this.expanded);
00150 }
00151
00152 public void setExpanded(boolean expanded) {
00153 this.expanded = expanded;
00154 }
00155
00160 protected String icon = null;
00161
00162 public String getIcon() {
00163 return (this.icon);
00164 }
00165
00169 protected String label = null;
00170
00171 public String getLabel() {
00172 return (this.label);
00173 }
00174
00178 protected boolean last = false;
00179
00180 public boolean isLast() {
00181 return (this.last);
00182 }
00183
00184 void setLast(boolean last) {
00185 this.last = last;
00186 }
00187
00191 public boolean isLeaf() {
00192 synchronized (children) {
00193 return (children.size() < 1);
00194 }
00195 }
00196
00200 protected String name = null;
00201
00202 public String getName() {
00203 return (this.name);
00204 }
00205
00210 protected TreeControlNode parent = null;
00211
00212 public TreeControlNode getParent() {
00213 return (this.parent);
00214 }
00215
00216 void setParent(TreeControlNode parent) {
00217 this.parent = parent;
00218 if (parent == null) {
00219 width = 1;
00220 }
00221 else {
00222 width = parent.getWidth() + 1;
00223 }
00224 }
00225
00229 protected boolean selected = false;
00230
00231 public boolean isSelected() {
00232 return (this.selected);
00233 }
00234
00235 public void setSelected(boolean selected) {
00236 this.selected = selected;
00237 }
00238
00244 protected String target = null;
00245
00246 public String getTarget() {
00247 return (this.target);
00248 }
00249
00254 protected TreeControl tree = null;
00255
00256 public TreeControl getTree() {
00257 return (this.tree);
00258 }
00259
00260 void setTree(TreeControl tree) {
00261 this.tree = tree;
00262 }
00263
00269 protected int width = 0;
00270
00271 public int getWidth() {
00272 return (this.width);
00273 }
00274
00275
00276
00285 public void addChild(TreeControlNode child)
00286 throws IllegalArgumentException {
00287
00288 tree.addNode(child);
00289 child.setParent(this);
00290 synchronized (children) {
00291 int n = children.size();
00292 if (n > 0) {
00293 TreeControlNode node = (TreeControlNode) children.get(n - 1);
00294 node.setLast(false);
00295 }
00296 child.setLast(true);
00297 children.add(child);
00298 }
00299
00300 }
00301
00312 public void addChild(int offset, TreeControlNode child)
00313 throws IllegalArgumentException {
00314
00315 tree.addNode(child);
00316 child.setParent(this);
00317 synchronized (children) {
00318 children.add(offset, child);
00319 }
00320
00321 }
00322
00326 public TreeControlNode[] findChildren() {
00327
00328 synchronized (children) {
00329 TreeControlNode results[] = new TreeControlNode[children.size()];
00330 return ((TreeControlNode[]) children.toArray(results));
00331 }
00332
00333 }
00334
00338 public void remove() {
00339
00340 if (tree != null) {
00341 tree.removeNode(this);
00342 }
00343
00344 }
00345
00353 public void removeChild(int offset) {
00354
00355 synchronized (children) {
00356 TreeControlNode child = (TreeControlNode) children.get(offset);
00357 tree.removeNode(child);
00358 child.setParent(null);
00359 children.remove(offset);
00360 }
00361
00362 }
00363
00364
00365 public String toString() {
00366 StringBuffer sb = new StringBuffer();
00367 sb.append(getName());
00368 sb.append(" - ");
00369 sb.append(isExpanded());
00370
00371 return sb.toString();
00372 }
00373
00374
00375
00382 void removeChild(TreeControlNode child) {
00383
00384 if (child == null) {
00385 return;
00386 }
00387 synchronized (children) {
00388 int n = children.size();
00389 for (int i = 0; i < n; i++) {
00390 if (child == (TreeControlNode) children.get(i)) {
00391 children.remove(i);
00392 return;
00393 }
00394 }
00395 }
00396
00397 }
00398
00399 }