How to Use EMF on the NetBeans Platform (Part 2)
Join the DZone community and get the full member experience.Join For Free
In Part 1, yesterday, Gunnar Reinseth explained how the development team at Exie in Norway incorporated an EMF model into their NetBeans Platform application. In this part, we'll look at the same example (the Library example from the Eclipse Modeling Tools distro), but using a development build of the upcoming NetBeans IDE 6.9. Essentially, this story is all about how to port Gunnar's sample to a NetBeans Platform application project in NetBeans IDE 6.9, using the various tools that are now available for developers using Equinox, which is what Gunnar's sample is based on.
To provide some immediate context, take a look at the default splash screen that comes with the Equinox sample project support that will be discussed below:
So, to get started porting Gunnar's sample to the NetBeans IDE 6.9 development environment for Equinox-based projects, choose this brand new project template in a NetBeans IDE 6.9 development build:
After completing the above wizard, notice in the Project Properties dialog that the new application included a module that provides a bridge between Equinox and the NetBeans Platform:
When you look at the generated sample, notice, among other things, a "BundleActivator", as follows:
When you run the application shown above, several NetBeans API classes (in particular TopComponent, BeanTreeView, and Node) were used to display the currently deployed OSGi bundles and NetBeans modules:
Note: The above is a Swing application.
So, now that you have a functioning application running on Equinox as well as the NetBeans Platform, you are ready to integrate additional OSGi bundles, in particular, those from EMF. Right-click on the application node, chose Properties, then go to the Libraries panel. Click "Add Cluster" and then browse to the "plugins" folder in your Eclipse distribution:
Then when you click OK above, notice this dialog, which is not very pretty yet, but remember this is a development build:
Then click Next, at which point the IDE generated two folders into the selected folder, containing files for all theOSGi bundles it had identified within the folder. Together those folders then contained metadata informing the NetBeans Platform how to handle the related OSGi bundles, e.g., whether to load them lazily or at startup.
Select everything you find within the "plugins" folder, since you don't know what EMF's minimum dependencies are (if someone knows what they are, please tell me):
Then you add a library wrapper module to the project, to include the "model.jar" from Gunnar's sample. This "model.jar" contains the model, as well as several supporting classes from EMF.
Next, simply copy all the packages from Gunnar's application into your own:
...which means you need to set dependencies on the OSGi bundles from EMF (and beyond) that Gunnar had used in his sample. For that, you have this tool in NetBeans IDE to help you:
After a bit of fiddling, you have everything working. Run the application, which turns out to be the same as before, of course:
Downloading the NetBeans/OfficeLAF (which is also created by Gunnar's team!) didn't take much time, while adding it involved no complex configuration at all: simply use the "Add Existing" menu item on the application node, browse to the downloaded NetBeans OfficeLAF module, add it, then run the application again, with this result:
The icing on the cake (or "cherry on the top", if you will) was the small step involved in creating an installer for the application:
That's it, your work is done. You have successfully ported the EMF sample to the new development environment for Equinox-based development, i.e., NetBeans IDE 6.9!
Opinions expressed by DZone contributors are their own.