Eclipse Zone is brought to you in partnership with:

Gunnar has posted 1 posts at DZone. View Full User Profile

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

  • submit to reddit

This is an example of how you can use the NetBeans Platform's Nodes API, Actions API, and Property Sheet API over a generated EMF model in a NetBeans Platform application.

The project implementation is just a simplified extract from our own code (we have Subversion integration and a lot of stuff that is only relevant to our product). We would probably be better off using the Project API / Filesystem API, but I didn't have the time to look into that.

The EMF version is 2.5.0. The generated EMF classes come from the EXTLibrary example from the EMF plugin in Eclipse, which models a simple book library. The model and its generated Eclipse editors can be tested in Eclipse (for reference) by opening up the projects under model/emfworkspace.

Note: A project has been requested under a BSD license at for further development of the example discussed in this article. Until the project is approved, you can get the source code for this article by clicking here.

Project Layout

- EmfNbm (Platform Application)
- - branding (branding module)
- - lib (external libraries)
- - model (standard Java project)
- - project (main module)
- - wrapper-model (wrapper to bring the model into the model suite)


The steps below outline the general approach taken in creating the example described above.

  1. Create a standard Java project in NetBeans with the following source folders:

    • model/emfworkspace/org.eclipse.emf.examples.library/src: the actual model files

    • model/emfworkspace/org.eclipse.emf.examples.library.edit/src: the "edit" classes / item providers

    The third folder, org.eclipse.emf.examples.library.editor is Eclipse specific and can't be used in NetBeans. I've included the code anyway since it is good for reference of how things are done in Eclipse.

    I created a standard Java project instead of a NetBeans Platform module  because of the multiple source roots (platform modules do not support this). (I could of course have created a platform module for each of the source roots, but that is not all straight forward since NetBeans is not too helpful when importing from external project models.)

  2. Create a library wrapper module for the model project. Modify the build script and the project metadata to make it work:

    • Override the "release" target in the build file to manually copy the jar file from the model project

    • Change the <class-path-extension> in the project metadata to point to the jar file of the model project

    A weakness of using a wrapper like this, is that changes to the class files in the model project won't be detected when compiling the module suite. So it has to be built manually and then the wrapper needs to be cleaned.

  3. Move in the "edit" project from the root folder into the source folder. This file is used for providing texts for the model.
           --> (...)/src/org/eclipse/emf/examples/extlibrary/provider
    The class EXTLibraryEditPlugin has been modified to reflect this change.  (It is the class that all generated item providers delegate to when looking up resources.)

  4. Create a ModuleInstaller in the "project" module that registers a dummy registry provider for Equinox. It also boots up the transaction and validation plugins and loads our generated model.

  5. Create the class emfnbm.project.Project. It is a simple class that is used to load and save XML files (with a custom extension that is registered in the static constructor of the class), and to provide an adapter factory and an editing domain.
    Also create the class emfnbm.project.ProjectManager which is used to manage a single open project. (Could probably use the Project API for this, but we still haven't found time to check it out.)


The main node implementation is emfnbm.nodes.EmfNode. It uses the AdapterFactory from the Project to get/adapt labels, icons, children and property descriptors, and it has support for drag and drop. It uses cookie sets and should probably be rewritten to using Lookups directly instead.
The drag and drop support reveals a problem in TreeView which can be noteworthy. Check out the following bug report (which sadly has never been addressed): 

I have also supplied a general purpose FilterNode implementation that uses EMF predicates to determine the visibility of children. I haven't created a usage example yet, but have a look at the comments in EmfFilterNode#updateChildren() and EmfFilterNode#createNodeListener() in regards to correctly switching the children factory from LEAF to a regular factory.

Now continue to part 2...


Published at DZone with permission of its author, Gunnar Reinseth.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Aljoscha Rittner replied on Wed, 2010/03/17 - 10:08am

Hi Gunnar!

Do you have some comments about using NetBeans Platform, not Eclipse RCP? My first thought was, why not EMF under Eclipse RCP? Do you have reasons for the "harder way" to create a complete new UI for EMF under NetBeans Platform?


Gunnar Reinseth replied on Wed, 2010/03/17 - 10:25am

Well, it started out with a project where we wanted to use EMF in a meta model build tool targeted at BI consultants. Considering that Eclipse RCP applications looks very much like an IDE (which is not very BI consultant friendly) and that the UI is quite hard to change (and the fact that we didn't have any SWT skills in the team), we opted to create our own Swing based application with a look and feel that didn't seem out of place with the components of Office 2007. It didn't take long, however, before we found out that we wanted a proper module system, so we then chose to go with NetBeans Platform 6.5 since it was Swing based and offered us what we needed plus much much more.

Tom Wheeler replied on Wed, 2010/03/17 - 11:19am in response to: Gunnar Reinseth

Great article, Gunnar.  Like you, SWT was the dealbreaker for me when I selected the NetBeans Platform as the foundation for an engineering application I started developing back in 2005.  It was a tough decision to make at the time because the NetBeans Platform was not nearly as popular as it is today, but it's since proven a very wise choice.

Since NetBeans Platform and Eclipse RCP are more or less equivalent in terms of features, I've found that most people decide based on whether it's more important to reuse existingcode and developer skills (+1 for NetBeans because of Swing) or to support the de facto standard module system (+1 for Eclipse because of OSGi). 

NetBeans 6.9 will have OSGi support, so I think that decision is going to get a lot easier for developers in the future.

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

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 for introduction).

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


Matt Coleman replied on Thu, 2012/04/26 - 12:44am

thanks for sharing this how-to...really appreciate it

graphic artist buffalo

Mateo Gomez replied on Fri, 2012/04/27 - 1:59am

this is very helpful for me who is in a way confused about rcp  mexican dessert

Samad Khatri replied on Tue, 2014/04/01 - 3:28am in response to: Aljoscha Rittner

 The project implementation is just a simplified extract from our own code (we have Subversion integration and a lot of stuff that anti aging skin care

Comment viewing options

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