Reuse a NetBeans Services Tab Node

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:

service tab 

 

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:
 

dialog servers

Comments:

Nice post Edward, I found your this post very helpful in my developement of Netbeans plug-in modules.

thanks,
http://macross-frontier.blogspot.com

Posted by game&gadget review on May 20, 2008 at 07:16 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

wingzero

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today