5 Minutes Tutorial "ModGraph and Ecore"

  1. Follow the installation instructions as shown at Download
  2. 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:
    ModGraph project structure.
  3. 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.)
  4. 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.)
  5. Go to the tree editor. Right click on the operation and choose ModGraph -> Implement as graph transformation rule.
  6. 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.

  7. 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.
  8. To relate them, draw creation links in between. Therefore choose the desired link from the Palette and simply connect the objects.
  9. 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.
  10. 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.
  11. 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.
  12. 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."
  13. Validate your ModGraph graph transformation rule by right clicking at the canvas and choosing ModGraph-> Validate graph transformation rule or using the dashboard.
  14. 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:
  15. This was you first glimpse at ModGraph! We hope you enjoyed it!