Chapter 3. Create an EMF model from your metamodel

3.1. With the dynamic instance creation tool

This is the most simple way to create an instance of your metamodel. You right click on the root class/model object of you metamodel (in our example, it is the Fsm class) : actually all your classes are only available, for creation, through this root class (remember, the containment property).

Create dynamic instance from an ecore file

Figure 3.1. Create dynamic instance from an ecore file

3.2. Using a reflexive editor

You should favour this solution if your metamodel is relatively stable, as it allows you to customize the generated editor to match your metamodel specificities. (see the end of this article: )

3.2.1. Generate the editor

This is the most ergonomic – but longest – way to create an instance of your metamodel. We will not detail the process here, but only give you the main lines:

  1. once your metamodel is created, you can create a model for model generation, called genmodel :

    1. File > New > Other > Eclipse Modeling Framework folder > EMF Models

    2. choose a name for your genmodel (fsm.genmodel is ok)

    3. select Load from an EMF core model button, and find your metamodel (fsm.ecore)

    4. select the unique package fsm

  1. you need to change, in the Properties tab of your genmodel, the model directory, in order to avoid weird behavior (particularly if the project you are working in was not set as a “Java project”) : please change the property called Model Directory (in the Model folder), to /MyFirstEMFSamples.model/src, so that the EMF source code is generated in a new empty project that will exclusively contain this source code.

  2. right-click on the root node of your fsm.genmodel, and choose the Generate all item.

3.2.2. Use the editor

  1. To be able to use the generated reflexive editor, you have to launch a new runtime workbench, through the tool bar menu:

    1. Run > Run As > Run-time Workbench (in eclipse 3.0.2)

    2. or Run > Run... > Eclipse application item in the right part > New button > Apply button > Run button at the bottom (eclipse 3.1)

  1. a new eclipse application is launched, so now you can create a new simple project (e.g called MyFirstEMFInstances), and select File > New > Other > Example EMF Creation Wizards folder > Fsm Model

  2. now, to create an EMF model, you have to follow the same principles as the creation of an ecore model. So, you can report to the metamodel creation steps, section 2.1, p.3, and adapt them (for example, the model object, which was EPackage in the metamodel creation, becomes Fsm in the EMF model creation)

  3. as you work in another Eclipse environment, you will probably want to copy the models that you created this way in your initial project (the one named MyFirstEMFSamples). Simply do it.