Sunday Jun 08, 2008

Running NetBeans from Eclipse

I made some progress with my Maven-based IDE agnosticism: I am now able to launch NetBeans Platform applications from Eclipse. To do so, I set this goal as a new Eclipse launch configuration for cleaning/building the suite:

clean install nbm:cluster

And I created another new launch configuration for running it:

nbm:cluster nbm:run-platform

Both were simply copied from the Actions tab in NetBeans, from the Maven application's Project Properties dialog box. Then I simply selected my launch configuration as needed, from the handy dropdown in Eclipse (of which I have a NetBeans version, described elsewhere in this blog, that I need to upload to the Plugin Portal soon).

The first time I saw the NetBeans splash screen appear in Eclipse was pretty cool:

And here's the result, a simple NetBeans Platform application that integrates with Flickr, created (mostly) in Eclipse:

The only thing that Eclipse needs is a bunch of wizards, templates, and code generators... and then anyone could use it for creating NetBeans Platform applications.

Saturday Jun 07, 2008

NetBeans Platform Interview on NetBeans.tv

Here's a really cool interview by Tinu, with Arseniy, who directs the NetBeans Platform, taken during JavaOne recently:
<script type="text/javascript" src="http://www.netbeans.tv/js/swfobject.js"></script> <script type="text/javascript"> </script>

Go here to NetBeans.tv if you want to see the video's page.

Thursday Jun 05, 2008

TagsMe GUI: A NetBeans Platform Application in Action

The TagsMe GUI Editor is a NetBeans Platform application that Ibon Urrutia and others developed to provide a graphical editor for their JavaME framework, TagsMe. TagsMe is an application development platform for portable devices (principally PDAs and mobile telephones), based in XML, with a simple and intuitive syntax. One of the main advantages is that it isn't necessary to develop a different application for each existing manufacturer's model, allowing applications to be developed rapidly, easily, and consistently for any device that uses Java MIDP 2.0, using a syntax similar to HTML, and without having to know how to program.

With TagsMe, you define your screens in XML files that are parsed at runtime. You can also download those files, while the application is running, from a web server, allowing the creation of online applications. TagsMe provides an extensive component library (Buttons, bitmap fonts, animations, sprites, maps), a plugin architecture, and a script language that is very similar to Java.

Here's two pics of some of the tooling that the TagsMe GUI Editor provides (and here are more):

Also, check out the cool NetBeans.tv movie about this application:

<script type="text/javascript" src="http://www.netbeans.tv/js/swfobject.js"></script> <script type="text/javascript"> </script>

I wonder if the movie screen's resolution can somehow be increased because it would be cool to see the actual tags in the XML editor.

PS: Fabrizio mentions this app in his blog too, here.

Wednesday Jun 04, 2008

Sun in Manila (17 - 19 June)!

The Sun Tech Days program is a 15-city world tour designed to educate developers in local markets on various technologies. The events are typically a two-day format and range from hands on education and university trainings to community programs and technical sessions.

From Tuesday 17th to Thursday 19th of this month, the event will take place in Manila, Philippines. The agenda looks very interesting. I've been to a few Sun Tech Days events before and apart from the sessions one might expect (JPA, JRuby, OpenSolaris, Swing, Java EE), there are a couple of sessions that move beyond these typical Sun talks. Take for example "OSGi: Development and Deployment", on Wednesday at 17.30. And how about the one right after that, on "Java EE with Spring and Seam"? In any case, the program is packed with sessions on the same topics, and of the same quality, as those presented at JavaOne. So if you're a programmer in Manila who never made it to JavaOne, this is definitely not a conference that you want to miss.

On the 17th, there'll be a "FREE NetBeans DeepDive Session", which is something like a NetBeans Day, except that a lot more time will be spent on fewer topics, which is pretty cool. I'll be there too, spending an hour and a half on "Using NetBeans for Desktop Development". I'll first talk about the Matisse GUI Builder, then on the NetBeans tooling for JSR-296 (the Swing Application Framework), and finally I will introduce the audience to the NetBeans Platform. I think the combination of Matisse GUI Builder, JSR-296, and the NetBeans Platform gives the desktop developer a very comprehensive range of choices, for desktop applications of every size and shape.

Go here to register, if you haven't done so yet.

Here's a summary of what you can expect on the "FREE NetBeans DeepDive Session":

There will also be a NetBeans Platform training at the university, on the 20th and 21st, delivered by Tim and myself. I'm looking forward to my time in Manila. No idea what to expect of it!

