Geertjan is a DZone Zone Leader and has posted 468 posts at DZone. You can read more from them at their website. View Full User Profile

How to Use EMF on the NetBeans Platform (Part 2)

03.18.2010
| 15492 views |
  • submit to reddit

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:

Note: (1) Read all about Netigso here. (2) Read all about Netbinox here.

 

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!

 

Published at DZone with permission of its author, Geertjan Wielenga.

Comments

Tom Schindl replied on Sat, 2010/03/20 - 11:34am

Great to see EMF getting to Swing Developers. You guys might be interested in the fact that using EMF-Databinding and Swing-Controls is available too.

An Eclipse-Project named UFaceKit I'm leading provides Eclipse-Databinding integration for Swing-Controls [1,2] (we could need some help from Swing-Folks though) and EMF comes with an Eclipse-Databinding implementation by default (See http://tomsondev.bestsolution.at/category/databinding/emf/tutorials/ for introduction).

Anyone interested in helping UFaceKit to provide first class databinding support for Swing-Controls?

[1]https://dev.eclipse.org/svnroot/eclipse/org.eclipse.ufacekit/bundles/proper/org.eclipse.ufacekit/org.eclipse.ufacekit.ui.swing/org.eclipse.ufacekit.ui.swing.databinding/
[2]https://dev.eclipse.org/svnroot/eclipse/org.eclipse.ufacekit/bundles/proper/org.eclipse.ufacekit/org.eclipse.ufacekit.ui.swing/org.eclipse.ufacekit.ui.swing.databinding.example/

Geertjan Wielenga replied on Sat, 2010/03/20 - 5:48pm in response to: Tom Schindl

Thanks for the tip, will certainly look into that once I am more comfortable with EMF and the other related frameworks, like validation, query, and transactions. Am also working on an official NetBeans Platform tutorial (which will be added on the tutorials page) that will cover the above scenario -- i.e., how to use EMF in NetBeans Platform applications via the new tools in NetBeans IDE 6.9. Great to have EMF (and all other OSGi-based tools)  so easily available to the NetBeans Platform now.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.