Chapter 3State of the ART3.1 IntroductionThis Chapter aims to complete the information presented in the chapter with the same name from theMEng Hons Project Phase 1 Report by oering a more in depth description of the Graphical EditingFramework and the Xtext Framework.
These are the main technologies used to realise this project and the information presented here is thekey to understanding the planning, implementation and testing aspects described in this report.3.2 Graphical Editing FrameworkThe Graphical Editing Framework (GEF) is a framework used to build graphical editors and applicationsthat can be easily integrated in the Eclipse UI.We are using GEF 3.11, which is also used to create the Visual Expressions plug-in for e2 studio.
This aspect translates to less problems during integration and maintenance of this project.It can be installed into Eclipse by Help->Install New Software and using the http://download.eclipse.org/tools/gef/updates/legacy/releases/. link.
3.2.1 Draw2dDraw2D sits at the base of GEF and is a layout and rendering toolkit building on top of SWT. It handles2 dimensional drawing and works along four concepts: Event dispatcher, Lightweight system, Updatemanager and Layout managers.Draw2D handles the event dispatching, the updating of gures and acts as a container of all gures.More features include ecient layout and rendering support, various gure and layout implementationsand borders.
Moreover, it allows to create complex drawings by the use of the parent-child relationshipbetween gures.Renesas Electronics Europe Ltd R Confidential24Figure 3.1: GEF, Draw2d, RCP3.2.2 The GEF MVC ArchitectureBefore we can explain the interactions between the Model, the View and the Controller, we have to denethem and the concepts that lie behind these denitions.
Every part of the Graphical Editor that we want to display and edit will have a Model, a Figure andan EditPart.The ModelThe model contains the information we need to visualise and edit. It is usually designed as a tree structureto help capturing the elements of the view. It starts from a base class that is extended to represent eachof the graphical elements.Figures- ViewThe Figues are what the user will see.
They can be modelled from basic Draw2d gures such as rectangles,triangles, lines and points. The connection with Controller is realised inside the EditPart classes throughthe createFigure() function which returns the Figure.ControlUnder the Control section of the GEF Architecutre we nd more components. We describe bellow thepurpose of these components.EditPartsThe EditParts are the core part of the Controller and the most basic part of GEF. An EditPart connectsthe Model with the View.
The gures are refreshed every time the user performs a change.Renesas Electronics Europe Ltd R Confidential25EditPart factoryThe EditPart factory is the rst connection point between the Model and the Controller. Its mainpurpose is to detect which EditPart is used depending on the element of the model.EditPoliciesThe changes performed by the user are handled by the EditPolices. Each EditPolicy species whathappens inside the EditPart when a task is performed. An EditPolicy is installed on an EditPart throughthe createEditPolicies() function.RequestsA request is what leads to a change to happen and it is strongly connected with an EditPolicy.
Wesay that a request has been triggered when the user performs an action that is detected by the GEFframework. Some types of requests can be selection, delete, move or change layout requests. Dependingon the type of the request the EditPolicy decides which command is executed.
CommandsThe Command object is created inside the EditPolicy as a result of a Request. The EditPolicy decides ifand how the command will be executed. Most of the commands have 4 main functions: one function forsetting the parent of the gure we will make the change on, one function setting the gure we performthe change on, an execution function which denes the change and an undo- revert function which willdene how the change performed can be reverted.ActionsContext menus and action bars are used to improve the functionality of an editor.
Because they areoutside the View, the commands can not be triggered by a Request directly, but by an Action. In otherwords, the action requests a command from outside the View.3.2.3 MVC InteractionNow that we have explained the concepts behind the Model- View- Controller Architecture we candescribe how the interactions between these is realised. Please keep in mind that under the Controlsection we nd the EditParts, the EditPart factory, the EditPolicies, the Requests, the Commands andthe Actions.• The EditPart factory assigns an EditPart for each corresponding node in the model.
• The EditPart is initiated and creates its corresponding Figure.• The EditPolicies are installed.Renesas Electronics Europe Ltd R Confidential26• Requests and Actions trigger Commands that change the model.• The EditPart refreshes the gures and the View based on the new information from the model.Figure 3.2: The MVC Architecture3.3 XtextAs mentioned to you, the Graphical Editor is part of a Multi-page Editor which oers a rich text editortogether with a Form-based Memory and Sections Pages.
This previous implementation of the Multi-pageEditor lies on top of an Xtext plug-in project.Xtext is a Java framework used to develop or model small textual domain-specic programminglanguages. The version of Xtext used by our project is 2.11 and it can be installed into Eclipse by usingthe following link:http://download.eclipse.org/modeling/tmf/xtext/updates/composite/releases/3.4 Runtime ConceptsXtext includes some Runtime Concepts that govern the plug-in’s back-end and the generation of themodel from the dened Domain Specic Language(DSL).
IDE ConceptsThese concepts create almost immediately the features of a Rich Text Editor which can be included intoan Eclipse-based IDE such as e2 studio.Some of these features include Content Assist, Linking, Code Formatting, Scoping, Validation andQuick Fixes.The GrammarThe grammar of the language we want to dene or model lies at the base of Xtext. It is usually a singlele that captures the syntax of the programming language as a domain-specic language.
Renesas Electronics Europe Ltd R Confidential27When an input le is analysed by an on-the-y parser, a model (Xtext model) is produced. Eachelement of the model has an URI. This is the key for locating and editing parts of the input le.Code GeneratorThe Code Generator feature of Xtext will generate, among other Java code, Java classes for each of theelements of this model.
Based on these classes, we can build other editing features.3.5 SummaryWe have presented in this chapter the main information required for a better understanding of thisreport.