Geertjan's Blog

  • April 19, 2014

Entity Expander for NetBeans IDE 8 (Part 4)

Geertjan Wielenga
Product Manager

Toni suggested it would be cool to create some templates for Nodes, ChildFactories, and TopComponents, on top of POJOs, for the Entity Expander that I blogged about last month

That way, NetBeans would have the start of something like EMF in Eclipse.

So, here are the templates I have so far.

Node ("BeanNode"):

package ${package};
import java.beans.IntrospectionException;
import java.util.List;
import javax.swing.Action;
import org.openide.nodes.BeanNode;
import org.openide.util.Utilities;
public class ${object}BeanNode extends BeanNode {
public ${object}BeanNode(${object} bean) throws IntrospectionException {
public Action[] getActions(boolean context) {
List myActions =
return myActions.toArray(new Action[myActions.size()]);

Child Factory ("BeanChildFactory"):

package ${package};
import java.beans.IntrospectionException;
import java.util.List;
import org.openide.nodes.ChildFactory;
import org.openide.nodes.Node;
import org.openide.util.Exceptions;
public class ${object}BeanChildFactory extends ChildFactory<${object}> {
protected boolean createKeys(List<${object}> toPopulate) {
//connect to data source
//and populate "toPopulate" list
return true;
protected Node createNodeForKey(${object} key) {
${object}BeanNode cbn = null;
try {
cbn = new ${object}BeanNode(key);
} catch (IntrospectionException ex) {
return cbn;

TopComponent ("ViewerTopComponent"):

package ${package};
import java.awt.BorderLayout;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.explorer.ExplorerManager;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.windows.TopComponent;
import org.openide.util.NbBundle.Messages;
preferredID = "${object}ViewerTopComponent",
persistenceType = TopComponent.PERSISTENCE_ALWAYS
mode = "explorer",
openAtStartup = true)
@ActionID(category = "Window",
id = "${package}.${object}ViewerTopComponent")
path = "Menu/Window" /*, position = 333 */)
displayName = "#CTL_${object}ViewerAction",
preferredID = "${object}ViewerTopComponent"
"CTL_${object}ViewerTopComponent=${object}Viewer Window",
"HINT_${object}ViewerTopComponent=This is a ${object}Viewer window"
public class ${object}ViewerTopComponent extends TopComponent implements ExplorerManager.Provider {
private ExplorerManager em = new ExplorerManager();
public ${object}ViewerTopComponent() {
setLayout(new BorderLayout());
//somehow create your children:
//Children.create(new MyChildFactory(), true);
Node rootNode = new AbstractNode(Children.LEAF);
public ExplorerManager getExplorerManager() {
return em;

Join the discussion

Comments ( 1 )
  • Tobias Moers Monday, April 21, 2014

    That would be a real cool Feature, which could save so much time creating those classes step by step..

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.