Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Sirius/Tutorials/DomainModelTutorial"

(Install Ecore Tools)
(Create an Ecore Modeling Project)
Line 58: Line 58:
  
 
[[File:Sirius_tuto4_05.png]]
 
[[File:Sirius_tuto4_05.png]]
 +
  
 
In Ecore Modeling Framework select ''Ecore Modeling Project''
 
In Ecore Modeling Framework select ''Ecore Modeling Project''
  
 
[[File:Sirius_tuto4_06.png]]
 
[[File:Sirius_tuto4_06.png]]
 +
  
 
Name it <code>org.eclipse.sirius.sample.basicfamily</code>
 
Name it <code>org.eclipse.sirius.sample.basicfamily</code>
Line 67: Line 69:
 
[[File:Sirius_tuto4_07.png]]
 
[[File:Sirius_tuto4_07.png]]
  
Click on ''Finish'', then select the ''Design viewpoint''.
+
 
 +
Click on ''Finish'' : Ecore Tools creates a project containing an Ecore model with an empty package and a blank diagram.
  
 
[[File:Sirius_tuto4_08.png]]
 
[[File:Sirius_tuto4_08.png]]
 +
 +
 +
==Create the elements of the metamodel==
  
 
Now you can use the palette to create the elements of the metamodel described previously.
 
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''.
 
  
 
[[File:Sirius_tuto4_09.png]]
 
[[File:Sirius_tuto4_09.png]]
  
Click on Relation '''Composition''' in palette to create compostion named ''members'' between '''Family''' and '''Person'''.
+
 
 +
Use the '''Class''' tool in the palette to create ''Family, Person, Man and Woman''. Use the properties view to set '''Person''' as ''abstract''.
  
 
[[File:Sirius_tuto4_10.png]]
 
[[File:Sirius_tuto4_10.png]]
  
Click on Relation '''Bi-directional Reference''' in palette to create the bi directional reference named ''children'' and ''parents'' on '''Person'''
+
 
 +
Note that you can edit the name of a model element (class, attribute, relation) directly from the diagram: just click on a selected element to activate the label edition (let some time before the selection and the click to avoid triggering a double-clik).
 +
 
 +
Use the '''Composition''' tool in the palette to create a composition relation named ''members'' between '''Family''' and '''Person'''.
  
 
[[File:Sirius_tuto4_11.png]]
 
[[File:Sirius_tuto4_11.png]]
  
Click on Relation '''SuperType''' in palette to create the inheritence between '''Mand''' and '''Person''' and '''Woman''' and '''Person'''
+
 
 +
Use the '''Bi-directional Reference''' tool in the palette to create the relation named ''children'' and ''parents'' from '''Person''' to '''Person'''.
  
 
[[File:Sirius_tuto4_12.png]]
 
[[File:Sirius_tuto4_12.png]]
  
You should obtain this metamodele
+
Use the '''SuperType''' tool in the palette to create the inheritance relations from '''Man''' and '''Woman''' to '''Person'''
 +
 
 +
You should obtain this diagram:
  
 
[[File:Sirius_tuto4_13.png]]
 
[[File:Sirius_tuto4_13.png]]
  
For more informations about [https://www.eclipse.org/ecoretools/doc/index.html Ecore Tools modeler]
+
 
Links to blog post on best practices to create a metamodel:
+
More information about [https://www.eclipse.org/ecoretools/doc/index.html Ecore Tools modeler]
 +
 
 +
Best practices on how to create a metamodel with Ecore:
 
* [http://cedric.brun.io/eclipse/ecore-design-checklist-part1/ Ecore design checklist part1]
 
* [http://cedric.brun.io/eclipse/ecore-design-checklist-part1/ Ecore design checklist part1]
 
* [http://cedric.brun.io/eclipse/ecore-design-checklist-part2/ Ecore design checklist part2]
 
* [http://cedric.brun.io/eclipse/ecore-design-checklist-part2/ Ecore design checklist part2]

Revision as of 11:18, 3 August 2016

Overview

This tutorial explains how to create your first EMF Metamodel. It can be seen as the early step before the Starter Tutorial.


These instructions describe the creation of the BasicFamily metamodel. This metamodel defines 4 concepts that can be use to describe a family:

  • The first concept is Family. A family has a name of type Estring.
  • A family contains members of type Person. A person has a name of type EString.
  • A person has 2 parents and many or no children.
  • Two concepts herited from Person are Man and Woman.
  • A person can have one father of type Man and/or one mother of type Woman.

Sirius tuto4 01.png


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

Create the Metamodel

The easiest way to define a metamodel is to use Ecore Tools (based on EMF and Sirius), a graphical editor for Ecore models.

Install Ecore Tools

If you are using Obeo Designer or Eclipse Modeling packages, Ecore Tools is already installed.

Otherwise, you can find it here: EcoreTools site

To install it, click on Help/Install New Software...

Sirius tuto4 02.png

Click on Add... and fill the fields

Sirius tuto4 03.png

Click on Ok.

Sirius tuto4 04.png

Finally, Click on Next > and follow the instructions to complete the installation.

Create an Ecore Modeling Project

In the Model Explorer View, right click on New->Other...

Sirius tuto4 05.png


In Ecore Modeling Framework select Ecore Modeling Project

Sirius tuto4 06.png


Name it org.eclipse.sirius.sample.basicfamily

Sirius tuto4 07.png


Click on Finish : Ecore Tools creates a project containing an Ecore model with an empty package and a blank diagram.

Sirius tuto4 08.png


Create the elements of the metamodel

Now you can use the palette to create the elements of the metamodel described previously.

Sirius tuto4 09.png


Use the Class tool in the palette to create Family, Person, Man and Woman. Use the properties view to set Person as abstract.

Sirius tuto4 10.png


Note that you can edit the name of a model element (class, attribute, relation) directly from the diagram: just click on a selected element to activate the label edition (let some time before the selection and the click to avoid triggering a double-clik).

Use the Composition tool in the palette to create a composition relation named members between Family and Person.

Sirius tuto4 11.png


Use the Bi-directional Reference tool in the palette to create the relation named children and parents from Person to Person.

Sirius tuto4 12.png

Use the SuperType tool in the palette to create the inheritance relations from Man and Woman to Person

You should obtain this diagram:

Sirius tuto4 13.png


More information about Ecore Tools modeler

Best practices on how to create a metamodel with Ecore:

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

Sirius tuto4 14.png

Open the basicfamily.genmodel. This model allows EMF to generate the Java code corresponding to the metamodel.

Sirius tuto4 15.png

Right click on first model element and select Generate All

Sirius tuto4 16.png

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

Sirius tuto4 17.png

How to test the metamodel

Launch a runtime to use the basic family concept.

In Model Explorer View, right click New->Other...

Sirius tuto4 18.png

In Eclipse Modeling Framework Example EMF Model Creation Wizards, select BasicFamily Model

Sirius tuto4 19.png

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/

Replace by Sirius tuto4 20.gif

To obtain

Sirius tuto4 21.png

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.

Sirius tuto4 22.png

To add element to model right click on Family element and select Man or Woman element.

Sirius tuto4 23.png

In properties view you can retrive element name and choose Parents or Children if elements are already present in model.

Sirius tuto4 24.png

You can also change the icon for Man, Woman and Family defined in /org.eclipse.sirisus.sample.basicfamily.edit/icons/full/obj16

  • Man by Sirius tuto4 25.gif
  • Woman by Sirius tuto4 26.gif
  • Family by Sirius tuto4 20.gif

To replace Sirius tuto4 27.png

By Sirius tuto4 28.png

Back to the top