Exporting a GMF Editor as an Eclipse Product

I have recently finished exporting a GMF editor as a stand-alone Eclipse-based product, as part of ongoing research work (see here for details).  I ran into a couple issues doing this, and after sorting them out I decided to write this technical note in case it helps other Eclipse plug-in/EMF/GMF/RCP developers.

A Little Context

Some context is needed in order to understand my technical requirements, approach and issues.  In order to test my research hypothesis, I am doing the following:

  • Building an EMF meta-model to generically describe electronic circuit designs
  • Building a concrete model of this meta-model to define a part library
  • Using an Epsilon transformation to create a new EMF meta-model for the part library
  • Generating a GMF editor from the part library meta-model (also using Epsilon — I can’t recommend it enough!)
  • Writing Java code to analyze and annotate (via resource markers) the circuits modeled with the GMF editor

My final report and source code will be available soon, but this should give you enough context to follow along as I explain my issues and their resolution.

Exporting Multiple Source Folders in your Plug-In

My model plug-in has two source folders: the built-in src, and an additional one named ext for “extension” classes.  My rational for this is that, for a clean start, I can wipe my src folder and re-generate it using EMF without losing my custom classes.

At first attempt, my plug-in failed in a way that pointed to a problem with my extension code.  I thought a model file I was loading there was not being found, but it turned out the extension class itself was not packaged with the plug-in binary.  This confused me, as the extension code Java package matched a generated code Java package, which of course was included in the plug-in’s exported packages.

By default Eclipse includes only the default src package in the build process.  To change this, open your plugin.xml file, go to the Build tab, and click the default “.” library (in the Runtime Information section).  This enables the Add Folder… button, where you can add your custom source folders.

Enabling Eclipse Resources on your Exported Product

As I said earlier, I have Java code (in a separate analysis plug-in) that extends the GMF editor by analyzing electronic circuit models.  The results of the analysis are provided via resource markers on the diagram files.  During development, this worked well because Eclipse runtime configurations bundled all of the workspace plug-ins.  When exporting my RCP product, however, many things fell apart because the default RCP product doesn’t have a workspace that can accommodate projects and other resources — and markers can only be applied to IResource objects.

By adding the -consoleLog launch program argument to my run configurations, putting in some elbow grease in the form of plug-in debugging, unpackaging and reading plug-in manifests, and help from these two Web sites, I managed to get workspace/project support in my product by taking the following steps:

  1. Do not use the generated GMF application class.  Instead, have your product and its run configurations use the org.eclipse.ui.ide.workbench application, either by directly configuring it in the product/run configurations, or by declaring a product extension in your GMF diagram plug-in manifest with this setup and then creating your product configuration based on this product extension
  2. In your product configuration, remove all plug-ins and add the following:
    1. Your GMF diagram plug-in
    2. org.eclipse.ui.ide.application (this bundles the org.eclipse.ui.ide.workbench application)
    3. org.eclipse.ui.navigator.resources (this bundles the Project Explorer view)
    4. org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.  Without this plug-in, you’ll get an error trying to open your diagram files from the Project Explorer
    5. Any other plug-ins you may require that will not be added automatically by Eclipse in the next step (e.g. any plug-ins that extend your model or diagram plug-ins)
  3. Click “Add Required Plug-ins” in your product configuration’s Dependencies tab.  This will add a platform plug-in (can’t remember which one right now) that includes the Problem View, where markers are displayed.  And if this also added the three plug-ins listed above, life would be a lot easier 🙂
  4. Modify your perspective class to include the Project Explorer and Problem View in the generated RCP product
  5. Modify your wizard new file page class so that new diagram file paths start somewhere within the workspace (by default they start in your OS home directory path)

You must choose a way to keep the changes in steps (4) and (5) from being lost when wiping clean and re-generating the editor.

Eclipse provides wonderful tools to develop powerful and sophisticated applications based on it, but the lack of documentation can be a bit off-putting.  This spurred me to write this note, hoping someone finds it helpful.  Comments will be most welcome!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s