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

EMF Editor goes RAP

Revision as of 11:21, 24 November 2007 by Reinhold.bihler.gmx.de (Talk | contribs) (Using the Editor)

How to turn an automatic generated EMF editor into an RAP application

The Simple Purchase Order Model

To generate the EMF editor we first need a Ecore model. We will use the Simple Purchase Order model (file SimplePO.ecore) that is also used in the EMF book. In an UML Editor this model looks as depicted below:

SimplePO.gif

The SimplePO.ecore file viewed in a text editor:

<?xml version="1.0" encoding="ASCII"?>
<ecore:EPackage xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="po"
    nsURI="http:///com/example/po.ecore" nsPrefix="com.example.po">
  <eClassifiers xsi:type="ecore:EClass" name="PurchaseOrder">
    <eStructuralFeatures xsi:type="ecore:EReference" name="items" upperBound="-1"
        eType="#//Item" containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="shipTo" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="billTo" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Item">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="productName" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="quantity" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="price" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFloat"/>
  </eClassifiers>
</ecore:EPackage>

The Code Generation Model

To generate code from the SimplePO.ecore model we first need to create a corresponding code generation model (file SimplePO.genmodel) for storing the code generation customization data. Assumed you have all the EMF plugins installed in your Eclipse environment you can do this by a right click on the SimplePO.ecore file in the Package Explorer:

CreateGenModel1.gif

Select the EMF Model wizard:

CreateGenModel2.gif

Click the Next button two times:

CreateGenModel3.gif CreateGenModel4.gif

Press the Load button and the Next button afterwards:

CreateGenModel5.gif

A click on the Finish button finally creates the SimplePO.genmodel file.

CreateGenModel6.gif

The code generation model allows you to customize the code generation. E.g. the properties Model Directory, Editor Directory, and Edit Directory determine into which folder the model, editor and edit code is generated. You can change the Model Plug-in ID and a lot's of other stuff.

File:CodeGenerationPaths.gif

Generating the Code

To generate the code for the model, edit and editor plugin simply do a right click on the root element of the SimplePO.genmodel and select Generate All

GenerateCode.gif

This generates four plugin projects and appropriate code into the directories specified in the code generation model. In this example the SimplePO, SimplePO.edit, SimplePO.editor and the SimplePO.test plugin project directories.

GeneratingCode.gif

Running the Editor

By right clicking on the SimplePO.editor project directory and selecting <Run As> <Eclipse Application> the just generated editor is started in a new Eclipse instance (this might take some seconds).

RunTheEditor.gif

The new Eclipse instance includes the generated plugins SimplePO Model, SimplePO Edit Support and SimplePO Editor as you can see by going into the <Help> <About Eclipse SDK> window and pressing the <Plug-in Details> button.

EclipseWithGeneratedEMFPlug.gif

Using the Editor

To use the editor you can right click into the Package Explorer and select the Po Model wizard via <New> <Other...> .

SelectThePOWizard.gif

Secify a project and a file name for the new SimplePO model instance file and press Next

SpecifiyEditorFile.gif

In the next page of the wizard select a Model Object to edit and the encoding of the XML file that stores the edited data and press Finish

POObjectAndEncoding.gif

Now you can use the Editor by adding a new child to the root Purchase Order object or by editing object attributes in the Properties View.

EditingWithTheEditor.gif

The edited data is stored in the specified file (in this example in the My.po file) in EMF's default XMI format. You can also load already existing SimplePO model instance files e.g. the SimplePOModelXMIDeserilizationTest.po file that is contained in the zip file that is attached to this page.

LoadPOResource.gif

View and Edit the loaded resource:

LoadedResourc.gif

The SimplePO plugins

A zip file that contains the generated plugins as well as the SimplePOModelXMIDeserilizationTest.po file can be downloaded under http://wiki.eclipse.org/Image:SimplePOPlugins.zip

Back to the top