Sunday Oct 14, 2007
Sunday Oct 14, 2007
In NetBeans 6.0 IDE under the "Services" tab, there are a bunch of useful nodes inside the tab, ie. Databases, AppServers, etc. They look like this:
Now if you are a NetBeans module developer and you want your module to re-use one of nodes, for example, you want your wizard to pop-up a JNDI-browsing window for Glassfish AppServer. You can do the following to accomplish this.
Find a reference to the Node instance corresponding to the "Servers" node.
FileObject fileObject =
Repository.getDefault().getDefaultFileSystem().findResource("UI/Runtime/ServerRegistry2.instance"); DataObject dataObject = DataObject.find(fileObject); Node serverNode = dataObject.getNodeDelegate(); final ResourceBrowserPanel browserPanel = new ResourceBrowserPanel(serverNode);
...
"UI/Runtime/ServerRegistry2.instance" is the URL of "Servers" node as described by
.\j2eeserver\src\org\netbeans\modules\j2ee\deployment\impl\layer.xml
This requires you to search the NetBeans' source code in order to find out the URL, after this it is straight forward to get the reference to the Node instance. To display this Node in an Explorer view, you can use NetBeans' Exporer API.
public class ResourceBrowserPanel extends JPanel implements ExplorerManager.Provider {
private final ExplorerManager manager = new ExplorerManager();
public ResourceBrowserPanel(Node rootNode) {
BeanTreeView btv = new BeanTreeView();
btv.setRootVisible(true);
btv.setDefaultActionAllowed(true);
btv.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
manager.setRootContext(rootNode);
setLayout(new BorderLayout());
add(btv, BorderLayout.CENTER);
}
public Node[] getSelectedNodes() {
return manager.getSelectedNodes();
}
public ExplorerManager getExplorerManager() {
return manager;
}
...
Here is the result of what it looks like when the same "Servers" node is projected in a new dialog window: