ay by day, Model Driven Architecture (MDA) is gaining more focus in many organizations. MDA stresses the benefits of modeling at various levels of abstraction and the integration and flow of information among models. With MDA, first the object model is built, which differentiates it from the traditional approach of server side development. Models are built after good communication between various team members, and after modeling completion, development of software and systems is enabled.
With the help of MDA, business and application logic remains shielded from burgeoning technologies. It results in increased productivity for developers by maximizing compatibility between systems, simplifying the process of design and by smooth flow of information. Code built using MDA approach is consistent and maintainable.
|Figure 1. Figure GMF Development Flow: This chart shows the flow for developing a graphical editor using GMF.|
MDA can be achieved by using UML, DSL (Domain Specific Language), or other modeling solutions. DSL is one of the most efficient and proven ways of creating an MDA-based solution. There are many frameworks available for DSL like xText, EMF, GMF, Groovy, etc. In the following article we will showcase how to achieve MDA using GMF as a domain specific language.
What Is GMF?
Eclipse Graphical Modeling Framework (GMF) is a Domain Specific language framework which is used to develop graphical editors based on Eclipse Modelling Framework (EMF) and Graphical Editing Framework (GEF). It helps in defining the domain model, their properties, and relationships among them. A set of configuration files like meta model, graphical model, tooling model, and the mapping model are defined. These configuration files provide graphical representation of domain model, its constraint etc.
GMF Development Flow
|Figure 2. Use-Case Description: This method divides the application into three nodes.|
The screen shot shows the basic flow for developing a graphical editor using GMF. The starting point for creating the graphical editor plugin is to create a domain model file. It is used for creating graphical model, tooling model and mapping model. The graphical model is used to define various graphical properties of nodes and links in editor. The tooling model defines the palette which contains tools for creating nodes and links. The mapping model binds the domain model, graphical model, and tooling model together, which is then used for further processing.
How to Create a Graphical Editor Plugin
This tutorial depicts the steps for creating a GMF-based plugin. Before creation, there is a need to define the metamodel / domain model which defines various models and relationships among them. Let’s take a simple example of Entity based Application development. We will divide the Model into 3 nodes – Application, Entity & Attribute where application consists of one or more entities, where each entity dilutes into the set of attributes.
Follow Figure 2 for a better understanding.
This is the model that we are going to follow throughout our tutorial. Before directly diving into the series of steps, let’s see how the graphical editor looks after completion. This will give the basic idea of what we're going to create.
|Figure 3. Final Product -- Graphical Editor: This is what the graphical editor looks like when you're done. |
In Figure 3, the root of the editor is the topmost node, i.e. Application. Customer and order are entities which contain attributes like custId, custName and orderId, address respectively. Arrow drawn between entities shows relation between them. So with the idea of what we are going to do, we will dig down further.
Step 1: Setup
To work with GMF, eclipse needs GMF-based plugins to be installed. GMF plugins and its build dependencies can be found on the eclipse downloads page.
Step 2: Create GMF Project
To create a new GMF project, go to File, New, Other, New GMF Project. The project created contains a model folder that will contain all model files.