5 Minutes Tutorial "ModGraph and Ecore"
-
Follow the installation instructions as shown at
Download
-
Create a new ModGraph project: Select File -> New -> Other -> ModGraph Project. Choose a name and click finish.
You get a new Project with the following project structure:
-
Create an Ecore model showing the structure of a library.
(The two String parameters of the operation are the author's name and the book's title.)
- Generate EMF code.
(Please ensure that the ns-prefix of the ePackage in your ecore model and
the genmodel's base package are the same.)
-
Go to the tree editor. Right click on the operation and choose ModGraph -> Implement as graph transformation rule.
-
Switch to the ModGraph perspective.
Next to the Eclipse package explorer on the left the main window shows the graph transformation
rule (at the moment you see the box where to draw the Graph Pattern). A comment can be attached to each rule using
the comment view on the right. A dashboard, shown at the bottom, provides a structured view on the process toward
the executable model.
The following pictures are snapshots of the main window.
-
Now we implement the behavior of our method: The library aquires a book, written by an author, who is not known
to the library yet.
Go to the Graph Pattern. Insert the current object (representing an instance of class Library) by choosing
the GTThisObject from the Palette. Insert two creation objects, one of class Book and one of class Writer.
-
To relate them, draw creation links in between. Therefore choose the desired link from the Palette and simply
connect the objects.
- Set the attribute values using Attributes from the Palette. Choose the attribute to be set and enter the
value at the assignment's right side.
- In order to ensure that this author is not known to the library yet, we use a Negative Application Condition.
It contains a forbidden situation. Here the library must not know any writer with the author's name.
- Furthermore the given parameters title and authorsName must not be null to avoid non titled books written by an
unnamed author. Therefore we use a precondition written in OCL.
-
On the right side of your eclipse window, you see the comment view. All comments placed here appear as JavaDoc comments within the
implemented operation. Let's comment something like "Aquires a book written by an author not known to the Library so far."
- Validate your ModGraph graph transformation rule by right clicking at the canvas and choosing ModGraph->
Validate graph transformation rule or using the dashboard.
- Generate code from your rule right into the EMF generated to to add the behavior to your operation.
Right click at the canvas -> ModGraph -> Generate Java code for graph transformation rule or using the dashboard.
The result should look like that:
- This was you first glimpse at ModGraph! We hope you enjoyed it!