TreeControlNode.java

00001 /*
00002  * $Header: /cvsroot/jonas/jonas/src/org/objectweb/jonas/webapp/taglib/TreeControlNode.java,v 1.1 2003/10/16 12:17:28 antonma Exp $
00003  * $Revision: 1.1 $
00004  * $Date: 2003/10/16 12:17:28 $
00005  *
00006  * ====================================================================
00007  *
00008  * The Apache Software License, Version 1.1
00009  *
00010  * Copyright (c) 2001 The Apache Software Foundation.  All rights
00011  * reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions
00015  * are met:
00016  *
00017  * 1. Redistributions of source code must retain the above copyright
00018  *    notice, this list of conditions and the following disclaimer.
00019  *
00020  * 2. Redistributions in binary form must reproduce the above copyright
00021  *    notice, this list of conditions and the following disclaimer in
00022  *    the documentation and/or other materials provided with the
00023  *    distribution.
00024  *
00025  * 3. The end-user documentation included with the redistribution, if
00026  *    any, must include the following acknowlegement:
00027  *       "This product includes software developed by the
00028  *        Apache Software Foundation (http://www.apache.org/)."
00029  *    Alternately, this acknowlegement may appear in the software itself,
00030  *    if and wherever such third-party acknowlegements normally appear.
00031  *
00032  * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
00033  *    Foundation" must not be used to endorse or promote products derived
00034  *    from this software without prior written permission. For written
00035  *    permission, please contact apache@apache.org.
00036  *
00037  * 5. Products derived from this software may not be called "Apache"
00038  *    nor may "Apache" appear in their names without prior written
00039  *    permission of the Apache Group.
00040  *
00041  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00042  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00043  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00044  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00045  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00046  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00047  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00048  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00049  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00050  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00051  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00052  * SUCH DAMAGE.
00053  * ====================================================================
00054  *
00055  * This software consists of voluntary contributions made by many
00056  * individuals on behalf of the Apache Software Foundation.  For more
00057  * information on the Apache Software Foundation, please see
00058  * <http://www.apache.org/>.
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 // ----------------------------------------------------------- Constructors
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 // ----------------------------------------------------- Instance Variables
00124 
00129     protected ArrayList children = new ArrayList();
00130 
00131 // ------------------------------------------------------------- Properties
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 // --------------------------------------------------------- Public Methods
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 // -------------------------------------------------------- Package Methods
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 }

Generated on Tue Feb 15 15:05:34 2005 for JOnAS by  doxygen 1.3.9.1