Tasks
In this assignment, we get a start with using EMF (Eclipse Modeling Framework). To
this end, we make the Petri net example from the lectures work in EMF. Note that,
except for the last task, these tasks should not take long and all participants of
the course should do them. Only the last task requires some more investigation.
- Create a new EMF project in your workbench (New->Project; select "Empty EMF Project" in
category "Eclipse Modeling Framework").
- In this new project, you will find a folder "model". In this folder, create a new
Ecore model and diagram (New->Other; select "Ecore Diagram" in category "Ecore Tools",
and give the file a reasonable name, e.g. "Petrinet.ecore").
For the Petri net model, see p. 33 of the slides of the first lecture.
In addition to the features in this model, the associations for source and target should be made
bidirectional (References in both directions that are opposites to each other); you will be needing
the reverse direction in the last task (simulation step).
- Create the Petri net model, with this Ecore Tools diagram editor. The Petri net objects
should have an attribute "id", which is an ID (set property "ID" to true in the
properties of this attribute in the advanced category of properties) and places
and transitions (nodes) should have a name attribute.
- Create the generator model for the new Ecore model: Select the Ecore file (not the
diagram!), right click and select "New->Other..."; select "EMF Generator Model" in
category "Eclipse Modeling Framework"; follow through the process (note that you
might need to click on "Load" in the "Ecore import" window, before you can proceed).
You do not need to change anything in the automatically generated generator model
with the extension ".genmodel". But, you might want to change the attribute "Base
package" of the petrinets package element to someting like "dk.dtu.imm.se2.e13.grX....".
This will help you to have a bit more structure in the generated Java packages.
- Open the generator model, select the root element and select the actions
"Generate Model Code",
"Generate Edit Code", and "Generate Editor Code" on it (the menu pops up
when you press the right mouse button on the root element of the generator
model).
Now, you should have some java classes in the src folder of your plugin. And there
should be two new plugin projects (*.edit and *.editor). These should (automatically) be
built and there should not be any errors. Have a first look at what was generated.
- Start the runtime-workbench, so that you can see what your "software" can do for
you: In some folder in the new run-time workbench create a new Petri net
("New->Other"; select "Petrinets" or
something similar - this depends on you name - in category "Example EMF Model creation wizard").
As root element chose your Petrinet class. Use the tree editor for creating the Petri net
elements and for connecting them (note that there is no a graphical editor yet). A right click
on a model element, will give you a menu for creating child elements. The attributes
of an element can be edited in the properties view (to open it, right click on an element
and select "Show Properties View").
Since editing Petri nets with this tree editor is very error prone, it is a good idea
to validate the model (click the right mouse button on the root model element and
select "Validate") before saving it.
- At last, extend your simple Petri net application, by implementing a simple Petri net
simulator (remember to switch back to the development workbench).
To this end, you should implement a PopUp action for the transitions of the Petri net. When selected,
the transition should fire, if it is enabled. A transition is enabled, if every
place on the incoming arcs has at least one token; the firing of a transition
removes one token from each incoming place and adds one token to every outgoing place.
See the eclipse help on more information on the implementation of popup menus (see
"Platform Plug-in Developer Guide -> Programmer's Guide -> Plugging into the workbench ->
Basic workbench extension points using actions -> org.eclipse.ui.popupMenus").
For an example, you can also see the popup menus that are attached to the ePNK nets
in the plugin org.pnml.tools.epnk.actions and look at the LinkLabels action and how
it is plugged in.
In order to install the popup menu on a right click on a transition, the "object class" should
refer to the java class that represents your transition
(e.g. dk.dtu.imm.se2.e13.grX.petrinets.Transition).
You should also add the dependency "org.eclipse.ui" to your plugin dependencies (tab "Dependencies"
after you open the plugin.xml).
Try your simulator in the run-time workbench (e.g. on the Petri net example, you have created
earlier, e.g. the square from the lecture and don't forget a token on one of the places).
Some more details and hints on how this can be done
will be discussed in the tutorial session on Sept. 13.
Note: It would be even nicer (popup menus are deprecated) if the "action" would be
included to the eclipse GUI with a command and default handler for that command. But, it is a
bit easier to start with a popup menu. This will be briefly discussed in the tutorial
on Sept. 13. And you will be provided with some examples of the use of commands and
default handlers later in this course.
|