Thursday Jan 31, 2013

Maven, GeoTK, NetBeans Platform

Following on from this blog entry, where you'll also find the link to the sources, the base GeoToolkit application now looks as follows on Ubuntu:

It's a cool starting point for anyone creating geospatial applications with GeoToolkit.

Tuesday Jan 29, 2013

New & Official ANTLR Development Environment is Now on NetBeans

Terence Parr, the ANTLR guy, sent out an e-mail a couple of days ago, starting with these words: "After 25 years, I think I've finally got the parser generator I've been looking for! Sam Harwell, ANTLR co-author, and I are very pleased to announce the release of ANTLR v4."

He continues: "Sam has built a really nice development environment based upon NetBeans, ANTLRWorks v2." And here's what it looks like:

It's cool, very powerful, and absolutely free. More info about the above is here:

http://tunnelvisionlabs.com/products/demo/antlrworks

"This IDE is a sophisticated editor for ANTLR v3/v4 grammars as well as StringTemplate templates. It can run the ANTLR tool to generate recognizers and can run the TestRig (grun on command line) to test grammars."

Note that a NetBeans plugin for NetBeans IDE 7.3 Beta 2 is also available, as described in the above link.

The usage of the NetBeans Platform as the basis of the new ANTLR development environment should not come as a surprise to anyone who reads this blog entry by Terence Parr in 2011:

http://www.antlr.org/wiki/display/~admin/2011/10/09/Report+of+GUI%27s+death+greatly+exaggerated

Congratulations to the ANTLR Team for this great step forward!

Monday Jan 28, 2013

New Russian Air Traffic Control System on the NetBeans Platform

VNIIRA, located in St. Petersburg, Russia, has created an ATC (air traffic control) system in Java on the NetBeans Platform, which has been installed at the newly constructed Talakan Airport in Sakha Republic, Russia. The application is the client of the ATC system, named "Sintez KSA", i.e., it is known as the "Sintez KSA" client.

The system allows tracking of hundreds of flights using primary and secondary surveillance radars. Its users are flight executive officers and traffic controllers. Application features include flight tracking, conflict detection and resolution, data display from various sources, together with playback and recording of all system events and user actions.

The application consists of dozens of modules with different functions. Using the modular NetBeans Platform, the team was able to compose features from multiple modules to provide the necessary functionality tailored to various roles, from flight executive officer to air traffic controller to combinations of these. Furthermore, the need for a flexible window management system, based on requirements coming from a demanding UI layout, is met by the NetBeans Platform window system. And, last but not least, the NetBeans Visual Library was used for creating custom UI controls.

How was the NetBeans Platform chosen? VNIIRA develops ATC systems for huge airports. Three years ago they needed a product for smaller airports and at that time their target operating system was Solaris. After evaluation, the NetBeans Platform turned out to be the only choice that could provide all necessary functionality. Then, two years ago, the target platform requirement changed and today the application runs under Linux. The transition was made absolutely seamlessly. The application is created on NetBeans Platform 6.9.1 and therefore the team is planning to switch to the latest version, so as to make extensive use of all the latest NetBeans Platform capabilities.

Thursday Jan 24, 2013

Seismic Data Velocity Analyzer Moving Further on the NetBeans Platform

Recently I published two YouTube movies showing how to port a seismic data application to the NetBeans Platform. The author of that application, Glenn Reynolds, wanted a starting point for migrating his JSR 296 application to the NetBeans Platform and that's why I made those movies, especially for his usecase.

Well, the good news is that Glenn's been quite busy since then, as this screenshot shows, which he sent me today: 

Congrats, Glenn! Must be plenty of seismic problems out there waiting to be solved with this application.

Wednesday Jan 23, 2013

org.openide.nodes.NodeListener

Here's a node hierarchy, with 4 selected, followed by a right-click, which results in a "Delete" menu item being shown:

Click the menu item and you see this dialog:

Click Yes and then all 4 are gone:

