Creation date: 2012-10
Author: David Naranjo
da-naran@uniandes.edu.co
Description: How to create a GMF-Based editor for graphical syntax (2) - Eugenia
Versions: Eclipse Modeling Framework Indigo 3.7.*
Requirements: Metamodel available here.

Creating a GMF-Based editor for graphical syntax (2) - Eugenia

This tutorial was prepared by David Naranjo

Eugenia is an incubation project from Eclipse Epsilon, and its goal is to reduce the complexity of GMF.

You can find another tutorial here.

Figure 1. Goal of this tutorial

Installation

EMFatic

EMFatic is a text editor of ECore Models, and its syntax is similar to Java.We need to download EMFatic for the automatic generation of the editor. In Eclipse, go to Help→Install New Software…

And add this Software Site: http://download.eclipse.org/emfatic/update/

The install wizard will guide you on installing EMFatic.

Eugenia

Now we will install Eugenia and its Epsilon dependencies. Again, we go to Help→Install New Software… and add this update site:

http://download.eclipse.org/epsilon/updates

The easiest way is to install all the Epsilon package. After installing, restart Eclipse.

Generating the editor

If you haven't, please download the Petri Net project.

Now, we'll generate an EMFatic model from the petrinet.ecore metamodel. It represents the same metamodel, but with a different syntax. Over the ecore file, click the secondary button, and then select Generate Emfatic Source.

If the ecore is valid, it will generate the file petrinet.emf. Open it and give a look at its syntax.

Annotating the model

Now we'll tell Eugenia how to display the elements of our metamodel. We'll do it by annotating the elements that are important in our metamodel.

If you have doubts with the annotations, the full list of supported annotations is here.

First, we'll tell which is our root element. It will represent an instance of our diagram, and it won't be displayed.

@gmf.diagram(foo="bar")
class PetriNet {
  val Element[*] elements;
}

Now, we'll annotate the nodes of our diagram. Eugenia uses the syntax @gmf.node(«parameters»). Look carefully at the parameters used. In this example we won't display attributes, but it is possible.

@gmf.node(label = "name", figure = "rectangle", color="0,0,0",label.placement="external",size="8,40")
class Transition extends Node {
  attr double maxDelay;
  attr double minDelay;
}

@gmf.node(label = "name", figure = "ellipse", border.width="2", border.style="solid",label.placement="external",size="40,40")
class Place extends Node {
}

And finally, we'll tell Eugenia which elements are connectors.

@gmf.link(target.decoration="arrow", source="from", target="to", incoming="false",label = "name")
class OutputArc extends Arc {
  ref Transition[1] from;
  ref Place[1] to;
}

@gmf.link(target.decoration="arrow", source="from", target="to",incoming="false",label = "name")
class InputArc extends Arc {
  ref Place[1] from;
  ref Transition[1] to;
}

That's all. If the emf model is valid, the plugin will generate the models that we usually derive and edit with GMF:

  • genmodel
  • gmfgraph
  • gmfmap
  • gmftool

Right-click on petrinet.emf and click on Eugenia→Generate GMF Editor.

If the annotations are valid, it will create the GMF models and projects, and display a success dialog.

Take a look at the generated projects:

We're interested in the *.diagram project. Right-click on it, and open Run As…→Run Configurations. Create a new Run Configuration as Eclipse Application, or modify the one you want.

Check on Arguments tab that you have the following arguments:

-Dosgi.requiredJavaVersion=1.5 -XX:MaxPermSize=512m -Xms40m -Xmx1024m

Finally, run the project. It will launch a new Eclipse instance. On this instance, create a new project or right-click on an existing project. Select New→Other… and create a new PN diagram.

Now we can create a Petri Net diagram.

/u1/cursos/postgrado/isis4712/public_html/dokuwiki/data/pages/tut_eugenia.txt · Last modified: 2012/02/21 18:17 by rcasalla
[unknown link type]Back to top
Departamento de Ingeniería de Sistemas y Computación - Facultad de Ingeniería - Universidad de los Andes
CC Attribution-Noncommercial-Share Alike 3.0 Unported
Valid CSS Driven by DokuWiki Recent changes RSS feed Valid XHTML 1.0