package org.jboss.console.navtree;
import java.util.Vector;
import org.jboss.console.manager.interfaces.ManageableResource;
import org.jboss.console.manager.interfaces.TreeAction;
import org.jboss.console.manager.interfaces.TreeInfo;
import org.jboss.console.manager.interfaces.TreeNode;
import org.jboss.console.manager.interfaces.TreeNodeMenuEntry;
public class RootWrapper
implements NodeWrapper
{
TreeInfo tree = null;
NodeWrapper[] sons = null;
TreeNode[] realSons = null;
public RootWrapper (TreeInfo tree)
{
this.tree = tree;
Vector nodes = new Vector ();
ManageableResource[] roots = tree.getRootResources ();
for (int i=0; i<roots.length; i++)
{
ManageableResource mr = roots[i];
TreeNode[] ns = tree.getTreesForResource (mr);
if (ns != null && ns.length > 0)
nodes.addAll (java.util.Arrays.asList (ns));
}
realSons = new TreeNode[nodes.size ()];
sons = new NodeWrapper[nodes.size ()];
for (int i=0; i<realSons.length; i++)
realSons[i] = (TreeNode)nodes.elementAt (i);
}
public Object getChild (int index)
{
if (index >= sons.length)
return null;
if (sons[index] == null)
sons[index] = new StdNodeWrapper(realSons[index], tree, "");
return sons[index];
}
public int getChildCount ()
{
return this.realSons.length;
}
public int getIndexOfChild (Object child)
{
for (int i=0; i<this.sons.length; i++)
{
if (this.sons[i] == child)
return i;
}
return -1;
}
public boolean isLeaf ()
{
return this.sons.length == 0;
}
public String getIconUrl ()
{
return this.tree.getIconUrl();
}
public String toString ()
{
return "JBoss Management Console";
}
public TreeAction getAssociatedAction ()
{
return this.tree.getHomeAction ();
}
public String getDescription ()
{
return this.tree.getDescription ();
}
public TreeNodeMenuEntry[] getMenuEntries ()
{
return this.tree.getRootMenus();
}
public String getPath ()
{
return "";
}
}