Friday, January 23, 2009

How to embed GMF into a multipage editor?

Today I have been looking through our blog archive and I have found a draf of a post about embedding GMF into a mulitpage editor. I was very surprised as the post was completed, so I wonder why I hadn't published it back then.
So here it is without any changes (better late then never):

Recently I had to find a way to embed GMF into a multipage editor. I had the experience with GMF, but I didn't know how to create a multipage editor, however, it went pretty easy and straightforward. For this short tutorial I will use the multipage editor example described here and the GMF MindMap example (you can check out the source code from the CVS). What we want to achieve it to embed the GMF editor into the first page of the exemplary multipage editor. If you follow the steps below you should get the desired result.
  • In org.eclipse.ui.examples.multipageeditor project find MultiPageEditorExample class and copy it to the org.eclipse.gmf.examples.mindmap.diagram.part package of org.eclipse.gmf.examples.mindmap.diagram project. There will be some error, but we will take care of them later on.
  • In MultiPageEditorExample you will find field private TextEditor editor; change it's type to MindmapDiagramEditor which is the class of GMF editor. Also in the method MultiPageEditorExample#createPage0 change the constructor call for the field editor.
  • Let's look now at the errors - they are mostly connected to MessageUtil class, which we simply don't have in our GMF project, however, we need some strings to pass them to the methods - we can put there any string we find appropriate (and later of course we can externalise those strings).
  • Now there should be only one error left. To get rid of it we can just comment out the method MultiPageEditorExample#sortWords and every call of this method.
  • For this moment we shouldn't see any errors in out diagram project. Now we have to change the editor class that is defined in the plugin.xml of org.eclipse.gmf.examples.mindmap.diagram project. Open the file, go to the Extensions tab, go to org.eclipse.ui.editors and there you should find one entry with the editor definition. Change the class attribute to point to our multipage editor (class MultiPageEditorExample).
  • Here it is! You should see the editor semillar to the one on the screenshot below:
    I know that this is the dirty way, but if you need to do this fast, or you don't know how to start then I guess this can be a good starting point.

3 comments:

Seweryn Niemiec said...

It's good to know that someone in Poznań works with GMF. I didn't seen you on modeling.gmf news group.

Jakub Jurkiewicz said...

From time to time I have a look at the GMF newsgroup, but usually I just observe what's happening.

Anonymous said...

iam new to eclipse
basically my requirement is to draw various figures using basic shapes on a JPanel.

Those are a bit complicated shapes and needs to be edited frequently..so drawing it from code is not possible
and i have to place a few controls like textbox on those figures drawn.

So is this possible with GMF?

If yes Before i go in for it could you please tell me how its possible?

else please suggest me something that satisfies my requirement.

Thanks a bunch