Graphical Modeling Framework/Tutorial/Part 4
In this fourth part of the GMF Tutorial, we will begin to explore alternative generation options; namely, the lite runtime option and targeting RCP. For this, you will need the experimental SDK installed, in addition to the normal SDK.
Please note that this portion of the tutorial was created using the 2.0 development stream codebase, just prior to the M2 release. Things may vary, so you may find inaccuracies contained here. If you do, remember... this is a wiki ;) Your help in maintaining, correcting, expanding, etc. the content here is most welcome (as are posts to the newsgroup and bugzilla, actually).
Lite Runtime Generation to RCP
Let's begin with a new workspace to keep things isolated from the main tutorial a bit. This also eases maintenance of the tutorial content. We will begin by generating the EMF code for an RCP application. Your EMF .genmodel settings will be picked up by the GMF generator, in this case.
GMF Dashboard View
First, let's create a new org.eclipse.gmf.examples.mindmap GMF Project and keep the option to use the dashboard view this time. Below is an image of the dashboard view we will use to work through the flow of producing a GMF-based editor. As you can see, it invokes actions for many of the steps we routinely use in GMF-based development, but all from a single location.
Generating EMF for RCP
First, let's obtain our same mindmap.xsd model from the main tutorial as the input. Copy this file to your project's model folder.
Using the dashboard view's 'Select' link in the Domain Model section, locate your mindmap.xsd file. To produce an .ecore and a .genmodel from the xsd, select the 'Derive' link between Domain Model and Domain Gen Model. This will launch the New EMF Model wizard. Work your way through the dialogs and accept the defaults to Finish.
In the opened editor, view the properties of the root 'Mindmap' element. Within the Editor category, select 'true' for the Rich Client Platform property. This will be picked up by our GMF generator later. Expand the root in the editor and change the 'Base Package Name' property of the 'Mindmap' package to 'org.eclipse.gmf.examples' and save the model. Right-click the root and generate your Model, Edit, and Editor (if desired) code. You can run it now, if you wish by creating a new Eclipse Application runtime configuration and selecting 'Run an application' with your org.eclipse.gmf.examples.mindmap.editor.MindmapEditorAdvisorApplication class as the Program to Run.
Creating the GMF Generator Model
Now that our domain is set, we'll need to copy our graphical, tooling, and mapping models from the main tutorial. Save them to your model folder (where your domain models are) and update the state of the dashboard for each using its respective 'Select' link.
With our models in place and 83% complete (according to the dashboard ;-), we can create our generator model using the 'Transform' link in the dashboard. This will invoke the creation of the mindmap-lite.gmfgen model, during which you will see a dialog for Generator Model Options. Clear both options for 'Use IMapMode' and 'Utilize enhanced features of GMF runtime' as we will be generating to the lite runtime.
When done, you can select 'Edit' from the dashboard's Diagram Gen Model section to open the model in the editor. Change the Diagram File Extension property in the Gen Editor to 'mmd' to match the main tutorial. A goal of the lite runtime is to allow for interoperability with diagrams used by the full runtime, which means they use the same notation model.
You may also wish to select the option 'Same File for Diagram And Model' in order to keep it simple for small applications where there may not be a need for multiple views into a single domain model instance (as is the case in our lightweight mindmap application).
Also, in the Gen Editor properties, add '.lite' to the package name prefix property, and also to the plug-in ID property of the Gen Plugin element. This will avoid clashes with our full tutorial diagram.
Generate and Run
We're now ready to generate our diagram code and run as an RCP application. At the time of this writing, the dashboard's link only generates the full runtime diagram, so we'll need to right-click on the mindmap.gmfgen file and select 'Generate pure-GEF diagram code'.
To run our RCP-based diagram, create a new Eclipse Application configuration named mindmap-rcp (or something) and select org.eclipse.gmf.examples.mindmap.diagram.lite.MindmapDiagramApplication from the Run an Application section of Program to Run. On the Plug-ins tab, opt to 'Choose plug-ins and fragments to launch from the list' and 'Deselect All'. Locate your org.eclipse.gmf.examples.mindmap.diagram.lite plug-in from the list, then 'Add Required Plug-ins' to create a minimal launch configuration. Run the diagram, and use the File menu to create a new diagram, similar to what you see below.
Exploring the Lite Runtime
What you will immediately notice are some differences with the full runtime:
- No collapsible compartments
- No toolbar
- No action bars or handles
These may become available in future versions of the lite runtime, but will be individually selectable by the toolsmith. The goal of the lite runtime is to provide minimal dependencies and small download size for running these kinds of RCP-based diagram editors.
Enhanced Generator Model Features
Some new enhancements have arrived in the generator model for the 2.0 release. Here, we will explore the project navigator and property sheet features in the context of our Mindmap application.