How to Get a Plugin into the Plugin Manager

Close readers of the NetBeans Weekly Newsletter will be aware of the announcement in Issue # 336 - Apr 07, 2008, in which the main highlight was the fact that the NetBeans Plugin Portal has several new features. The most interesting of these is the fact that it is now possible for a plugin uploaded into the Plugin Portal to find itself in the Plugin Manager!

Here's how it works. In NetBeans IDE 6.1, go to Tools | Plugins. There, in the Settings tab, you'll find that "Plugin Portal" is registered as one of the update centers, along with all the others. That means that when you go to the "Available Plugins" tab, all the plugins made available by the registered update centers are included in the "Available Plugins" tab, ready for you to install them.

"Aaaaaaaaaargh!" is what you might now be thinking. "That means that anyone can come along, create some random plugin that includes something really damaging, upload it into the Plugin Portal, and then it will be available in the Plugin Manager for the unwary user to install into their IDE, potentially wiping out everything they have on their disk, in a worst case scenario where the plugin author has malicious intent."

Not to worry, that's not how it works at all. (Although, that's EXACTLY how it works in IntelliJ. I uploaded something into their Plugin Repository some months ago and then it was IMMEDIATELY available inside IntelliJ's built-in Plugin Manager. That seemed odd to me at the time.) Instead, there's a pretty strenuous vetting process. Believe me, it's stringent. I know because I'm in it.

It all started last month, with my Zip NBMs plugin (which was inspired by Mark Stephens at JavaOne who wanted a menu item that would zip up all the NBMs in a suite). I uploaded it into the Plugin Portal. Then I saw these new components on the page:

This enabled me to specify that I want my plugin to be verified, for inclusion in the Plugin Portal's update center, i.e., the one that is automatically registered in the Plugin Manager for NetBeans IDE 6.1. There are minimal quality criteria that the plugin must meet, which is determined by verifiers, who come from the NetBeans team as well as from within the broader community.

So I specified that I wanted my plugin to be verified for 6.1:

