How – To Kybele GMF Generator

advertisement
Juan M. Vara, Álvaro Jiménez
Kybele Research Group
Rey Juan Carlos University
July 2010
{juanmanuel.vara, alvaro.jimenez}@urjc.es
How – To
Kybele GMF Generator
1. Introduction
In a MDA development, OMG defends that the transformations between different models must
be automatic so, in agreement with this idea, we noticed that in the Eclipse context there
weren‟t any tool that provided a completely automation process. In this context, appears Kybele
GMF Generator (also known as KybeleGMFgen), a new Model-Driven Software Development
(MDSD) tool for Eclipse Modeling Tools for creating, in only a few steps, graphical editors from
manually annotated metamodels and customization files. Kybele GMF Generator is based on
Eclipse GMF (Ref. 2) and Eclipse Epsilon (Ref. 1) projects.
2. Before Kybele GMF Generator
GMF (Graphical Modeling Framework) is a great tool that provides some mechanics for
developing graphical editors based on EMF and GEF. Nevertheless, for developing a graphical
editor using GMF, the users must create some models: ecore (contains the metamodel),
gmftool, gmfgraph and gmfmap. Also they must generate genmodel, EMF editor code (JAVA),
gmfgen model and GMF editor code. Following the correct steps and creating these models
could be complicated for inexperienced developers, due to the fact that these models are
complex. If you want to know the models and the steps that you need to created a graphical
editor using GMF, you can see Fig. 1
Fig. 1 – GMF Overview
Kybele Research Group
Page 1
Kybele GMF Generator
In response to these difficulties, the Software and Systems Modelling Team of the York
University is developing Epsilon EuGENia (“the front-end provided by Epsilon for simplifying the
development of GMF editors”), a tool that creates gmfgraph, gmftool and gmfmap using the ecore
model (augmented with a few GMF-specific annotations). This ecore model (metamodel) could
be written using Emfatic (you can see the syntax and an example in Ref. 4).
Using the GMF-specific annotations, you can obtain a functional but simple editor. In order to
generate more complex editors, Epsilon proposes to define a simple editor and polish it using
code files written in Epsilon Object Language (syntax in Ref. 6).
EuGENia automates part of the process and using the ecore and the customization files allows
repeating the process as times as you want. This functionality is very useful when you need
modify the metamodel because, in the most of these cases, the gmfmap becomes an invalid
model, so you must remake it. Despite of EuGENia advantages, the process is only automated
in part, so the users must follow a workflow composed of some steps such as generate EMF
code or synchronize gmfgen model, among others.
In this context, we continue looking for more automation in the process of creating
semiautomatic graphical editors. For doing that, we have developed Kybele GMF generator that
uses the EuGENia advantages and adds another features such as genmodel generation, EMF
editor code generation, genmodel synchronization, gmfgen generation, gmfgen model
synchronization and GMF editor code generation.
3. Using Kybele GMF Generator
In this section, we explain how to use the new tool Kybele GMF Generator. To do that, we use
the same example which Epsilon use to show how you can customize your graphical editor
using EuGENia. This example implements a flowchart GMF editor which is polished by using an
EOL file. You can get this „Flowchart‟ example in Epsilon SVN Repository
(http://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.epsilon/trunk/examples).
We start defining the metamodel, to do it, we can use an ecore file or an emfatic file. In this
case, we use an emfatic file (‘.emf’ extension) to see correctly the GMF-specific annotations
(they start with „@gmf‟):
@namespace(uri="flowchart", prefix="flowchart")
package flowchart;
@gmf.diagram(foo="bar")
class Flowchart {
val Node[*] nodes;
val Transition[*] transitions;
}
@gmf.node(label="name", label.icon="false")
abstract class Node {
attr String name;
ref Transition[*]#source outgoing;
ref Transition[*]#target incoming;
}
@gmf.link(label="name", source="source", target="target", target.decoration="arrow")
class Transition {
attr String name;
ref Node#outgoing source;
ref Node#incoming target;
}
Kybele Research Group
Page 2
Kybele GMF Generator
class Subflow extends Flowchart, Node{
}
@gmf.node(figure="org.eclipse.epsilon.eugenia.examples.flowchart.diagram.figures.SquareFigure")
class Action extends Node {
}
@gmf.node(figure="org.eclipse.epsilon.eugenia.examples.flowchart.diagram.figures.DiamondFigure")
class Decision extends Node {
}
flowchart.emf
If you don‟t want to create an emfatic file, you can define an annotated ecore file, like you see in
Fig. 2. This is possible because KybeleGMFgen works the same way with an emfatic file or an
ecore file, in fact when you use an emfatic file, KybeleGMFgen generates an ecore file
automatically.
Fig. 2 - flowchart.ecore
After defining the annotated metamodel, such as we commented before, you could obtain a
simple functional graphical editor. However, you can create two EOL files to customize your
new graphical editor which must be called „Ecore2GMF.eol‟ and „FixGMFgen.eol‟. (To see EOL
syntax, use Ref. 6).
While „Ecore2GMF.eol‟ allows customizing the elements of gmfgraph, gmftool and gmfmap
models, „FixGMFgen.eol‟ does the same but with gmfgen model.
Kybele Research Group
Page 3
Kybele GMF Generator
Next, you can see the EOL files that we use to customize the Flowchart GMF editor:
Fig. 3 - Ecore2GMF.eol
To help to create the Ecore2GMF.eol file, we have implemented an EOL file which contains
some common operations that you can invoke in your Ecore2GMF.eol file. You can download
this file from http://cerbero.escet.urjc.es:81/KybeleGMFgenUtils/operations.eol and to use it, you must
include the following code at top of your file: import ‘operations.eol’;
Fig. 4 - FixGMFGen.eol
Also, if you want to add copyright text in your editor, you can create a text file which contains
your copyright information. This file must be called ‘copyright.txt’.
Fig. 5 – copyright.txt
Finally, once you have created the metamodel and the customization files, you can launch
KybeleGMFgen process from the metamodel file contextual menu (both emfatic and ecore).
Kybele Research Group
Page 4
Kybele GMF Generator
Fig. 6 – Launch Kybele GMF Generator from emfatic file
Fig. 7 - Launch Kybele GMF Generator from ecore file
After executing the process, KybeleGMFgen shows user a message which indicates whether
the execution ends successfully or whether, on the contrary, it has found errors. In the Fig. 8,
you can see the message corresponding to a successfully execution and the files what have
been generated by Kybele GMF Generator:
Kybele Research Group
Page 5
Kybele GMF Generator
Fig. 8 – Kybele GMF Generator process finished successfully
In this figure, you see how KybeleGMFgen has created, in your project, a set of new models
(modelName.genmodel, modelName.gmfgen, modelName.gmfgraph, modelName.gmfmap and
modelName.gmftool) and three packages (modelName, modelName.impl and modelName.util)
and also, how it has created three new projects in your workspace (ProjectName.diagram,
ProjectName.edit and ProjectName.editor). These packages and projects contain the JAVA
code for EMF editor and GMF editor.
Next, you can test your graphical editor and remake it as times as you want, repeating the same
process.
Fig. 9 – Flowchart Diagram Example
In the figure 6, you can see a model example created using the new Flowchart GMF editor. As
you can see, the action name appears in bold and decision name appears in italic so, the
customization works successfully.
Kybele Research Group
Page 6
Kybele GMF Generator
4. Installation
To download and install KybeleGMFgen in your computer please follow the steps below:
1. Install Eclipse Modeling Tools
KybeleGMFgen is an Eclipse plugin and therefore, to install it you need to download and
install Java 1.6+ and Eclipse Modeling Tools. You can download Eclipse in the official
website: http://www.eclipse.org/downloads/
*Note: Kybele‟s members use the following Eclipse distribution (for Windows):
http://www.kybele.es/Software/eclipse-modeling-ganymede-SR2-incubation-win32.zip
2. Download and Install KybeleGMFgen
Once you have installed Eclipse, you can install KybeleGMFgen using the Eclipse Update or
work directly with the source code from our SVN repository.
To install using Eclipse Update: This is the recommended option to install and update
KybeleGMFgen. We provide an Update Site:
http://cerbero.escet.urjc.es:81/KybeleGMFgen-UpdateSite
Source Code: You can get the latest version of the KybeleGMFgen in our SVN repository
available in Google Code:
http://kybelegmfgen.googlecode.com/svn/trunk/
5. More Information
The actual version of KybeleGMFgen works using the following features:

EMF 2.4.2

GMF 2.1.3

Epsilon 0.8.6
However, we are working to develop, in the future, a new version of KybeleGMFgen based on
the latest versions of these frameworks.
References
1.
Eclipse Epsilon Official Web-Site: http://www.eclipse.org/gmt/epsilon/
2.
Eclipse GMF Official Web-Site: http://www.eclipse.org/modeling/gmf/
3.
Epsilon Weblog: http://epsilonblog.wordpress.com
4.
EuGENia GMF Tutorial: http://www.eclipse.org/gmt/epsilon/doc/articles/eugenia-gmf-tutorial/
5.
Kolovos, D., Paige, R., & Polack, F. (2006). Eclipse Development Tools for Epsilon, Eclipse Summit
Europe, Eclipse Modeling Symposium. Esslingen, Germany.
6.
Kolovos, D., Rose, L., Paige, R. & Polack, F. The Epsilon Book: Available in
http://www.eclipse.org/gmt/epsilon/doc/book/
Kybele Research Group
Page 7
Download