How to implement this?

  1. Enable the Delete Action on the ExplorerManager. The "true" below causes the "Confirm Deletion" dialog to appear.
    ActionMap map = getActionMap();
    map.put("delete", ExplorerUtils.actionDelete(controler, true));
    
    associateLookup(ExplorerUtils.createLookup(controler, map));
  2. Make the Node deletable. Make sure that the underlying object is in the Node Lookup. Then return "true" in "canDestroy", include the "DeleteAction" in "getActions", and, most important of all, call "fireNodeDestroyed" in "destroy":
    public class MansionNode extends BeanNode {
    
        public MansionNode(Mansion bean) throws IntrospectionException {
            super(bean, Children.LEAF, Lookups.singleton(bean));
            setDisplayName("Mansion: " + bean.getCity());
            setIconBaseWithExtension("com/mit/movie/viewer/resources/movie-orange-icon.gif");
        }
    
        @Override
        public boolean canDestroy() {
            return true;
        }
    
        @Override
        public Action[] getActions(boolean context) {
            return new Action[]{(SystemAction.get(DeleteAction.class))};
        }
    
        @Override
        public void destroy() throws IOException {
            fireNodeDestroyed();
        }
        
    }
  3. Implement NodeListener in the ChildFactory. The interesting thing is that when you implement "NodeListener", the "nodeDestroyed" is automatically called by "fireNodeDisplayed" in the Node's "destroy". So, the link between the Node and the ChildFactory does not need to be provided by ChangeSupport, which is how Toni did it in a cool example he made on this topic. Instead, the NodeListener, added to the Node, listens for the "fireNodeDestroyed" in the "destroy".
    public class MansionChildFactory extends ChildFactory<Mansion> implements NodeListener {
    
        private final Actor actor;
        private List<Mansion> mansions;
    
        public MansionChildFactory(Actor actor) {
            this.actor = actor;
            mansions = new ArrayList<Mansion>();
            mansions.addAll(actor.getMansions());
    
        }
    
        @Override
        protected boolean createKeys(List<Mansion> list) {
            list.addAll(mansions);
            return true;
        }
    
        @Override
        protected Node createNodeForKey(Mansion key) {
            MansionNode mansionNode = null;
            try {
                mansionNode = new MansionNode(key);
                mansionNode.addNodeListener(this);
            } catch (IntrospectionException ex) {
                Exceptions.printStackTrace(ex);
            }
            return mansionNode;
        }
    
        @Override
        public void nodeDestroyed(NodeEvent ev) {
            Mansion removedMansion = ev.getNode().getLookup().lookup(Mansion.class);
            mansions.remove(removedMansion);
            refresh(true);
        }
    
        @Override
        public void childrenAdded(NodeMemberEvent nme) {
        }
    
        @Override
        public void childrenRemoved(NodeMemberEvent nme) {
        }
    
        @Override
        public void childrenReordered(NodeReorderEvent nre) {
        }
    
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
        }
        
    }

There's only one problem with the above. Let's assume that instead of "MansionChildFactory", we have "PersonChildFactory", with a "createNodesForKey" that creates either an ActorNode or a DirectorNode. Under these circumstances, the above sequence doesn't work. In short, I don't know how to set up the above for a ChildFactory that uses "createNodesForKey" instead of "createNodeForKey".

Tuesday Jan 22, 2013

NetBeans IDE 7.3: Groovy Meets Java EE

In NetBeans IDE 7.3, for the first time, when you create a new Groovy class in a web (i.e., Java EE) application, whether you're in an Ant project or Maven project, the IDE will set up everything for you automatically so that the Groovy class will be compiled together with the application.

For example, in the case of Maven, the Groovy dependency will be added to the POM and the Groovy Eclipse Compiler plugin will be registered there too. And, as you can see here, a special source package root is created for Groovy, automatically when you start creating your first Groovy class in a project:

Then when the application is built, so is the Groovy class:


Related reading, which shows more good stuff for Groovy fans in NetBeans IDE 7.3:

http://wiki.netbeans.org/NewAndNoteworthyNB73#Groovy