First of all, before anything else happened, before my plugin even got into the hands of the verifiers, verification failed. Why? Because I hadn't set the name of the plugin's author (and something else I can't remember). So then I added this metadata via the plugin's Project Properties dialog box.

Then it entered the verification process correctly and I was able to watch its progress:

It failed soon thereafter, because someone spotted that it hadn't been signed. Here are the instructions for doing so. In addition, there are a couple of plugins in the Plugin Portal that should be able to help you. I need to investigate those soon.

So then I signed it and uploaded a new version. A day or so later the plugin failed again, because I hadn't included a license:

So I uploaded a new one with a license. And, guess what? Today I received my first "Go". Take a look for yourself:

I'll probably get another "NoGo" from someone before getting "Gos" from all of them. But I'm really happy with all these checks that are being done to make sure that only plugins of a basic minimal quality make it into the Plugin Manager. And, soon, I hope, my plugin will find its way into the Plugin Portal's update center, i.e., I guess that'll happen when all the verifiers give it a "Go" and then it'll be in the Plugin Manager and you, as potential users of this plugin, will be secure in the knowledge that your IDE (and much else) won't be destroyed when you install it. Thanks a lot, verifiers, you're doing a great job.

Tuesday Jun 03, 2008

Swing Outline Component

Announcing the new Swing Tree Table today, Tim writes:

Usage is incredibly easy - you just provide a standard Swing TreeModel of whatever sort you like, and an additional RowModel that can be queried for the other columns contents, editability and so forth.

I found an example from sometime ago, by Tim, and have been playing with it to get used to this new development. The result is as follows:

To get started, I simply download the latest NetBeans IDE development build from netbeans.org and then attached the platform8/org-netbeans-swing-outline.jar to my Java SE project. Then I created a JFrame.

To work with this Swing tree table, you need to provide the new "org.netbeans.swing.outline.Outline" class with the new "org.netbeans.swing.outline.OutlineModel" which, in turn, is built from a plain old javax.swing.tree.TreeModel, together with the new "org.netbeans.swing.outline.RowModel". Optionally, to change the default rendering, you can use the new "org.netbeans.swing.outline.RenderDataProvider".

Let's first create a TreeModel for accessing files on disk. We will receive the root of the file system as a starting point:

private static class FileTreeModel implements TreeModel {

    private File root;

    public FileTreeModel(File root) {
        this.root = root;
    }

    @Override
    public void addTreeModelListener(javax.swing.event.TreeModelListener l) {
        //do nothing
    }

    @Override
    public Object getChild(Object parent, int index) {
        File f = (File) parent;
        return f.listFiles()[index];
    }

    @Override
    public int getChildCount(Object parent) {
        File f = (File) parent;
        if (!f.isDirectory()) {
            return 0;
        } else {
            return f.list().length;
        }
    }

    @Override
    public int getIndexOfChild(Object parent, Object child) {
        File par = (File) parent;
        File ch = (File) child;
        return Arrays.asList(par.listFiles()).indexOf(ch);
    }

    @Override
    public Object getRoot() {
        return root;
    }

    @Override
    public boolean isLeaf(Object node) {
        File f = (File) node;
        return !f.isDirectory();
    }

    @Override
    public void removeTreeModelListener(javax.swing.event.TreeModelListener l) {
        //do nothing
    }

    @Override
    public void valueForPathChanged(javax.swing.tree.TreePath path, Object newValue) {
        //do nothing
    }

}

Next, let's introduce the RowModel class:

private class FileRowModel implements RowModel {

    @Override
    public Class getColumnClass(int column) {
        switch (column) {
            case 0:
                return Date.class;
            case 1:
                return Long.class;
            default:
                assert false;
        }
        return null;
    }

    @Override
    public int getColumnCount() {
        return 2;
    }

    @Override
    public String getColumnName(int column) {
        return column == 0 ? "Date" : "Size";
    }

    @Override
    public Object getValueFor(Object node, int column) {
        File f = (File) node;
        switch (column) {
            case 0:
                return new Date(f.lastModified());
            case 1:
                return new Long(f.length());
            default:
                assert false;
        }
        return null;
    }

    @Override
    public boolean isCellEditable(Object node, int column) {
        return false;
    }

    @Override
    public void setValueFor(Object node, int column, Object value) {
        //do nothing for now
    }
    
}

Now, after dragging-and-dropping an Outline object onto your JFrame (which is possible after adding the beans from the JAR to the Palette Manager) which, in turn, automatically creates a JScrollPane as well, this is how you could code the JFrame's constructor:

public NewJFrame() {

    //Initialize the ui generated by the Matisse GUI Builder, which,
    //for example, adds the JScrollPane to the JFrame ContentPane:
    initComponents();

    //Here I am assuming we are not on Windows,
    //otherwise use Utilities.isWindows() ? 1 : 0
    //from the NetBeans Utilities API:
    TreeModel treeMdl = new FileTreeModel(File.listRoots()[0]);

    //Create the Outline's model, consisting of the TreeModel and the RowModel,
    //together with two optional values: a boolen for something or other,
    //and the display name for the first column:
    OutlineModel mdl = DefaultOutlineModel.createOutlineModel(
            treeMdl, new FileRowModel(), true, "File System");

    //Initialize the Outline object:
    outline1 = new Outline();

    //By default, the root is shown, while here that isn't necessary:
    outline1.setRootVisible(false);

    //Assign the model to the Outline object:
    outline1.setModel(mdl);

    //Add the Outline object to the JScrollPane:
    jScrollPane1.setViewportView(outline1);    

}

At this point, you can run the JFrame, with this result:

So, we see a lot of superfluous info that doesn't look very nice. Let's implement "org.netbeans.swing.outline.RenderDataProvider", as follows:

private class RenderData implements RenderDataProvider {

    @Override
    public java.awt.Color getBackground(Object o) {
        return null;
    }

    @Override
    public String getDisplayName(Object o) {
        return ((File) o).getName();
    }

    @Override
    public java.awt.Color getForeground(Object o) {
        File f = (File) o;
        if (!f.isDirectory() && !f.canWrite()) {
            return UIManager.getColor("controlShadow");
        }
        return null;
    }

    @Override
    public javax.swing.Icon getIcon(Object o) {
        return null;

    }

    @Override
    public String getTooltipText(Object o) {
        File f = (File) o;
        return f.getAbsolutePath();
    }

    @Override
    public boolean isHtmlDisplayName(Object o) {
        return false;
    }

}

Now, back in the constructor, add the renderer to the outline:

outline1.setRenderDataProvider(new RenderData());

Run the JFrame again and the result should be the same as in the first screenshot above. Look again at the rendering code and note that, for example, you have tooltips:

Monday Jun 02, 2008

Practical API Design

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
« June 2008 »
SunMonTueWedThuFriSat
1
6
13
19
26
28
29
     
       
Today