Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Sirius/Tutorials/DomainModelTutorial"
(→How to create our Metamodel) |
|||
Line 2: | Line 2: | ||
This tutorial explains how to create your first EMF Metamodel. | This tutorial explains how to create your first EMF Metamodel. | ||
− | This tutorial can be seen as the start of Sirius [[Sirius/Tutorials/4MinTutorial | Starter Tutorial]] before Starter Tutorial | + | This tutorial can be seen as the start of Sirius [[Sirius/Tutorials/4MinTutorial | Starter Tutorial]] before Starter Tutorial. |
We will create the basic family Metamodel | We will create the basic family Metamodel | ||
Revision as of 05:15, 3 August 2016
Contents
Overview
This tutorial explains how to create your first EMF Metamodel. This tutorial can be seen as the start of Sirius Starter Tutorial before Starter Tutorial. We will create the basic family Metamodel
Create my first metamodel
Our metamod will have 4 concepts. These concepts will be the basics concepts about family. The first concept is Family. A family has a name type of Estring. A family contains members type of Person. A person has a name type of EString. A person has 2 parents and many or no children. Two concepts herited from Person are Man and Woman. A person should have 1 father type of Man or/and 1 mother type of Woman or neither father nor mother. To sum up, our metamodel have 4 concepts
- Family
- Person
- Man
- Woman
and 6 relations
- members from Family to Person
- children from Person to Person, with cardinality 0..*
- parents from Person to Person with cardinality 0..2
- father from Person to Man with cardinality 0..1
- mother from Person to Woman with cardinality 0..1
- an extend from Person for Man and Woman
How to create our Metamodel
We will use Ecore Tools (based on EMF and Sirius) to create our Metamodel. You can find it here: EcoreTools site To install it, menu Help/Install New Software...
Click on Add… button and fill the fields
- Name: Ecore Tools Modeler
- Location: One of update site of EcoreTools UpdateSite
Click on Ok button
Ckick on Next and follow instructions.
After Sirius has restarted, in Model Explorer View, right click New->Other...
In Ecore Modeling Framework select Ecore Modeling Project
Name it org.eclipse.sirius.sample.basicfamily
Click on Finish, then select the Design viewpoint.
Now you can use the palette to create the elements of the metamodel described previously. Click on Class in palette to create Family, Person, Man and Woman. The element Person is abstract.
Click on Relation Composition in palette to create compostion named members between Family and Person.
Click on Relation Bi-directional Reference in palette to create the bi directional reference named children and parents on Person
Click on Relation SuperType in palette to create the inheritence between Mand and Person and Woman and Person
You should obtain this metamodele
For more informations about Ecore Tools modeler Links to blog post on best practices to create a metamodel:
How to generate the source code of the Metamodel
You should retrieve the basicfamily.ecore Ns URI. Open the basicfamily.ecore and select tab Model in properties view. Change the Ns URI to http://www.eclipse.org/sirius/sample/basicfamily
Open the basicfamily.genmodel. This model allows EMF to generate the Java code corresponding to the metamodel.
Right click on first model element and select Generate All
The "Generate All" produces these elements :
- The code src in org.eclipse.sirisus.sample.basicfamily
- The MANIFEST.MF in the META-INF directory
- The directory org.eclipse.sirisus.sample.basicfamily.edit
- The directory org.eclipse.sirisus.sample.basicfamily.editor
- The directory org.eclipse.sirisus.sample.basicfamily.tests
How to test the metamodel
Launch a runtime to use the basic family concept.
In Model Explorer View, right click New->Other...
In Eclipse Modeling Framework Example EMF Model Creation Wizards, select BasicFamily Model
As you can see the BasicFamily Model have the default EMF icons.
To change this icon, modifiy BasicfamilyModelFile.gif
in /org.eclipse.sirisus.sample.basicfamily.editor/icons/full/obj16/
To obtain
Warning For every icons changes, you must restart the sirius runtime to see change.
Click on Next> button to create a basicfamily model.
Select Model Object Family
and click on Finish Button.
To add element to model right click on Family element and select Man or Woman element.
In properties view you can retrive element name and choose Parents or Children if elements are already present in model.
You can also change the icon for Man, Woman and Family defined in /org.eclipse.sirisus.sample.basicfamily.edit/icons/full/obj16