Free tutorials for Java, Eclipse and Web programming



Follow me on twitter

3. Define EMF model

3.1. Create project

Create a new project "de.vogella.emf.webpage.model" via File / New / Project... / Eclipse Modeling Framework /Empty EMF project

3.2. Create Ecore diagram

Select the folder "model", right click on the folder and select New / Other... / Ecore Tools / Ecore Diagram

Name your "Domain File Name" "webpage.ecore".

This should open a visual editor for creating EMF models.

Open the "Properties" view via Window -> Show View -> Other -> "Properties". This view will allow you to modify the attributes of your model elements.

Click on EClass and click into the editor to create a new class. Create the classes "MyWeb", "Webpage", "Category" and "Article".

Using the EAttribute node assign to each object the atttribute "name" of String "EString".

Add the attributes "title", "description" and "keywords" to "MyWeb" and "Webpage".

We want to use the data type calendar in our model. Select "EDataType" and give it the name "calendar" and type "java.util.Calendar". Add the EAttribute "created" to "Article" and use your new type.

Select EReferences and create an arrow similar to the following picture. Make sure the upper bound is set to "*" and that the "Is Containment" property is flagged.

3.3. View Ecore diagram

Close the dialog and open the file "webpage.ecore". The result should look like the following.

3.4. Create EMF Generator Model

Select your "webpage.ecore" -> Select File -> New -> Other -> "EMF Generator model" and create "webpage.genmodel" based on your "Ecore model".

Select your model and press load.

3.5. Set the package

Open "webpage.genmodel" and select the node "Webpage". Set the "base package" property to "de.vogella.emf.webpage.model".