This tutorial will introduce another kind of concrete syntax for your models, namely a graphical syntax. Instead of writing models in a textual format, they are created by dragging elements from a palette into a two-dimensional plane. The framework we will employ here is Graphiti, which is based on the Graphical Editing Framework.

Contents

Defining the Diagram Type

The main documentation of Graphiti is found in the Eclipse online help, which is also found in the Eclipse application (Help → Help Contents). If you don't have Graphiti yet, install it from the Juno release update site, Modeling category. The first step of this tutorial consists of defining a diagram type for Turing Machines and adding a wizard dialog for the creation of new diagrams.

  1. Read the Graphiti Introduction.
  2. Create a new plugin named de.cau.cs.rtprak.login.turing.graphiti (like in previous tutorials, replace "login" by your login name) and add dependencies to the following plugins:
  3. Create a class TuringDiagramTypeProvider with superclass org.eclipse.graphiti.dt.AbstractDiagramTypeProvider.
  4. Open plugin.xml and create an extension for org.eclipse.graphiti.ui.diagramTypes with a diagramType element:
  5. Create an extension for org.eclipse.graphiti.ui.diagramTypeProviders with a diagramTypeProvider element:
  6. Add a diagramType element to the diagramTypeProvider with id de.cau.cs.rtprak.TuringDiagramType.
  7. Create a class TuringFeatureProvider with superclass org.eclipse.graphiti.ui.features.DefaultFeatureProvider.
  8. Add the following constructor to TuringDiagramTypeProvider:

    /**
     * Create a Turing diagram type provider.
     */
    public TuringDiagramTypeProvider() {
        setFeatureProvider(new TuringFeatureProvider(this));
    }
  9. Copy GraphitiNewWizard.java and CreationWizardPage.java to your plugin, adapting the package name accordingly. These files implement a generic wizard dialog for creating Graphiti-based models.
  10. Create a subclass of GraphitiNewWizard for specifying a concrete wizard dialog for your models.
  11. Include the new plugin in your Eclipse run configuration and start it. Create a Turing Machine diagram with your new wizard: FileNewOther...OtherTuring Machine. This opens a Graphiti diagram editor for the new file, but you cannot do anything in that editor, since the palette is still empty.
  12. In order to open a previously created tudi file, right-click it → Open WithOther...Graphiti Diagram Editor. This setting for tudi files will be saved in your workspace preferences.