KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > console > navtree > RootWrapper


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.console.navtree;
23
24 import java.util.Vector JavaDoc;
25
26 import org.jboss.console.manager.interfaces.ManageableResource;
27 import org.jboss.console.manager.interfaces.TreeAction;
28 import org.jboss.console.manager.interfaces.TreeInfo;
29 import org.jboss.console.manager.interfaces.TreeNode;
30 import org.jboss.console.manager.interfaces.TreeNodeMenuEntry;
31
32 /**
33  * Default implementation of NodeWrapper for the first level of the tree
34  * which aggregates the first level of plugins using the "bootstrap" managed objects
35  *
36  * @see org.jboss.console.navtree.NodeWrapper
37  *
38  * @author <a HREF="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>.
39  * @version $Revision: 37459 $
40  *
41  * <p><b>Revisions:</b>
42  *
43  * <p><b>20 decembre 2002 Sacha Labourey:</b>
44  * <ul>
45  * <li> First implementation </li>
46  * </ul>
47  */

48
49 public class RootWrapper
50    implements NodeWrapper
51 {
52    // Constants -----------------------------------------------------
53

54    // Attributes ----------------------------------------------------
55

56    TreeInfo tree = null;
57
58    NodeWrapper[] sons = null;
59    TreeNode[] realSons = null;
60
61    // Static --------------------------------------------------------
62

63    // Constructors --------------------------------------------------
64

65    public RootWrapper (TreeInfo tree)
66    {
67       this.tree = tree;
68
69       // create starting set of subnodes
70
//
71
Vector JavaDoc nodes = new Vector JavaDoc ();
72       ManageableResource[] roots = tree.getRootResources ();
73       for (int i=0; i<roots.length; i++)
74       {
75          ManageableResource mr = roots[i];
76          TreeNode[] ns = tree.getTreesForResource (mr);
77          if (ns != null && ns.length > 0)
78             nodes.addAll (java.util.Arrays.asList (ns));
79       }
80
81       realSons = new TreeNode[nodes.size ()];
82       sons = new NodeWrapper[nodes.size ()];
83
84       for (int i=0; i<realSons.length; i++)
85          realSons[i] = (TreeNode)nodes.elementAt (i);
86                
87    }
88
89    // Public --------------------------------------------------------
90

91    // Z implementation ----------------------------------------------
92

93    public Object JavaDoc getChild (int index)
94    {
95       if (index >= sons.length)
96          return null;
97
98       if (sons[index] == null)
99          sons[index] = new StdNodeWrapper(realSons[index], tree, "");
100
101       return sons[index];
102    }
103
104    public int getChildCount ()
105    {
106       return this.realSons.length;
107    }
108
109    public int getIndexOfChild (Object JavaDoc child)
110    {
111       for (int i=0; i<this.sons.length; i++)
112       {
113          if (this.sons[i] == child)
114             return i;
115       }
116       return -1;
117    }
118
119    public boolean isLeaf ()
120    {
121       return this.sons.length == 0;
122    }
123
124    public String JavaDoc getIconUrl ()
125    {
126       return this.tree.getIconUrl();
127    }
128
129    public String JavaDoc toString ()
130    {
131       return "JBoss Management Console";
132    }
133    
134    public TreeAction getAssociatedAction ()
135    {
136       return this.tree.getHomeAction ();
137    }
138    
139    public String JavaDoc getDescription ()
140    {
141       return this.tree.getDescription ();
142    }
143    
144    public TreeNodeMenuEntry[] getMenuEntries ()
145    {
146       return this.tree.getRootMenus();
147    }
148    
149    public String JavaDoc getPath ()
150    {
151       return "";
152    }
153    // Y overrides ---------------------------------------------------
154

155    // Package protected ---------------------------------------------
156

157    // Protected -----------------------------------------------------
158

159    // Private -------------------------------------------------------
160

161    // Inner classes -------------------------------------------------
162

163 }
164
165
Popular Tags