|
|
(10 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
− | =How to turn an automatic generated EMF editor into an RAP application=
| + | #REDIRECT[[RAP/EMF_Integration]] |
− | | + | |
− | ==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 <tt>SimplePO.ecore</tt>) that is also used in the EMF book. In an UML Editor this model looks as depicted below:
| + | |
− | | + | |
− | <center>[[Image:SimplePO.gif]]</center>
| + | |
− | | + | |
− | The <tt>SimplePO.ecore</tt> file viewed in a text editor:
| + | |
− | <pre>
| + | |
− | <?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>
| + | |
− | </pre>
| + | |
− | ==The Code Generation Model==
| + | |
− | To generate code from the <tt>SimplePO.ecore</tt> model we first need to create a corresponding code generation model (file <tt>SimplePO.genmodel</tt>) 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 <tt>SimplePO.ecore</tt> file in the Package Explorer:
| + | |
− | <center>[[Image:CreateGenModel1.gif]]</center>
| + | |
− | Select the EMF Model wizard:
| + | |
− | <center>[[Image:CreateGenModel2.gif]]</center>
| + | |
− | Click the <b>Next</b> button two times:<br>
| + | |
− | <center>[[Image:CreateGenModel3.gif]] [[Image:CreateGenModel4.gif]]</center><br>
| + | |
− | Press the <b>Load</b> button and the <b>Next</b> button afterwards:<br>
| + | |
− | <center>[[Image:CreateGenModel5.gif]]</center><br>
| + | |
− | A click on the <b>Finish</b> button finally creates the <tt>SimplePO.genmodel</tt> file.<br>
| + | |
− | <center>[[Image:CreateGenModel6.gif]]</center><br>
| + | |
− | The code generation model allows you to customize the code generation. E.g. the properties
| + | |
− | <tt>Model Directory</tt>, <tt>Editor Directory</tt>, and <tt>Edit Directory</tt> determine into which folder the model, editor and edit code is generated.<br>
| + | |
− | <center>[[Image:CodeGenerationPaths.gif]]</center>
| + | |
− | ==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 <tt>SimplePO.genmodel</tt> and select <b>Generate All</b><br>
| + | |
− | <center>[[Image:GenerateCode.gif]]</center>
| + | |
− | This generates four plugin projects and appropriate code into the directories specified in the code generation model. In this example the <tt>SimplePO</tt>, <tt>SimplePO.edit</tt>, <tt>SimplePO.editor</tt> and the <tt>SimplePO.test</tt> plugin project directories.
| + | |
− | <center>[[Image:GeneratingCode.gif]]</center>
| + | |
− | ==Running the Editor==
| + | |
− | By right clicking on the <tt>SimplePO.editor</tt> project directory and selecting <b><Run As></b> <b><Eclipse Application></b> the just generated editor is started in a new Eclipse instance (this might take some seconds).
| + | |
− | <center>[[Image:RunTheEditor.gif]]</center>
| + | |
− | The new Eclipse instance includes the generated plugins <tt>SimplePO Model</tt>, <tt>SimplePO Edit Support</tt> and <tt>SimplePO Editor</tt> as you can see by going into the <b><Help> <About Eclipse SDK></b> window and pressing the <b><Plug-in Details></b> button.
| + | |
− | <center>[[Image:EclipseWithGeneratedEMFPlug.gif]]</center>
| + | |
− | ==Using the Editor==
| + | |
− | To use the editor you can right click into the Package Explorer and select via <b><New> <Other...></b> the <tt>Po Model</tt> wizard.
| + | |
− | <center>[[Image:SelectThePOWizard.gif]]</center>
| + | |
− | Secify a project and a file name for the new SimplePO model instance file and press <b>Next</b>
| + | |
− | <center>[[Image:SpecifiyEditorFile.gif]]</center>
| + | |
− | 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 <b>Finish</b>
| + | |
− | <center>[[Image:SpecifiyEditorFile.gif]]</center>
| + | |