Entity Expander for NetBeans IDE 8 (Part 4)

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 {
        super(bean);
        //setDisplayName();
        //setShortDescription();
    }

    @Override
    public Action[] getActions(boolean context) {
        List myActions = 
            Utilities.actionsForPath("Actions/${object}");
        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}> {
    
    @Override
    protected boolean createKeys(List<${object}> toPopulate) {
        //connect to data source
        //and populate "toPopulate" list
        return true;
    }
    
    @Override
    protected Node createNodeForKey(${object} key) {
        ${object}BeanNode cbn = null;
        try {
            cbn = new ${object}BeanNode(key);
        } catch (IntrospectionException ex) {
            Exceptions.printStackTrace(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;

@TopComponent.Description(
        preferredID = "${object}ViewerTopComponent",
        persistenceType = TopComponent.PERSISTENCE_ALWAYS
)
@TopComponent.Registration(
        mode = "explorer", 
        openAtStartup = true)
@ActionID(category = "Window", 
        id = "${package}.${object}ViewerTopComponent")
@ActionReference(
        path = "Menu/Window" /*, position = 333 */)
@TopComponent.OpenActionRegistration(
        displayName = "#CTL_${object}ViewerAction",
        preferredID = "${object}ViewerTopComponent"
)
@Messages({
    "CTL_${object}ViewerAction=${object}Viewer",
    "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() {
        setName(Bundle.CTL_${object}ViewerTopComponent());
        setToolTipText(Bundle.HINT_${object}ViewerTopComponent());
        setLayout(new BorderLayout());
        //somehow create your children:
        //Children.create(new MyChildFactory(), true);
        Node rootNode = new AbstractNode(Children.LEAF);
        em.setRootContext(rootNode);
    }

    @Override
    public ExplorerManager getExplorerManager() {
        return em;
    }

}
Comments:

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

Posted by Tobias Moers on April 21, 2014 at 08:01 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2015
SunMonTueWedThuFriSat
   
4
5
11
12
26
27
28
29
30
  
       
Today