...
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.
- Read the Graphiti Introduction.
- 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:
- org.eclipse.core.runtime
- org.eclipse.core resources
- org.eclipse.ui
- org.eclipse.ui.ide
- org.eclipse.emf.ecore.xmi
- org.eclipse.emf.transaction
- org.eclipse.emf.workspace
- org.eclipse.graphiti
- org.eclipse.graphiti.ui
- de.cau.cs.rtprak.login.turingmodel
- Create a class
TuringDiagramTypeProvider
with superclassorg.eclipse.graphiti.dt.AbstractDiagramTypeProvider
. - Open plugin.xml and create an extension for org.eclipse.graphiti.ui.diagramTypes with a diagramType element:
- id: de.cau.cs.rtprak.TuringDiagramType
- type: turing
- name: Turing Diagram Type
- Create an extension for org.eclipse.graphiti.ui.diagramTypeProviders with a diagramTypeProvider element:
- id: de.cau.cs.rtprak.login.TuringDiagramTypeProvider
- name: Turing Diagram
- class: name of the
TuringDiagramTypeProvider
class
- Add a diagramType element to the diagramTypeProvider with id de.cau.cs.rtprak.TuringDiagramType.
- Create a class
TuringFeatureProvider
with superclassorg.eclipse.graphiti.ui.features.DefaultFeatureProvider
. Add the following constructor to
TuringDiagramTypeProvider
:Code Block theme Eclipse language java /** * Create a Turing diagram type provider. */ public TuringDiagramTypeProvider() { setFeatureProvider(new TuringFeatureProvider(this)); }
- 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.
- Create a subclass of
GraphitiNewWizard
for specifying a concrete wizard dialog for your models.Add a constructor that calls a super-constructor with according parameters for configuration:
Code Block theme Eclipse language java 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.- Implement the
createModel
method by creating and returning an instance of the top-level element of your Turing Machines, e.g.TuringMachine
. - Register the new wizard class in your plugin.xml using a wizard extension for org.eclipse.ui.newWizards (you only need to choose an id and name and set the correct class name).
- Include the new plugin in your Eclipse run configuration and start it. Create a Turing Machine diagram with your new wizard: File→ New→ Other...→ Other→ Turing 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.
- In order to open a previously created
tudi
file, right-click it → Open With→ Other...→ Graphiti Diagram Editor. This setting fortudi
files will be saved in your workspace preferences.