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.
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.
TuringDiagramTypeProvider
with superclass org.eclipse.graphiti.dt.AbstractDiagramTypeProvider
.TuringDiagramTypeProvider
classTuringFeatureProvider
with superclass org.eclipse.graphiti.ui.features.DefaultFeatureProvider
.Add the following constructor to TuringDiagramTypeProvider
:
/** * Create a Turing diagram type provider. */ public TuringDiagramTypeProvider() { setFeatureProvider(new TuringFeatureProvider(this)); } |
GraphitiNewWizard
for specifying a concrete wizard dialog for your models.Add a constructor that calls a super-constructor with according parameters for configuration:
super("Turing Machine", "tudi", "turing", "turing", org.eclipse.graphiti.ui.editor.DiagramEditor.DIAGRAM_EDITOR_ID); |
Diagrams are stored in two separate files, one containing the actual Turing Machine model and one containing the specific graphical elements used to represent the model. Here it is assumed that "turing"
is the file extension for Turing Machine models (this depends on how you configured your EMF model), while "tudi"
will be the file extension for diagrams.
createModel
method by creating and returning an instance of the top-level element of your Turing Machines, e.g. TuringMachine
.tudi
file, right-click it → Open With→ Other...→ Graphiti Diagram Editor. This setting for tudi
files will be saved in your workspace preferences.