https://blogs.oracle.com/netbeansgroovy

Monday Jan 21, 2013

Make Empty JToolBars In MultiViewElements Not Floatable

Sometimes you use the NetBeans API MultiViewElement class to create new tabs in a TopComponent, without needing to display a toolbar. However, as you can see below, you get an empty toolbar anyway, thanks to the getToolbarRepresentation override. That's a bit ugly...

...but gets even worse when the user tries to drag it, which sometimes succeeds, but then when they try to put it back, things might go wrong. Either way, this is the ugly error stack that they see:

Not very nice. My solution to this is simple, the same as described in this issue:

http://netbeans.org/bugzilla/show_bug.cgi?id=110008

I.e., rather than returning an empty JToolBar, return an empty JToolBar that has its floatable set to false:

@Override
public JComponent getToolbarRepresentation() {
    JToolBar toolBar = new JToolBar();
    toolBar.setFloatable(false);
    return toolBar;
}

Then, not only can the toolbar not be dragged, which would be a reasonable solution, but it magically completely disappears, as can be seen below:

A perfect solution. And not only for empty JToolBars. Even if I had buttons in that JToolBar, setting the floatable to false fixes the same problem (see this for related code):

@Override
public JComponent getToolbarRepresentation() {
    Action printAction = FileUtil.getConfigObject("
               Actions/File/org-netbeans-modules-print-action-PrintAction.instance", 
               Action.class);
    Action sysOpenAction = FileUtil.getConfigObject("
               Actions/Edit/org-netbeans-core-ui-sysopen-SystemOpenAction.instance", 
               Action.class);
    JToolBar toolBar = new JToolBar();
    toolBar.setFloatable(false);
    JButton printButton = new JButton(printAction);
    printButton.setText(Actions.cutAmpersand((String)printAction.getValue(Action.NAME)));
    toolBar.add(printButton);
    toolBar.add(sysOpenAction);
    return toolBar;
}

OK, then the toolbar can't be floated, but who cares, that's not something users expect to be able to do in this scenario.

Sunday Jan 20, 2013

TMINPQ: The Most Important NetBeans Platform Question

When beginning a new NetBeans Platform application... there is always one crucial question that you should ask yourself in the design/architecture phase of the project. I.e., before you put your hands on the keyboard, you should have TMINPQ answered. The entire direction of the application will depend completely on the answer to that single question.

What is that question? In under 15 minutes from now, that question will be very clear, if you watch this brand new YouTube movie:

And, if you liked part 1, you'll REALLY like part 2, especially if you also like visualizations of seismic data:

Related tutorial: http://platform.netbeans.org/tutorials/nbm-filetype.html

Saturday Jan 19, 2013

YouTube: PrimeFaces CRUD Generator for NetBeans

Recently I wrote about how to create a custom "JSF Pages from Entity Classes" wizard. Kay Wrobel, who was introduced in that blog entry, has now taken the concept to the next level and created on SourceForge the PrimeFaces CRUD Generator for NetBeans:

http://sourceforge.net/projects/nbpfcrudgen/

He's also provided an excellent starting guide, which includes an explanation of each of the files the generator will create for you:

http://sourceforge.net/p/nbpfcrudgen/wiki/GettingStarted/

Once you've downloaded the ZIP from this location, you're good to get started. A binary NBM file will be made available in due course once bugs have been fixed and everything is sorted out.

And here's a 4 minute movie I made to show how smoothly everything already fits together:

Great work, Kay!

Friday Jan 18, 2013

NetBeans IDE 7.3: Find Usages Filter

You're happily coding along and suddenly think to yourself: "Hmmm. I wonder where the 'pos' variable in my class is used throughout my application?" So you right-click your "pos" variable and choose "Find Usages":

Now, as always, you see the dialog below where you can set the scope of the search and whether comments should be included:

Then you click Find and get a massive amount of data back, in this case, 274 occurrences where the "pos" variable is used: 

That's a lot of data you got back. For the first time, in 7.3, you now have the second column of buttons on the left of the Usages window. This column is the "Find Usages Filter" and has six buttons, as shown below.

