Automata Diagram with GEF and EMF - csns

Automata Diagram Editor Tool with GEF and EMF
Project Report
Hideyo Isaji
California State University, Los Angeles
16 May 2008
1. Abstract
In theoretical computer science, automata theory is the study of abstract machines
and problems they are able to solve. An automaton is a mathematical model for a finite
state machine (FSM) that given an input of symbols, through a series of states according
to a transition function can be represented as a table. On the other hand, Eclipse is an
integrated development environment (IDE) which users can extend its capabilities by
installing plug-ins, such as development toolkits for other programming languages, and
can write and contribute their own plug-in modules [1]. The tool we propose in this report
is an Eclipse plug-in that is for drawing and editing the automata diagram graphically,
and testing that the automaton either accepts or rejects the input using GEF(Graphical
Editing Frameworks) and EMF(Eclipse Modeling Frameworks) plug-ins.
2. Introduction
The Automata diagram editor tool is one of plug-in projects of Eclipse. The
Eclipse platform is structured around the concept of plug-ins. Plug-ins are structured
bundles of code and data that contribute different functions to the system. A function can
be contributed in the form of code libraries which is Java classes with public API,
platform extensions, or even documentation [1]. Plug-ins can be extended from another
plug-in by defining extension points, or combining with another plug-ins.
In addition, this editor tool relies heavily on GEF and EMF frameworks which
can work individually or collaboratively. Many different varieties of plug-ins have
already been created all over the world. Graphical Editing Framework (GEF) is one of
these plug-ins, allowing developers to create a rich graphical editor from an existing
application model [2]. Eclipse Modeling Framework (EMF) is another set of plug-ins,
which is a modeling framework and code generation facility for building tools and other
applications based on a structured data model. Models can be specified using annotated
Java, XML documents, or modeling tools, then imported into EMF [3].
Automata diagram plug-in project can be extended with the GEF plug-in for
drawing and editing parts, and also can be extended with EMF plug-in for testing the
decidability of the automaton. The benefit of this diagram editor tool is that users are able
1
to edit and test an automata diagram easier than any other automata applets. For example,
adding and editing states (models) can be done by simply changing name of states
directly. The editor tool also provides flexible connections and the ability to
undo/redo/delete easily and the capability to save the diagram.
3. Technical Background
Automata diagram editor tool is mainly implemented with two different plug-in
development tools; GEF and EMF. However, those two plug-ins are developed by several
different plug-ins. Thus, the automata diagram depends on a variety of plug-ins, such as
SWT (The Standard Widget Toolkit), Draw2d, GEF, eclipse.ui, eclipse.ecore and EMF.
3.1. Eclipse Plug-ins
We are able to start plug-in development instantly by using PDE (plug-in
development environment) which is a function for creating plug-in projects in Eclipse.
When a plug-in project is created, the manifest file is opened in the plug-in manifest
editor. This multi-page editor is the central place to manage our plug-in and can be used
to edit all the files of the plug-ins. When we use the editor's forms, PDE transparently
handles the task of writing changes to the right files.
When we would like to run the plug-in project, we launch the “runtime
workbench”. Then it will show a new screen within Eclipse aside from the previous ones.
This is the “runtime workbench”. A plug-in project consists of a workspace and a
workbench. Eclipse workspace then is just a directory where your work is stored. The
“runtime workbench” is a second Eclipse workbench that is started when debugging an
Eclipse plug-in that is under development. In some sense the normal Eclipse that you are
running is considered a 'Runtime', but the 'Runtime workbench' usually means the second
Eclipse workspace used during plug-in development [1].
3.2. GEF (Graphical Editing Framework)
The Graphical Editing Framework (GEF) ships with a painting and layout plug-in
called Draw2d that is a lightweight widget system hosted on a SWT (The Standard
2
Widget Toolkit) composite which is a graphical widget toolkit for use with the Java
platform [2]. A Draw2D instance consists of a SWT composite, a lightweight system, and
its contents' figures. A figure is simply a java object, with no corresponding resource in
the operating system. Figures can be composed via a parent-child relationship. The root
figure will obtain these properties from the lightweight system's Canvas [5].
The GEF plug-in adds editing on top of Draw2d. The purpose of this framework is
to: facilitate the display of any model graphically using draw2d figures. It supports
interactions from mouse, keyboard, or the Workbench and provide common components
related to the above. GEF assumes you have a model you would like to display and edit
graphically. To do this, GEF provides viewers that can be used anywhere in the Eclipse
workbench.
Figure 1: MVC architecture
GEF viewers are based on the Model-View-Controller (MVC) architecture (Figure
1). In MVC (model-view-controller) design, the controller which is also called EditPart is
the only connection between the view and the model. The controller is responsible for
often maintaining the view, and for interpreting UI events and turning them into
operations on the model. The model is any data that gets persisted. Any model can be
used with GEF. The view is anything visible to the user. Both Figures and TreeItems can
be used as view elements. They are also responsible for editing.
To make models editable, we have to create Commands and EditPolicies classes.
Commands are passed around throughout edited. They are used to encapsulate and
3
combine changes to the application's model. Each Editpolicy is then able to focus on a
single editing task or group of related tasks. This also allows editing behavior to be
selectively reused across different Editpart implementations. Also, behavior can change
dynamically, such as when the layouts or routing methods change [2].
3.3. EMF (Eclipse Modeling Framework)
Eclipse Modeling Framework (EMF) is an open source framework for developing
model-driven applications. It generates Java code for graphically editing, manipulating,
reading, and serializing data based on a model specified in XML Schema, UML, or
annotated Java [3].
Figure 2: Architecture of EMF
When we use EMF, we first create a model. EMF model is the model that is for
handling integrated modeling by java, UML and XML. Core model holds the content of
models. We ought to create core model at first when we use EMF. In Figure3, the
generator model is the model for generating source codes. The generator model shows a
root object, representing the whole model. Ecore is a model that defines a core model,
and EMF generator generates source code according to the content of the provided EMF
model. JMerge enables you to customize the generated models and editors without
having your changes battered by regenerating the code [1].
4
4. System Overview
This automata diagram editor tool is created with GEF and EMF frameworks. The
GEF is for creating visual editors. Generally, we create our own models which are likely
to be based on Java objects. The EMF creates others using Java objects, which provides
numerous functions for manipulating models that are not found in Java objects [4]. With
GEF, the automata diagram can add and edit models generated by EMF. With EMF, the
automata editor tool can save the data of the diagram that is drawn by GEF as in creating
an XML file, getting the information of each model from the data, and testing whether
the diagram accepts or rejects of input.
4.1. Creating Model
When we start the GEF plug-in project, the first thing that needs to be done is to
create a model. This Automata diagram editor tool uses EMF Ecore models as GEF
models. Thus, when we combine GEF with EMF, we have to define the EMF models in
GEF EditPart, EditPolicies and Command classes. First of all, we normally create Ecore
models with tree diagram in EMF.
5
Figure 4: Core model with Topcased
In Figure 4, we can also create core models graphically using Topcased that is an
open source of UML editor tool. Topcased also has the Ecore tool that is the editor of
EMF core model. For example, there are FirstState, States, FinalState and Transition as
Ecore models. After we create these Ecore models, as noted above, EMF generates the
generator models which create source code that includes model code, edit code, editor
code and test code. We can use or edit these generated codes as one project or for unit
test. For example, there are methods such as getFirstState() in the FirstState class, the
getTransition() method in the Transition class, and the getName() method in each of the
state class model code package. We were able to implement the run feature of the
automata diagrams using these functions.
6
4.2. EMF application
After the models are created, we launch the runtime workbench. The second
Eclipse screen will then appear which then the user will need to follow the procedure to
open the EMF application that is based on the Ecore models. First of all, we create new
project files and choose “others…” Then we will see the name of the EMF editor which
was previously created. We open this file, and the following EMF application will be
shown up (Figure 5).
Figure 5: EMF application of Automata editor tool
We are able to create States and Transitions models by defining their names,
Targets and Sources. However, as we can see, this is hard to recognize which States
relates to which States or Transitions. To solve this problem, we use GEF with EMF
together.
7
4.3. Using GEF with EMF
To combine GEF and EMF, what needs to be done is to import EMF models as
GEF models into GEF application, and getting all of the model information from EMF
model class. After we succeed to connecting these EMF models into GEF applications,
we can then launch the EMF editor again, and choose “Open with” → “Automata GEF
and EMF” editor. After all, we will see the EMF application with Palette and white
canvas which is a GEF part (Figure 6).
Showing and editing EMF models graphically can be done with GEF and EMF
together by getting information of Target and Source States and Transitions, saving the
diagram as XML file, and testing the Automata diagram either it accepts or rejects the
input.
5. Design and Implementation
5.1. Edit models (adding, delete and undo/redo models)
The automata diagram editor tool can add models from Palette that is extended by
the GraphicalEditorWithPalette class in GEF. When we click one of the components, we
can put the images on the canvas which are a part of figures in GEF. Components of the
palette are defined within each model. For example, when we click on the “First State”
component, it will create the FirstStateModel class. Next, the FirstStateEditPart class
will call the FirstStatefigure class that corresponds to the FirstStateModel. We can then
see the image file that was put on the canvas.
This diagram tool can delete and undo/redo models by pressing the delete button
on the keyboard, by clicking right mouse button and choose “Delete”, or by clicking
delete icon on the tool bar. When we delete or move the models, the EditParts call the
EditPolicies, and the EditPolicies then calls the Commands class that operates editing
models. In this project, there exists the CreateElementCommand for adding models,
DeleteElementCommand for deleting models, MoveElementCommand, and so on.
8
Figure 6: Design of Automata diagram editor tool
5.2. Connection
Another feature of the Automata diagram editor tool is its flexible connection. In
GEF, connection is also handled as one of the models. We create connections using the
getModelSourceConnections and getModelTargetConnections methods that are included
in AbstractGraphicalEditPart class in GEF.
Figure 7: Design of Connection
9
To make connections flexible, we create bending points. We install a
BendpointEditPolicy for editing the connections routing constraints. This editpolicy
requires a router that takes a List of bending points. During selection, this policy will add
normal handles to existing bending points on the connection. It adds smaller handles
where the user can create new bending points [5].
5.3. Edit name Save XML files
We can save our Automata diagram using the resource methods of EMF. When we
open the diagram class as a text file, we see the following XML file. There are
Transition’s and State’s information in the file. We can get names of those models by
calling the getTransition.getName() or getState.getSourceTransition.getName() methods
from other java classes. These methods are all generated in EMF projects automatically.
My5.automaton2 xml file
<?xml version="1.0" encoding="UTF-8"?>
<Automaton2:Automatadiagram xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:Automaton2="http://Automaton2">
<Transition name="a" source="//@State.0" target="//@State.1"/>
<Transition name="b" source="//@State.1" target="//@State.2"/>
<State xsi:type="Automaton2:FirstState" sourceTransition="//@Transition.0"
X="107" Y="183" name="q1"/>
<State xsi:type="Automaton2:States" sourceTransition="//@Transition.1"
targetTransition="//@Transition.0" X="260" Y="110" name="q2"/>
<State xsi:type="Automaton2:FinalState" targetTransition="//@Transition.1"
X="405" Y="224" name="q3"/>
</Automaton2:Automatadiagram>
5.4. Testing
When we test the acceptance of the diagram, we create another java class named
TestAutomata for calling the EMF AutomataDiagram class. We added doTest methods
inside of EMF generated codes. We also create the frame with the SWT toolkit that has
text fields for inputting Strings for testing. If the strings in the text field are the same as
the route of the diagram, and if the input reaches the FinalState, then it returns “accept.”
10
Otherwise, it returns “reject.” However, when we would like to test the diagram, we will
have to copy the XML file into the TestAutomata class and define the argument each
time.
Figure 8: Testing Automaton
6. System Evaluation
GEF plays the part in adding, editing models, and in creating flexible connections
which is much simpler and easier than other Automata diagram editor tool created by the
applet. On the other hand, EMF is in charge of saving and testing. We could combine
GEF and EMF together however this requires more work to implement initially. Also,
when we test if the input is accepted or rejected, we have to copy the XML file that is
created by the information of the diagram, and put the file into java project as an
argument. This takes time and increases difficulty for the users. In order to solve this
problem, we will need to create another java class that automatically copies to the
specific java project and change the argument. Alternatively, we need to create another
plug-in that is able to obtain information of the file from the runtime workbench.
11
7. Conclusion and Future Work
There has been a considerable amount of work done trying to unify these two
popular Eclipse projects: EMF and GEF [5]. If we use GEF as editing tools, it becomes
much easier to create any diagrams graphically with shorter lines of code. Moreover,
EMF is an automatic code generator that corresponds to Ecore models, thus the
realization of greater projects will become possible. This means if more plug-ins are
combined together, the possibility will be infinite. Last year, Graphical Modeling
Framework (GMF) was created as a new Eclipse project that is to form a generative
bridge between EMF and GEF, whereby a diagram definition will be linked to a domain
model as input to the generation of a visual editor [4]. As possible work for the future, we
can apply GMF for our project with much simpler lines of code because we can
abbreviate the task of incorporating both GEF and EMF.
After we went through creating this automata diagram editor tool, we learned not
only about GEF and EMF, but also about how to create plug-in project on Eclipse. We
found that the most important things about frameworks development is that
understanding the basic idea such as, what function the framework has and what the
framework was created for. The basic idea of Eclipse is simple. “Everything is Plug-ins”
is the only one idea of Eclipse. Therefore, anyone can extend and integrate the functions
securely. We expect further development of these technologies in the future.
8. References
[1] Takezoe Naoki. Shida, Takahiro. Eclipse Plug-in Development guidebook.
Mycom Co, 2007.
[2] Hunter, Anthony. Boldt, Nick. Graphical Editing Framework (GEF),
http://www.eclipse.org/gef/
[3] Skrypuch, Neil. Eclipse Modeling Framework (EMF),
http://www.eclipse.org/modeling/emf/
[4] Aniszczyk, Chris. Using GEF with EMF.
http://planeteclipse.net/articles/Article-GEF-EMF/gef-emf.html
[5] Help - Eclipse Platform. GEF Programmer’s Guide.
12