Last updated on 2014-09-05
Previous Tutorial: Creating a GEF editor – Part 1: Defining the Model
The eclipse EMF framework provides tools for the creation of structured data models and the generation of code based on these models. In this tutorial we generate the model and edit code for the model we created on the previous tutorial.
Just a short reminder of the status of the project:
We have 5 EClasses (ObjectProcessDiagram, OPMThing, OPMObject, OPMProcess and OPMLink), some attributes and links between the EClasses. We are now ready for code generation, using the EMF Generator Model.
- Right click on the model directory on your project, select “New”->”Other…”. The new file wizard will open. Select the “EMF Generator Model” file kind and click “Next”:
- I will name my file “opm.genmodel” (note that the filename must end in .genmodel). Click next once again (and forgive me for not adding another screenshot).
- Now it’s time to select from where the model is loaded. An EMF Model Generator file is kind of a “decorator” for a model, which provides extra information to enable code generation of the model. Since we just created and Ecore model in the previous tutorial, we will be using it. You can also create a model using comment annotations in java interfaces (a good tutorial can be found here), which is actually how I started in the first place, but since the annotations are in the comments (and not real java annotations) you have to remember all the syntax, there is no error checking when editing, and after some playing with the Ecore model editor I got pretty used to it. So I’ll click on “Ecore model” in this screen and click “Next”:
- Since we have our model file in a project in the workspace, select “Browse Workspace” and find the Ecore model find you want. It should appear in the model URI textbox. You should be able to click on “Load” and nothing bad should happen. Click “Next” once again.
- Leave the next wizard page with no changes and click “Finish”. This page lets you select which packages to generate and reference from other generator models, but since I really don’t know what this means, and in any way we only have one package to model, just ignore.
- Voila! we have our EMF Generator Model:
Take some time to inspect it. It looks just like our Ecore model, but the properties window suddenly has a lot more lines! This is where all of the information for code generation is stored. We will be editing it a bit and also checking that the generated values are correct. Note that I am not really an expert on EMF, and if you want to understand all of the details you should probably read the EMF book.
- Lets define the properties of the Generation Model.
- Root properties: changed the Model Name to OPM which better matches the name I want to give my models.
- Package properties: changed the prefix (which provides a string prefix for some utility generated classes) to OPM.
This should be all we need for now. Right click on the root of the genmodel and select “Generate All” (there is no real need to generate all, but it is nice to use generated editor and test if the model works as expected).
- That is basically it. This is how my environment looks now:
If you want to test your model, you can run a model editor by clicking on the execute button (the green one with the white triangle). Another possibility if this does not work is to right-click on the “com.vainolo.phd.opm.model.edit” project, and select “Run As->Eclipse Application”. Create a new project: “File”->”New”->”Project” and select “General”->”Project”:
Click next and name your project as you like (I named mine “test”. Very original). Now we’ll create a new OPM model file! Right click on the project and select “New”->”Other…”. The wizard now also contains “OPM Model” as one possible option!
Click “Next” and give your model a nice name, for example “TheBestOPMModel.opm”. Click “Next”. You now have to select which model class to create as the root of your model’s hierarchy, so select the ObjectProcessDiagram, which is the container of all other EClasses in our model.
Next Tutorial: Creating a GEF Editor – Part 3: Basic GEF Editor
I am using Eclipse Indigo and have installed the EMF and GEF plug-ins. I have completed Tutorial 1 and all of Tutorial 2 except the last step of “Creating GEF Editor”. I do not get the Example EMF Model Creation Wizards as shown in the last step. Please let me know if there are any other ways of completing that step, or what is missing from my Indigo installation.
What do you mean by “Example EMF Model Creation Wizards”? Where did you stop? before or after creating your .genmodel file?
I finished step 7 (Generate All). The first item in the Package Explorer does not have * like the first screen shot of step 8. Then I created project “test”. In the tutorial you ask to Right Click on the project (I am assuming “test”) and select “New” -> “Other…” and show the New Select Wizard screen, which has the Example EMF Model Creation Wizards folder. I do not get that folder. I do not know what else to do.
The * is because my editor had uncomitted changes, so please disregard it.
After you generated all the code, did it compile? Did you run a NEW eclipse instance and created a “test” project on the new instance (and not in the eclipse instance where the editor was defined)?
I have the same problem as Girish above.
I’ve got as far as starting the new Eclipse instance but the menu New -> Other -> Example EMF Model Creation Wizards isn’t there?
I repeated the tutorial yesterday and everything worked. I am using eclipse indigo sr1 on both linux and windows.
Thanks for the good tutorials.
But the last part has some ambiguous infos.To see ‘OPM Model’ in the ‘Example EMF Model Creation Wizards’,we should run ‘com.vainolo.phd.opm.model.editor’ project first before making new general ‘test’ project.
Of course, you need to execute the project, as I wrote in the second line of the 8th step (“click on the execute button”).
Clicking on the execute button doesn’t run the editor project – Eclipse has no idea what it should be running the editor project as.
It can’t find a main type to run it as a Java Application.
Running it as an Eclipse Application fails.
This line of the tutorial definitely needs clarifying, it doesn’t look like I’m the only person who doesn’t understand what’s required.
It should work if the editor project is selected… The
com.vainolo.phd.opm.model.editproject is an eclipse plug-in project, so executing a new eclipse application should work. I added this to the tutorial. Thanks for the comments.
Did you execute the eclipse platform? The “OPM Model” will not appear in the eclipse platform on which you are executing, but on a new platform.
at the last Step, creating the new OPM Modell
after the selection of “ObjectProcessDiagram” I can’t finish the project…
Model Object is: Object Process Diagram
XML encoding is: UTF-8
when I click finish nothing happens
You should get an empty EMF editor. Nothing fancy, just what is generated automatically by the EMF generator.
I was reading this tutorial yesterday and all images display with no problem, now images doen’t display. Are there any problem in the blog?.
Wooops! I did a big update that destroyed all my site. Working on fixing this. Thanks for the heads up!
In step 8, even though I created the new “test” project in new Eclipse application, I could not find the “OPM Model” as an option. I am using Eclipse Kepler and installed GEF and EMF plugins.
Try to do things again. Last time I checked it worked as I wrote. If you do find that something in my instructions is not correct, I’ll be glad to hear about it.
FYI and for all interested or stuck at step 8.
Once you have the Eclipse Application running, you are supposed to create a new project within that newly running instance and then can create a new OPM Model in that project on that instance.
Don’t get stuck like I did.