When Administration Services Console starts, a panel is created called the “Enterprise View”. This panel contains an instance of the CTree class. The text for the root node is called “Enterprise View”. Each plug-in gets the opportunity to add children to the root node. This permits each plug-in to have its own branch in the Enterprise Tree view.
In the plug-in root, add a class called ConsoleTreeHandler. In our example, this would be com.MyPlugin.ConsoleTreeHandler. Add a method called “populateTree()” to this class. The source code should look something like the following example:
public class Console TreeHandler { //a no-argument constructor is required by the framework. public ConsoleTreeHandler() { } public void populateTree(CTreeModel model) { Object root=model.getRoot(); //strictly speaking, this next check should not be //necessary; however, we do this to make sure some other //plug-in hasn’t replaced the root node with something //unexpected. if ((root!=null) && (root instanceof CTreeNode)) //create any CTreeNode-derived objects, adding them //as children of the root node. } } }
There are some unenforced semantic rules associated with CTree objects:
The only action a plug-in should perform on the CTreeModel is to get the root. The plug-in should never replace the root node, traverse the tree model, or make changes to any other descendants of the root node.
Every object added as child of the root node must be derived from a CTreeNode. Theoretically, any object can be added as a child of the root; however, other parts of the framework will not respond to those objects in any meaningful way.
A plug-in can be called more than once if the console disconnects from the current server. The code needs to check that the node has already been added and only append nodes that have not been added previously. The source code should look something like the following Essbase ConsoleTreeHandler code: |
/** * populates the model with information required. */ public void populateTree(CTreeModel model) { Object root=model.getRoot(); CTreeNode rootNode=null; boolean firstTime=true; if (root instanceof CTreeNode) { rootNode=(CTreeNode) root; if (rootNode.getChildCount()!=0) { CTreeNode node=(CTreeNode) rootNode.getFirstChild(); while (node !=null) { if (node instanceof ServersContainerNode) { firstTime=false; UIFactory.refreshServerList(); break; } node=(CTreeNode rootNode.getChildAfter(node); } } } if (firstTime) { CTreeNode essnode=new ServersContainerNode(null); rootNode.add(essnode); final CTreeNode containerNode=essnode; ConsoleManager.getConsoleInstance().addFrameListener(new WindowAdapter() { public void windowClosed(WindowEvent e) { //signal that we are simply disconnecting instead of //closing if (e.getNewState() == WindowEvent.WINDOW_OPENED && e.getOldState() == WindowEvent.WINDOW_OPENED) { Server[] servers = UIFactory.getServers(); for (int ii=0; ii<servers.length; ii++) { UIFactory.removeServerInstance(servers[ii]); } } UIFactory.disconnectAll(); } }) } }