Generating an Extended EMF 1.1 Model

This tutorial is a follow-on to the tutorial "Generating an EMF Model" in which a simple "library" model is generated. In that tutorial, we showed how an EMF model can be generated very easily from a Rose model or a set of Java interface files. In this tutorial, we will show you how an extended EMF model, one that extends an existing model, can be generated.

First of all, let us review what the "library" model contains:

We are now going to extend this "library" model by creating a new package called "schoollibrary". The "schoollibrary" package contains three classes, two of which extend classes in the "library" model:


This tutorial will show you step-by-step how to generate an EMF model of this "schoollibrary" package using the existing "library" model. As in the previous tutorial, we will demonstrate creating this new model from a Rose model and from a set of Java interfaces.

The screenshots in this tutorial were captured using version 2.1 of the Eclipse SDK and version 1.1.0 (build 20030501_0612VL) of EMF.

Contents

Step 0: Prerequisites
Step 1: Creating a New EMF Model Project from a Rose Model or Java Interfaces
Step 2: Generating the EMF Model and the Editor
Step 3: Running the Generated Editor
Step 4: Modifying the Editor
Appendix:
An Alternative Way of Generating the Model and Editor


 contents

Step 0: Prerequisites

You have generated the library model as well as its editor in an Eclipse workspace following the instructions in the tutorial "Generating an EMF Model".


 contents

Step 1a: Creating a New EMF Model from a Rose Model

Save the Rose model file schoollibrary.mdl somewhere on your workstation, say, d:\tmp\lib. It contains both the "library" and "schoollibrary" packages:



We should really place each of the packages in a separate ".cat" file and reference them in the ".mdl" file. This would enable the packages to be shared by various models. However, this is not the key for this tutorial, we have duplicated the "library" package in the previous tutorial in the "schoollibrary" model. The generator behaves exactly the same whether the package is contained inside the same ".mdl" file or referenced in an external ".cat" file.

The following steps will create a new EMF model project in the workspace:


 contents

Step 1b: Creating a New EMF Model from Java Interfaces

Here are the annotated Java interfaces for the "schoollibrary" package. We can create the GenModel from these interface files instead of a Rose model.
SchoolLibrary.java
package org.eclipse.example.schoollibrary;

import org.eclipse.example.library.Library;

/**
* @model
*/
public interface SchoolLibrary extends Library
{
/**
* @model
*/
String getLocation();
}
Asset.java
package org.eclipse.example.schoollibrary;

/**
* @model
*/
public interface Asset
{
/**
* @model
*/
float getValue();
}
SchoolBook.java
package org.eclipse.example.schoollibrary;

import org.eclipse.example.library.Book;

/**
* @model
*/
public interface SchoolBook extends Book, Asset
{
}



  1. Create a Java Project

  2. Import the Interfaces

    You can create and type in the interfaces as in the previous tutorial, but we will show here how to import them from the zip file schoollibrary.zip.

  3. Create the Gen(erate) Model


 contents

Step 2: Generating the EMF Model and the Editor

The GenModel shows a root object, which represents the whole model. The immediate children under the root object represent the packages inside the model.


 contents

Step 3: Running the Generated Editor

Before a run-time workbench instance can be run, a launch configuration need to be setup. 

The school library model wizard can now be used to create a new instance of the model.


 contents

Step 4: Modifying the Editor

This part of the tutorial will show you how you can change the label in the generated editor in a number of ways.

Quit the run-time workbench instance and go back to the Resource perspective of the original Eclipse workbench with the "schoollibrary" genmodel.


 contents

Appendix: An Alternative Way of Generating the Model and Editor

If you do not already have the base model "Library" and its editor generated in separate projects, you can have both the "Library" and "School Library" models generated into the same set of projects. This can be done either through a Rose model or through a set of Java interfaces.

  1. Through Rose Model

  2. Through Java Interfaces:

  3. Generating the EMF Model and the Editor

  4. Running the Generated Editor


contents