In this assignment, you will learn how to use the Graphical Modeling Framewrok (GMF)
for generating graphical editors for EMF models. You will model and generate a graphical editor
for Petri nets (initially ignoring tokens) starting from the model and the project
for Petri nets that you made in Assignment 1.
For the initial version (ignoring tokens) you will use the so-called
GMF-dashboard for generating the different GMF-files, which define
the graphical editor by the help of wizards. Later, you will change and
extend these files manually. The idea of these files is explained in
the lecture (see MBSE-GMF.pdf).
You will learn how to
- install GMF in your version of Eclipse,
- initially set up the graphical definition model, the tooling definition model,
and mapping model for generating an graphical editor with the GMF-dashboard,
- generate the GMF generator file and how to generate the code for the editor
from it, and how to
- extend the graphical definition model, the tooling defining model, and the
mapping model manually for more advanced features of the graphical editor.
Below, the assignment is broken down into simple steps starting from your
solution for Assignment 1.
- Install the Graphical Modeling Framework (GMF) in your version of Eclipse.
To this end, start the "Install" dialog (Help -> Install New Software...). In this dialog, select the update site
(Work with:) http://www.eclipse.org/modeling/amalgam/downloads/package/modeling/mars/
Then select all GMF features (filter "GMF" will reveal them) in category
"Modeling", and follow through the install dialogs (don't forget to accept
the license).
Note: In principle, it should be possible to install GMF via
the "Install Modeling Components" dialog. But, this did not work last
time I checke — but it might work for you.
- Open the GMF-Dahsboard view (Window -> Show View -> Others ->
General -> GMF Dashboard); then open the EMF project with the Petri net model
from Assignment 1. All the following steps
are illustrated in the slides discussed in today's lecture: MBSE-GMF.pdf
- In the GMF-Dashboard, select the Petri net Ecore model from the project of Assignment 1 as domain model and the respective genmodel
as the gen model
(see MBSE-GMF.pdf, p.5).
Note: Make sure that the
Compliance level of your "gen model" is set to 6.0 (open the gen model,
select the topmost element, and set the compliamce level in the properties view).
- Next, generate the graphical definition model with the respective GMF-Dashboard
wizard by pressing the "derive" button. In the resp. dialogs, select "Petrinet"
as diagram element (root element); then select, which elements of the model
should be nodes, links, or labels in the editor
(see MBSE-GMF.pdf, p.6).
Please note that, intitially, you should not select the tokens for the editor
since this might cause some problems (a token should be contained in a place).
You will deal with tokens in a later step.
- Next, generate the tooling definition model with the respective GMF-Dashboard
wizard (button "derive"). Again, select Petri net as the diagram element
(root element); then select which elements of the model
should be nodes, links, or labels in the editor
(see MBSE-GMF.pdf, p.7).
Make sure that these choices are consistent with the choices that
you made for the graphical definition model.
- Now, from these three models, create the mapping model with the help of the
GMF-Dashboard (press "combine") the wizard that starts up; while running
through the wizard make sure, that the
selection of nodes and links is consistent with the earlier choices (see
MBSE-GMF.pdf, p.8).
Also make sure, that you select the right source and target features for the arc (which is a link in the editor).
Note that the mapping model is the most sophisticated model and will relate to the
two above models. In most cases, you need to make some manual changes here, to fix
"errors" made by the wizards (see MBSE-GMF.pdf 10-13).
- Generate the GMF generator model by pressing the "transform" button. Note that at this
point, there might be error messages due to mistakes in the mapping model (or the
other two models). You need to fix the problems (pages 10-13 of
MBSE-GMF.pdf
might give you some clue, as what you need to fix); the error message also give some idea on where to look.
Once you successfully generated the GMF generator model, open it; from the
GMF generator model, create a diagram plugin (right mouse button "Generate diagram code" or clicking on "Generate diagram editor" in the GMF dashboard)
for a graphical editor for Petri nets.
- Start the runtime workbench and create a Petri net (with the wizard "New -> Other... -> Example --> Petrinet Diagram) in some project there;
experiment a bit with the generated graphical editor.
Note: It might happen that your runtime workbench crashes with an
java.lang.OutOfMemoryError: PermGen space error. In that case,
shut down the runtime workbench, and before you start it again, change the
configuration of your runtime workbench (-> Run Configurations...); select
your configuration, and then select tab "Arguments". In that tab, add
-XX:PermSize=128M to the VM arguments (this will make Eclipse
start up with more memory).
You will realize, that all nodes are represented as boxes, arcs do not have an
arrow-head, and places are not ellipses yet. For fixing this, you need to make
some modifications in the GMF graph model
(see page 16 in MBSE-GMF.pdf); after making
these changes, you need to re-generate the GMF generator model again, and then
regenerate the code for the graphical editor.
Note that the editor still allows you to have arcs from places to places or from
transitions to transitions, which should not be possible in Petri nets.
For now, we do not deal with this problem (if you are curious: we could use OCL
constraints in GMF for that or use EMF Validation).
- Once the basic graphical Petri net editor is working,
add the tokens to the GMF model, so that
the tokens show as black circles. Note that the token mapping, unlike the
other nodes, should not be a "Top Node Mapping"; it should be a
"Child Reference" of the mapping for places (see pages 13, 15, and 16 of
MBSE-GMF.pdf. After you made these changes
in the GMF tooling definition, the GMF graphical definition and the GMF
mapping model, you need to regenerate the GMF gen model again, and from
their re-generate the code.
If you do not get the graphical editor with tokens fully working, you can fix
that in the next tutorial (which contibues with GMF).
|