From top to bottom, the buttons above have the following tooltips:

  • Read filter
  • Write filter
  • Read/Write filter
  • Import filter
  • Comment filter
  • Test filter

From the data returned to the Usages window, you can remove all comments, for example, where "pos" was found, or all test classes, so that you're left with exactly the data you're interested in. Most useful is to use the "Write filter". Now everything is filtered out of the Usages window, except for the places in the code where the selected variable has write access:

Compare the above to what you get back when you use the "Read filter" instead, showing where the variable has read access:

And what does the "Read/Write filter" do? It will find occurrences where the variable has both read and write access, e.g., "pos += 3".

Thanks to Ralph for help in understanding this one. 

Thursday Jan 17, 2013

Seismic Unix on the NetBeans Platform

I'm looking at a seismic velocity application based on the Seismic Unix data format (the SEGY format), with Glenn Reynolds, who created it:

The above is created on the Swing Application Framework. The basic functionality can be ported to a new application on the NetBeans Platform in an hour or two:

Many advantages to doing this porting procedure, including the possibility of opening (and comparing!) multiple files and the pluggability/modularity of the above application. Below two files are open, but there could be dozens, which can now be compared with each other:

Planning to create a YouTube movie about how to do the above porting procedure soon!

Wednesday Jan 16, 2013

Icons for NetBeans Platform Applications on Windows

A recurring question in the NetBeans Platform world is: "How am I supposed to change the desktop shortcut icon and icons of the executables in the installation directory of a NetBeans Platform application installed on Windows via an installer created by the NetBeans Platform installer infrastructure?"

Let's use the Paint Application, one of the samples in the New Project wizard, as an example. Right-click the project node and choose "Package as | Installers". Now go outside NetBeans IDE and find the generated installer, double-click it, and complete the wizard.

On the desktop, you now see this desktop shortcut icon:

In the startup menu, you see this:

And in the installation directory, the icons for the executables look like this:

Sometimes, the above is fine and you don't care whether your own icons are used or not. Other times, you have a business requirement that all the above icons should be your custom icon. The first question to ask is: "Where does that orange NetBeans icon come from?" Well, take a look at your NetBeans installation directory and you'll find them:

Note: I am on 64-bit Windows, that's why you see a 64-bit executable above.

The above executables are NOT the executables for starting NetBeans IDE. Those executables are found in the "bin" folder above. Therefore, when we change the executables above, NetBeans IDE remains unaffected. So, don't worry, you'll still be able to start NetBeans IDE by the time you've worked through this blog entry.

Now that you know where the icons come from, you need to, in one way or another, change that icon to your own icon. In this FAQ entry you are shown how to do so. However, what that entry doesn't tell you is that you need to change those icons exactly where you see them above, i.e., not in your own "build" folder, since those will be overridden at some stage in the installer generator process, so that you'll only be partially successful, i.e., the executables for launching the application from the installation directory will be correctly changed, while the desktop shortcut icon will still be the orange NetBeans icon.

Here's what I do to override those orange NetBeans icons that you see above.

  1. Download the "ReplaceVistaIcon.exe", from here: http://www.rw-designer.com/rsrc/ReplaceVistaIcon.exe  and put the executable into the folder that you see in the screenshot above. That's right, the same folder where the executables are found that we're going to change.

  2. Get an ".ico" file, i.e., not some other kind of file, but one that is an icon file, i.e., the file extension is ".ico". Therefore, if you have ".png" file, for example, you'll need to somehow convert it to ".ico". For purposes of these steps, I am using Penguin.ico, which I found somewhere online. Put that file into the same folder as where the executables, and the utility from the previous step, are found.
  3. Now go to the command line. In the command line, cd into the folder shown above. Make sure that you have permissions on the folder and on the executables that you're going to change. Then type:

    ReplaceVistaIcon.exe app.exe Penguin.ico

    ...in the command line, which should change the icon of the first executable. Do the same for the other executables you find in the folder. If things go wrong at this stage, again, check the permissions on the folder and on the executables you're changing. When this step is complete, you'll see the following, where you can see I have selected the Penguin icon and the ReplaceVistaIcon utility, while the executables that have been changed are clearly different, i.e., no more orange NetBeans icons can be seen below:

  4. Now you're ready to regenerate your installer. Start by running "Clean" on your application, to make sure that your 'build' folder and 'dist' folder are removed. Then create the installer again and then run the installer, as you did before.

    And here's the result, after running the installer. Firstly, the desktop shortcut icon:

    Secondly, the start menu:

    Finally, the launchers (i.e., the executables) of the application:

