Lorsque j’ai commencé à travailler sur le sujet MDA et la transformation de modèles, j’ai eu un petit peu du mal, j’avoue. Tout paraissait simple. J’ai compilé ci-dessous une micro-tutoriel: mise-à-part la réalisation du modèle métier lui même, cela ne prend pas plus de 30 minutes pour réaliser un prototype d’éditeur Eclipse dédié spécifiquement à votre modèle. A l’aide de EMF (Eclipse Modeling Frameworks) et GMF (Graphic Modeling Frameworks) vous pouvez tout faire, paraît-il. La preuve: dans la compilation ci-dessous, j’importe un XSD me servant de modèle pour réaliser l’éditeur qui va bien, càd un éditeur dédié à mon modèle où les objets graphiques lui correspondent, ainsi que les outils de dessin/édition disponibles. J’ai appliqué ce tutoriel à un modèle de données de signalisation ferroviaire, en deux étapes: d’abord un modèle simplifié, puis un modèle plus complet et nécessairement bien plus complexe. Dans le premier cas les choses se sont passées effectivement en 15min, dans le deuxième, hmmm, ce fur plus dur. Voici donc ce tutoriel (inspiré comme je l’ai dit de diverses sources et que j’enrichirai au fur et à mesure sur ce site):
Requirements: Eclipse Helios installed with modelling tools packages (EMF, GMF)
Start: File -> New -> Other … EMF Generator Model
EMF Project: name your project (prefer .emf at the end of the name in order to avoid miseunderstandings)
Select a Model Importer: XSD Schema
XML Schema Import: load your XSD file and set the name of hte model (must end with .genmodel)
The project is created and you have there two files:
- genmodel one
- ecore model (a translation of the XSD Schema to ecore).
Now you need to generate adjacent projects needed for your modeling tool.
Open the genmodel file if not already done, and right click on the root of the tree displayed by the file.
Select « Generate All »
3 other projects have been created in the workspace:
<…>.edit
<…>.editor
<…>.tests
Graphical part: File -> New -> Project -> Graphical Modeling Framework: new GMF Project
Go to next screen and select « Show dashboard view for the created project »
During the following steps you’d better keep the emf initial project selected, so that the operations applies to it.
First, select tour « Domain model » and « Domain gen model » in your dashboard. The first one is your ecore gnerated file, while the second one is the genmodel file (both from your initial emf project, in the model directory).
Now we should be able to generate the graphics and tools using the guided derivation provided by the dashboard.
In future articles, we will enter all the details of creating manually (and more precisely) these graphics and tools.
Click on Derive in the dashboard for generating first the Graphic Def Model.
Name you file (most of the time we will be happy with the defaul one that follows your projects naming rules based on EMF model).
Then, in the next screen, select the root diagram element.
In the Graphical Definition screen coming next, select which of your elements are connectors and which are objects. You can also define the labels related to each object or connector.
You need to do the same for the tools.
Click on Derive in the dashboard for generating the Tooling Def Model. Do same kind of stuff as for the Graphic Def Model.
Now you need to map all this together. In order to do this, the simplest way is to use the « combine » action from the dashboard. At this level you need to chose wich are your input models and, for each element, which are nodes and which are links (a default proposal is given by the tool).
Once the mapping done, you have a new file in your EMF project: the gmfmap one.
At this stage, the last step is generating rour specific model editor prototype. First transform your current models in a new output model using the « transform » link in the dashboard. Checking the RCP value will let you generate a standalone editor prototype.
Once this done, generate your diagram editor.
The dashboard will let you know that you have reached 100%.