Chapter 4. Editor

In this chapter we present how to create instances of the Fsm metamodel. You can use two ways to do that, creating dynamic instances directly or using an EMF tree editor.

4.1. Dynamic instances

Like shown in the Process tutorial create a dynamic instance is an easy way to create an instance of a metamodel during the first development phases. To do so :

  1. Create a new folder dynamic_instance in org.eclipse.fsm.emf .Open the fsm.ecore file with the Sample Ecore Model Editor (Right click on the file -> Open with -> Sample Reflective Ecore Model Editor)

  2. To open the content of thid file click on the arrows at the left. Then, right click on the FSM metaclass -> Create Dynamic Instance and select the folder dynamic_instance. Name your instance fsm.xmi.

Create dynamic instance from an Ecore file

Figure 4.1. Create dynamic instance from an Ecore file


Open this instance with the Sample Reflexive Ecore Model Editor (like shown above). You can add two State st1 and st2 on the FSM class and then a transition a that produce b between st1 and st2 like in the following image :

Example of dynamic instance

Figure 4.2.  Example of dynamic instance


The Logo tutorial ( chapter 4 Editor, section 4.1 Dynamic Instance) presents how to create a dynamic instance with an ecorediag. The next section presents another way to create instances of a given metamodel, create a tree view editor with an EMF project.

4.2. Tree view editor

Tree view editors should be favoured for meta-models that are relatively stable and for final development phase. It allows to customize the generated editor to match meta-model specificities. (see the end of this article: Eclipse Corner Article : Using EMF)

4.2.1. Generate the editor

This is the most ergonomic – but longest – way to create an instance of a meta-model. This method is here presented in its main lines:

  1. Create a new project and a new ecore metamodel ( this step was ever made in the section Create the fsm meta-model )

  2. Once the meta-model is created, it is possible to create a model for model generation, called genmodel:

    1. Right click on the file fsm.ecore New > Other > Eclipse Modeling Framework folder > EMF Generator Model and select Next;

    2. Keep the proposed name (fsm.genmodel) and click on Next. Then, select Ecore model in the following wizard and click on Next;

    3. Here, the metamodel is ever selected. Otherwise, select Browse workspace button, and find the meta-model file (fsm.ecore into or.kermeta.fsm.emf/model). Then click on Load button and on Next;

    4. Select the package fsm at the top of the window and click on Finish

    5. In order to avoid weird behaviour (particularly if the current project was not set as a “Java project”) the model directory of the genmodel needs to be changed in the Properties tab of the genmodel. For this purpose, click on the root node of the fsm.genmodel and change the property called Model Directory (in the Model folder) to /org.kermeta.fsm.emf.model/src, so that the EMF source code is generated in a new empty project that will exclusively contain this source code. You need also to change the property Model Plug-in ID to org.kermeta.fsm.emf.model .

      Model Directory Property

      Figure 4.3.  Model Directory Property


    6. Right-click on the package node of the fsm.genmodel (second sub node, it corresponds to the fsm package), and choose the Generate all item.

You should obtain the following plugins (if we not consider the folder dynamic_instance which is not linked with the EMF editor creation) :

Plugins Generated with EMF

Figure 4.4. Plugins Generated with EMF


You can customize this EMF editor following the example given on the section Customize the generated EMF editor . The next section presents how to use this newly created tree view editor.

4.2.2. Use the editor

To be able to use the generated reflexive editor, a new runtime workbench has to be launched through the tool bar menu:

  1. In Eclipse Galileo (3.5), right click on org.kermeta.fsm.emf.editor and select Run As -> Eclipse Application

  2. Once the new eclipse application is launched, create a new General project (File -> New -> Other-> General -> Project). Call it MyFirstEMFInstances). Then select File > New > Other > Example EMF Model Creation Wizards folder > Fsm Model to create your instance file and choose FSM as Model Object;

  3. To add elements to your model just right click on the FSM container and add new Child or new Sibling like in metamodels 's creation steps (cf fsm.xmi example in the section Dynamic Instances ;

[Note] Parallelism between edit a model or a metamodel

Creation of an EMF model follows the same principles that the creation of an Ecore model. Note that the model object, which was EPackage in the meta-model creation, becomes Fsm in the EMF model creation.

You can use another editors to create instances models such as graphical or textual editors. The following sections presents rapidly this kind of editors.

4.3.  Textual editors

You can also use textuals editors like XText , EMFText, Sintaks (which is part of the Kermeta project) . This textuals editors are not detailed here, please refer to the Logo tutorial (chapter 4 Editor, section 4.3 Textual Editor).

4.4.  Graphical editors

EMF metamodels can be used with tools like GMF (Graphical Modelling Framework) or Topcased (the FSM Diagram from Kermeta -> Samples FSM was created with Topcased) to create graphical editors for model instances. The tutorial How to create a FSM graphical editor with GMF? explains the creation of an GMF editor with a very simple FSM metamodel. You can retrieve the result of this tutorial and the gmf models into fr.irisa.triskell..kermeta.samples.fsm.gmf.

You know how to create a model conform to the Fsm metamodel. The next chapter explains how to manipulate models with Kermeta.