Tip: If the desktop shotcut icon is still not correct after the above procedure, restart your computer. I've noticed this happen sometimes, probably because I didn't uninstall a previous version of the application correctly and there was still some cached data in the .paintit-installer folder.

The above is not the prettiest solution, but it works. If you're wondering: "OK, but I have multiple applications, must I do the above for each of those applications, i.e., will I have to do this over and over again whenever I create an installer for one of my applications?" And the answer is: "Yes." Again, not pretty. But it works. And that's what this blog is all about.

Tuesday Jan 15, 2013

How to Create a Custom "JSF Pages from JPA Entity Classes" Code Generator

Kay Wrobel is new on the NetBeans Platform developer mailing lists. He's interested in PrimeFaces and really likes NetBeans IDE for that reason (and rightly so, of course). However, being able to modify the templates used to generate JSF pages from entity classes is not enough for him:

Instead, what he'd like is the ability to replace those templates completely, to have multiple PrimeFaces oriented files to be generated, i.e., not following the View/Create/Edit/List approach that you see above, but following his own business requirements.

Currently, there's no API for the above dialog, though that would be nice. So, I've forked the parts of the NetBeans sources that relate to the above dialog (plus some other stuff, since I haven't completely broken it down to its minimum yet) here:

http://java.net/projects/nb-api-samples/sources/api-samples/show/versions/7.2/misc/ForkedJSFSupport

You can get the above via Subversion, open in NetBeans IDE 7.2.1, compile it there (several impl dependencies, so you must use 7.2.1), then run it. Then create a new web application create/generate some entity classes, and then you'll be able to go to this new wizard, which comes from the above code:

As you move through the wizard, right now, you'll have exactly the same steps and results as in the standard "JSF Pages from Entity Classes" wizard. The second panel proves that anything can be changed, i.e., notice "Hi Kay!" in the first label below the heading in the main panel in the dialog below:

The result of the above is, currently, exactly as you have in NetBeans IDE: JSF pages created from entity classes. So, now you have the basis for your own PrimeFaces, or whatever, code generator from entity classes.

Those parts of what you add/change to the source code should be contributed back to the NetBeans project, since changes you make are actually changes to the NetBeans source code. Not everything you contribute back will be useful or necessarily accepted, of course, but the point is that in principle anything you add/change is something you should be open to sharing back with the NetBeans project.

Monday Jan 14, 2013

David Geary's New HTML5 Game Development Series

I came across David Geary's article HTML5 2D game development: Implementing Sprite behaviors yesterday. The article ends with a download ZIP file.

I downloaded the ZIP, went to NetBeans IDE 7.3 Beta 2, and then chose File | New Project | HTML/JavaScript | HTML5 Application with Existing Sources. I then browsed to the root folder of the unzipped ZIP file and was then able to open it into the IDE. That makes understanding the source code and debugging it a lot easier because all the HTML5 capabilities of NetBeans IDE 7.3 are available to me immediately, e.g., Nashorn JavaScript editor, JavaScript debugger, bidirectional WebKit browser integration, HTML5 editor, CSS Rule Editor, etc:

Looking forward to following the rest of David Geary's series via NetBeans IDE.

Sunday Jan 13, 2013

JBoss 7/NetBeans in "web-main" branch

I tried out the 'jboss7' branch in 'web-main' today, where my colleague Petr Hejl pushed the latest jboss7 patch, which he's been working on with contributors, especially M Pragalathan, who did a fantastic thing in starting the NetBeans/JBoss 7 work on his own initiative, in the related issue:

http://hg.netbeans.org/web-main/rev/f5bc69ac5215

For the adventurous, it's worth trying out. It will not be part of 7.3, too late for that, but a plugin could be made available once bugs and other issues have been fixed, and later it could end up in the standard JavaEE distribution of the IDE. No plans have been made for this yet, though, so watch this and other spaces.

Here I have JBoss 7.1.1 registered and running, with some applications deployed to it.

These are great steps forward!

Saturday Jan 12, 2013

New Dark Theme for Nimbus in NetBeans IDE

A brand new plugin by the NetBeans Team's window system guru Stan Aubrecht:

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

Dark theme for Nimbus Look and Feel. It goes well with "Norway Today" editor color scheme. It does not affect other look and feel implementations so you must force Nimbus l&f, i.e., by using --laf Nimbus command line switch. To revert back to the default Nimbus theme just uninstall this module.

In Stan's words, this is a "poor man's" solution. There are some area that would need more tweaking, e.g., the top bar in the Options window. But it would mean changing code in NetBeans. This new module just adjust a few UIManager constants.

I think this is also interesting for any other application based on the NetBeans Platform, especially since the sources are available in the contrib repository:

http://hg.netbeans.org/main/contrib/file/25a8acfe62f4/nimbus.theme

In particular, look at the ModuleInstall class:

http://hg.netbeans.org/main/contrib/file/25a8acfe62f4/nimbus.theme/src/org/netbeans/modules/nimbus/theme/Installer.java

Patches and tweaks are welcome.

Note: You need a very recent build of NetBeans IDE, i.e., NetBeans IDE 7.3 Beta 2 is not recent enough. It needs to be more recent than that, i.e., download the latest NetBeans IDE 7.3 development build to try out this plugin.

Friday Jan 11, 2013

NetBeans IDE 7.3: Easy Access to Hierarchy Inspection Features

Users of NetBeans IDE 7.3 will find a significant usability enhancement caused by a redesign of the "inspect hierarchy" functionality.

The new Hierarchy window that you see shown below on the right provides supertype and subtype information, as opposed to the previous releases where this information was displayed in modal dialogs. Several small helpful related changes include integration with the Javadoc window, as can be seen below, which updates itself based on what is selected in the Navigator, Hierarchy window, or editor:

All in all, you'll have a cleaner user interface with all related information immediately and contextually available in the IDE's supporting windows.

Much more info here:

http://wiki.netbeans.org/UEXInspectMembersAndHierarchies

Thursday Jan 10, 2013

Mathematical Experiment Tool on the NetBeans Platform

The year is freshly born and already there's yet another NetBeans Platform application... named TeaCat. TeaCat is a dynamic mathematical application that aims to enable high school students to experiment with and to exercise a variety of mathematical topics. Even engineers may benefit from TeaCat for rather complex calculations, since TeaCat includes working with derivatives, integrals, systems of equations and matrices.

Wednesday Jan 09, 2013

"New File" Feature Without a Project Type?

You're creating a NetBeans Platform application and discover that your "New File" menu item (and toolbar button) are always disabled. Why? Because you haven't implemented the Project API in your application. The "New File" feature is part of the Project UI module. You could include that module in your application and then you'd have the "New File" feature available but it will never be enabled, unless you've created a project already. You can see this in the New File dialog in the IDE: you need to specify the project for which you're creating a new file, until you have a project, you can't create a file. In short, "New File" is part of the project infrastructure.

So, what to do in applications that don't have a Project implementation but that do need to have "New File" feature? In this sample that I created today, two solutions are available out of the box:

http://java.net/projects/nb-api-samples/sources/api-samples/show/versions/7.2/misc/SimpleApp

Here are the two solutions:

  • An Action (same as the equivalent defined here in the PinkMatterPlatform) that creates a new file.
  • An Action that pops up a dialog where the user can select a file to be created.

In both cases, the "Templates" folder in the filesystem is queried, a file (or multiple files, in the second case) is found, and then the selected file is created.

Therefore, if you need a "New File" feature in your application, look no further than the prepackaged solutions above!

Tuesday Jan 08, 2013

How to Create an Editable Diff Viewer

Well, I've learned a lot of cool things about the NetBeans APIs over the years, but this probably takes the cake. All you need to do if you want an editable diff viewer is put a FileObject into the Lookup of a Node and then you can reuse the standard Diff Action that's part of NetBeans IDE.

In the right pane, you can type, i.e., the right pane is editable. All the editing functionality, e.g., code completion, is available too. That's exactly how it is when using NetBeans IDE's diff functionality. No surprise there, since the Diff Action in the IDE is being reused, completely as-is, unchanged, in this scenario.

Here's the definition of the Node above:

public class CustomerNode extends BeanNode<Customer> {
    
    public CustomerNode(Customer bean) throws IntrospectionException {
       this(bean, new InstanceContent());
    }
    
    private CustomerNode(Customer bean, InstanceContent ic) 
            throws IntrospectionException {
        super(bean, Children.LEAF, new AbstractLookup(ic));
        ic.add(bean.getFileObject());
        setDisplayName(bean.getFileObject().getName());
    }

    @Override
    public Action[] getActions(boolean context) {
        return new Action[]{FileUtil.getConfigObject(
                "Actions/Tools/org-netbeans-modules-diff-DiffAction.instance", 
                Action.class)};
    }

} 

What's magical about the above is that the org-netbeans-modules-diff-DiffAction becomes active when one or more Nodes are selected and opens the Diff Viewer for the FileObjects found in the Nodes. So, therefore, since my Customer object is defined by a FileObject read from the layer file, when multiple Customers are selected multiple FileObjects are available (because I put the FileObject into the Node Lookup).

Now, what happens if MORE than two FileObjects are available, i.e., more than two Nodes are selected (or the two selected Nodes have more than two FileObjects in their Lookups)? Well, automatically, the Diff Action is disabled:

And what about if there are LESS than two FileObjects? Then you see the following, i.e., you are prompted to browse on disk for a file that you'd like to compare with the available FileObject:

Next, just make sure that the editor modules for the language of your choice are in the application. For example, because I have the HTML Editor modules, the diff view uses the HTML Editor to display the two FileObjects... because the two FileObjects are recognized as being HTML files, since their file extension is "html".

And what if your Customer object does not define a FileObject, i.e., you want to compare something different? Somehow, create a FileObject anyway. Put into that FileObject the data you'd like to diff. For example, I have this in the module's layer file:

    <folder name="customers">
        <file name="james.html" url="resources/james.html"/> 
        <file name="john.html" url="resources/john.html"/> 
        <file name="henry.html" url="resources/henry.html"/> 
    </folder> 

I then construct the Node hierarchy from the layer folder you see above:

public class CustomerChildFactory extends ChildFactory<Customer> {
    @Override
    protected boolean createKeys(List<Customer> list) {
        FileObject customersFolder = FileUtil.getConfigFile("customers");
        for (FileObject customerFile : customersFolder.getChildren()) {
            list.add(new Customer(customerFile));
        }
        return true;
    }
    @Override
    protected Node createNodeForKey(Customer key) {
        CustomerNode node = null;
        try {
            node = new CustomerNode(key);
        } catch (IntrospectionException ex) {
            Exceptions.printStackTrace(ex);
        }
        return node;
    }
    
} 

Each file you see in the layer folder snippet above is a FileObject, defined by a name (ending in "html", so that the HTML Editor will be used to display the file) and an HTML file that is within the module. Once I have the Node hierarchy, I put the FileObject into the Node Lookup, as shown in the CustomerNode definition above, after which I reuse the Diff Action, as you can see in the getActions method of the CustomerNode. That's all it takes.

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
« January 2013 »
SunMonTueWedThuFriSat
  
25
26
27
30
  
       
Today