Sunday Nov 04, 2012

Lookup Viewer

The Maven integrated view that I showed yesterday I was able to create because I happened to know that an implementation of SubprojectProvider and LogicalViewProvider are in the Lookup of Maven projects. With that knowledge, I was able to use and even delegate to those implementations. But what if you don't know that those implementations are in the Lookup of the Project object? In the case of the Maven Project implementation, you could look in the source code of the Maven Project implementation, at the "getLookup" method. However, any other module could be putting its own objects into that Lookup, dynamically, i.e., at runtime. So there's no way of knowing what's in the Lookup of any Project object or any other object with a Lookup.

But now imagine that you have a Lookup Viewer, as a tool during development, which you would exclude when distributing the application. Whenever new objects are found in the Lookup, the viewer displays them. You could install the Lookup Viewer into NetBeans IDE, or any other NetBeans Platform application, and then get a quick impression of what's actually in the Lookup when you select a different item in the application during development.

Here it is (though I vaguely remember someone else writing something similar):

Above, a Maven Project is selected. The Lookup Window shows that, among many other classes, an implementation of SubprojectProvider and LogicalViewProvider are found in the Lookup when the Maven Project is selected. If an item in the Lookup Window has its own Lookup, the content of that Lookup is displayed as child nodes of the Lookup, etc, i.e., you can explore all the way down the Lookup of each item found within objects found within the current selection. (What's especially fun is seeing the SaveCookieImpl being added and removed from the Lookup Window when you make/save a change in a document.)

Another example is below, showing the Lookup Window installed in a custom application created during a course at MIT in Boston:

A small trick I had to apply is that, when a Node in the Lookup Window is selected, I always show the previous Lookup, since the current Lookup, when you select one of the Nodes in the Lookup Window, would be the Lookup of the Lookup Window itself! If anyone is interested in this, I can publish the NetBeans module providing the above window to the NetBeans update center. 

Saturday Nov 03, 2012

Maven Hierarchical View for NetBeans IDE 7.2

Started working on an oft-heard request from Kirk Pepperdine for an integrated view for multimodule builds for Maven projects in NetBeans IDE, as explained here. I suddenly had some kind of brainwave and solved all the remaining problems I had, by delegating to the LogicalViewProvider's node, instead of the project's node, which means I inherit all the icons, actions, package nodes, and anything else that was originally defined within the original project, in this case for the open source JAnnocessor project:

Above, you can see that the Maven submodules can either be edited in-line, i.e., within the parent project, or separately, by opening them in the traditional NetBeans way.

Get the module here:

http://plugins.netbeans.org/plugin/45180/?show=true

Some people out there might be interested in how this is achieved. First, hide the original ModulesNodeFactory in the layer. Then create the following class, which creates what you see in the screenshot above:

import java.util.ArrayList;
import java.util.List;
import javax.swing.event.ChangeListener;
import org.netbeans.api.project.Project;
import org.netbeans.spi.project.SubprojectProvider;
import org.netbeans.spi.project.ui.LogicalViewProvider;
import org.netbeans.spi.project.ui.support.NodeFactory;
import org.netbeans.spi.project.ui.support.NodeList;
import org.openide.nodes.FilterNode;
import org.openide.nodes.Node;

@NodeFactory.Registration(projectType = "org-netbeans-modules-maven", position = 400)
public class ModulesNodeFactory2 implements NodeFactory {

    @Override
    public NodeList<?> createNodes(Project prjct) {
        return new MavenModulesNodeList(prjct);
    }

    private class MavenModulesNodeList implements NodeList<Project> {

        private final Project project;

        public MavenModulesNodeList(Project prjct) {
            this.project = prjct;
        }

        @Override
        public List<Project> keys() {
            return new ArrayList<Project> (project.getLookup().
                lookup(SubprojectProvider.class).getSubprojects());
        }

        @Override
        public Node node(final Project project) {
            Node node = project.getLookup().
                lookup(LogicalViewProvider.class).createLogicalView();
            return new FilterNode(node, new FilterNode.Children(node));
        }

        @Override
        public void addChangeListener(ChangeListener cl) {
        }

        @Override
        public void removeChangeListener(ChangeListener cl) {
        }

        @Override
        public void addNotify() {
        }

        @Override
        public void removeNotify() {
        }
        
    }
    
}

Considering that there's only about three actual statements above, it's pretty amazing how much can be achieved with so little code. The NetBeans APIs really are very cool.

Hope you like it, Kirk!

Friday Nov 02, 2012

UNHCR and Stanyslas Matayo Receive Duke's Choice Award 2012

This year, NetBeans Platform applications winning Duke's Choice Awards were not only AgroSense, by Ordina in the Netherlands, and the air command and control system by NATO... but also Level One, the UNHCR registration and emergency management system.

Unfortunately, Stanyslas Matayo, the architect and lead engineer of Level One, was unable to be at JavaOne to receive his award. It would have been really cool to meet him in person, of course, and he would have joined the NetBeans Party and NetBeans Day, as well as the NetBeans Platform panel discussions that happened at various stages throughout JavaOne. Instead, he received his award at Oracle Day 2012 Nairobi, some days ago, where he presented Level One and received the Duke's Choice Award:

Level One is the UNHCR (UN refugee agency) application for capturing information on the first level details of refugees in an emergency context. In its recently released initial version, the application was used in Niger to register information about families in emergency contexts. Read more about it here and see the screenshot below.

Congratulations, Stanyslas, and the rest of the development team working on this interesting and important project!

Thursday Nov 01, 2012

Visage

Raj, the Chennai JUG lead, together with others from that JUG, is interested in Visage, the JavaFX script language closely associated with Stephen Chin.

He sent me the related lexer and parser and I started by having a look at them in the new version of ANTLRWorks being developed by Sam Harwell (who demonstrated it very effectively during JavaOne):

Notice how the lexer and parser are shown in a tree structure, as well as in a cool syntax diagram.

Next, I downloaded a bunch of JARs from here, so that packages such as from "com.sun.tools.mjavac" can be used, i.e., these are Visage-specific packages that aren't found anywhere except in the location below:

http://code.google.com/p/visage/wiki/GettingStarted

It turns out that there's also a Visage NetBeans plugin out there:

http://code.google.com/p/visage/source/browse/?repo=netbeans-plugin

Rather than recreating everything from scratch, i.e., generating ANTLR Java classes from the lexer and parser, I copied a lot of stuff from the site above and now a file Raj sent me looks as follows, i.e., basic syntax coloring is shown:

For anyone wanting to seriously support Visage in NetBeans IDE, I recommend downloading the existing Visage NetBeans plugin above, rather than creating everything yourself from scratch, and then figuring out how to use that code in some way, i.e., add the JARs I pointed to above, and work on its build.xml file, which could be frustrating in the beginning, but there's no point in recreating everything if everything already exists.

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
« November 2012 »
SunMonTueWedThuFriSat
    
11
13
14
15
24
25
 
       
Today