RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Model-Driven Architecture with GMF : Page 4

This approach results in increased productivity for developers by maximizing compatibility between systems and simplifying the design process.


Step 8: Create Generator Model

Generate model is input for the code generator. It is like a layer between mapping definition model and code generator. It contains the information from all files created till now. It provides more generation-specific details like class/package name or some specific parameters.

To create the generator model, right click on gmfmap file and Create Generator Model (Figure 17).

Figure 17. Generate Diagram Code: This creates a new project.

A file with gmfgen extension is created. The behavior of the graphical editor and its file can be customized by setting the properties such as diagram and domain file extension, package prefix, activator class name, saving diagram and domain information in same file, etc.

We will modify gmfgen file by changing its properties. We want single file for domain and diagram information and ‘model’ as extension. To achieve this, click on Gen Editor Node and set Same File For Diagram and Model to true and change Diagram File Extension & Domain File Extension properties to ‘model.’

Step 9: Generate Diagram Code

The last step in the creation of the graphical editor is generating diagram code. Generated diagram code is based on the properties in gmfgen file which in turn represents metamodel, graphical, tooling and mapping models. GMF uses Java Emitter Templates (JET) to generate source files from its EMF models. Templates are located in the org.eclipse.gmf.codegen plug-in, under the templates directory and they are arranged in commands, editor, part, policies and providers folders. There is a main Generator class which utilizes EmitterFactory to load templates and generate the java code.

To generate Diagram code, right click on gmfgen file, Generate Diagram Code. This creates a new project with .diagram appended to the core project name in same workspace. That’s it.

Figure 18. All Projects Created: This step shows your directory structure.

After generating the diagram code, your directory structure (Figure 18) should consist of main core project, one project with .diagram appended and one project with .edit name appended.

To run it, right click on any of these projects and RunAs, EclipseApplication. In runtime environment, create a new Model Diagram by right clicking and selecting Model Diagram (under Examples menu). Give a name to it and press Finish. A file with .model extension will be created in the specified location. We can use plugin.xml to customize the menu under which we want it to display.

As we have selected Application node as the root node for editor, therefore, properties view is showing its attributes when clicked on it.

Now click Entity from palette and drop it on the editor and give it a name. Drop Attributes inside Entity and specify properties. Use EntityRelation to make a connection between two nodes. See Figures 19 and 20 for reference.

As MDA is gaining more and more attention every day, there is a need to create a solution following the MDA approach. GMF helps us in achieving it easily and creating models which simplifies the development of an application. Following the MDA approach increases the pace of development and results in ore consistent and maintainable code. Apart from benefits provided by MDA, below are the advantages of GMF over other domain specific language frameworks:

Figure 19. Graphical Editor: This step shows the properties view.

  • GMF comprises of EMF and GEF which provides advantage of developing a rich, graphical, modeling oriented editor from a domain element.

  • Efforts for graphical editor development reduce drastically.

  • Various models can be visualized by using this framework.

  • GMF generates the code based upon model that can be modified manually also.
Models created using MDA are ultimately transformed to source code like Java, C++, etc. and associated resource files. This is known as model-to-text transformation. Model-to-text transformation generally uses templates to generate the text files. Some of the commonly used templating languages are:

    Figure 20. Graphical Editor with Entities and Attributes: Use EntityRelation to make a connection between two nodes.

  • JET (Java Emitter Templates)

  • Freemarker

  • Velocity

  • Xpand (part of openArchitectureWare)

  • Acceleo Template Language
You now know all the required steps for creating a GMF-based plugin.

Abhishek Pratap Singh works as a Senior Technical Specialist for Infosys Technologies Ltd. in SETLabs, the R&D division of the company. He specializes in the design and architecture of Java EE solutions, cloud databases, software factory, Eclipse plug-ins, and tools development.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date