start [GMF Samples And Tutorials]

GMF Samples and tutorials overview

Eclipse GMF is very exciting technolgy. Unfotunately, it is not very easy to understand. The tutorials that can be found about GMF on the Internet are not always detailed enough.

This project aims to give a few samples to help people interested in GMF to get into that technology with step by step examples.

As GMF is deeply coupled to EMF, you will also find a few resources about EMF.

The code can be retreived via subversion ( It is also made available through the File Manager feature of sourceforge (

⇒ If you are looking for a lightweight alternative to GMF that can be used quickly with a minimal effort you should take a look at emf2gv (EMF to Graphviz) tool :

I hope that this material will be helpful for you. If you want to support it, your help is welcome :

EMF Tutorials

GMF Tutorials

How to...

  1. Avoid node deletion/removal : see Tutorial 7 / Diagram initialization
  2. Validate the diagram and manage diagram errors (with error icons) : see Tutorial 5 / Diagram error managment
  3. Automatically change label values when the users enters or modifies data : see Tutorial 5 / Computation automatisation
  4. Automatically add nodes when diagram editor is initialized : see Tutorial 7 / Diagram initialization
  5. Set the default edge routing mode to rectilinear : see Tutorial 5 / Basic diagram generation
  6. Modify a link label position : see Tutorial 8 / Link label position
  7. Programmatically define when a label is read only or not : go here
  8. Change the default font :
    1. After having generated the diagram editor plugin, edit the DiagramAppearancePreferencePage class (in the xx.diagram.preferences package)
    2. Modify the constructor (instanciate teh font class and save in the preference store) :
	 * @generated NOT
	public DiagramAppearancePreferencePage() {
		IPreferenceStore store = BowtieDiagramEditorPlugin.getInstance()
		FontData defaultFont = new FontData("Verdana", 7, SWT.NONE);
				IPreferenceConstants.PREF_DEFAULT_FONT, defaultFont);

Troubleshoot / fixes / workarounds



Hejer, 2010/05/16 12:33

Hello, (sorry for my poor english) I'm working in an editor with GMF and i'm new on it. I have a problem that i should solve as soon as possible!!! SO, here is the situation: I have a diagram which contains an element “components” , when i double click on it, another diagram should be open in which is initialized some elements :” activities”, “roles”, …

The double click works, and when i was working on the sub-diagram only, elements are initialized without problem. But when i link between the two diagrams, elements “activites, roles”.. are not initialized when i double click !!



Jean-François Brazeau, 2010/07/07 21:12

Hello Hejer…

Can you send me your code to let me try to help you ?

I'm afraid it may be hard to help you with the informations that you provided…..


jerome, 2011/07/27 13:24

Hello, I'm using GMF and i'm trying to do the same thing. I would like, after double-clicking on an object on the diagram, to open a sub diagram? i'm searching for three weeks now, can you help me please????

Jean-François Brazeau, 2011/12/08 20:09

You should take a look at this :

Bass, 2010/05/22 12:35


 I have created a diagram, and everything is OK, 
 now, i need to display the diagram in read-only mode, 

Please let me know how to disable all edit options,

1) Editing Tool, 2) Mouse over, 3) Palette

Jean-François Brazeau, 2010/07/07 21:14

I don't know if I really understand. Do you want your diagram to be all the time in a read only mode ? Or do you want your editor to get readonly after a special event ?

Jan Gewald, 2010/12/18 20:37


I'm new to GMF and I am trying to generate my first graphical Editor with it. I created an Ecore with several classes and relationships between them. Also I was able to create an editor out of it. But now I have a palette with several links on it. well i guess its a correct behaviour because my domain model has several relationships but I want an graphical editor just with one link, representing every relationship. Can you please tell me how I can get this feature in GMF? I searched in the book from Gronback and I also read several tutorials but I cant find a clue how to get this.

I am also working with the former DSL Tools in Visual Studio and I can get this feature, to have one link for every relationship, with a connection builder. But I cant find a similiar function in GMF.

I hope you can help me.

Kind regards

Jan Gewald

Jean-François Brazeau, 2011/01/05 13:16

Hello Jan,

As far as I can see, GMF classically needs one tool in the palette per relation. It is understandable, if you have two relations between to EClasses for example, GMF should not know which relation you would like to create with a unique tool. Nevertheless, I think it is probably possible to get the result you want but you will have to customize the code by yourself.

Take a look at the createXXXXTool methods in your XXXPaletteFactory ⇒ A LinkToolEntry is instanciated with a unique relationship type. Maybe if you add other relations type, you will get the result you are expected.



Mary Cole, 2010/12/31 00:07

Hi , thank you very much for this tutorial. I want to do an editor based GMF. I want to use the Jena Framework for validation in this editor.But I'm new GMF and I don't know where to start.Do you have resources you can recommend me to read. I'll be glad if you help.

Jean-François Brazeau, 2011/01/05 13:19

Hello Mary,

I'm sorry, I have never used Jena Framework. Maybe could you find some interesting stuff here :



Hoang Tran, 2011/01/20 08:29

Dear Jean,

I'm doing a research, in which I have to create a GMF editor for a software process language named UMLPP. UMLPP uses UML2.0 heavyweight extension mechanism (It extends some UML classes ex: Classifier, Element, DirectedRelationship …). I've already create the umlpp.ecore and umlpp.genmodel. I use uml.ecore available in eclipse. When generating model code, edit code and editor code. I face with many errors. Most of them said that : I have to implement abstract operations from UML class (For example : AbstractProcessPatternImpl must implement the inherited abstract method ActivityNode.getIncoming(String, boolean, EClass) AbstractProcessPatternImpl)

I can't go on to create the gmftool, gmfgraph and gmfmap without overcome this problem. Could you please give me some suggestions to solve this? Thanks in advance and wish you sucess

Jean-François Brazeau, 2011/02/27 15:27

Hum… How strange is your problem… It seems that you have interfaces with methods that are not implemented in your implementation class. By default, EMF generates the interfaces and implementation together. Have you added custom method in the model interfaces ? Could you send me your code (with your EMF file : ecore, …).

Gandharva Kumar, 2011/02/25 12:04

Hello, I'm creating Navigation design editor for android platform in GMF. In the generated editor, I'm able to create a model diagram, a model code in XMI is automatically created. I need to create java code and XML files from the diagram instead of the automatically created XMI code. Is it possible to do that? How? Please help.

Jean-François Brazeau, 2011/02/27 15:31

If you are using the EMF tree editor, then the java code of your model has been generated (as the editor needs these classes). XMI is the persistent format used by the EMF tree editor to save the data. If you want to uses Java classes, you have to directly use the generated java classes of your model and/or load the file you've created with your editor. Maybe this page should be helpful : Hope it helps.

Mehdi, 2011/03/04 09:01


I want to create a Class Diagram palette with GFM that allow to users drawing Class Diagrams, the problem is that i can't find an Ecore metamodel of the Class Diagram alone, all that i found is an Ecore of all UML diagrams.

So how can i do to generate a Class Diagram palette with GMF based on Ecore metamodel of the class diagram ?


Jean-François Brazeau, 2011/03/18 21:13

If you want to create UML diagrams, it may be more simple to use a tool like Topcased than to build your own Class diagram editor…. Don't you think ?

Idrees Ashraf, 2011/03/13 21:14

how can i create dropdown menu for the labels of links in GMF? Thanks

Jean-François Brazeau, 2011/03/18 21:17

Sorry, I don't have the solution (I have not yet tried to do that). You will have to get into the generated code and modify it to get the special behavior you're expecting… If you find the solution, maybe you could give us a feedback : it should incorporated as a new tutorial.

Guo Fengzai, 2011/03/17 04:43

How to create a link like below?



Guo Fengzai, 2011/03/17 04:50

The link must be a whole one, and can connects three nodes.

Jean-François Brazeau, 2011/03/18 21:22

I have done something like this in the past but I am not sure that my solution is exactly the one your expecting. I simply created a node with two entries and one output. For example to get something like this :


I put a node in the middle like this :


Hope it helps….

SD, 2011/04/06 18:25

Hello, I want to create a node (n1) with an attached node (n2) in the border (half inside, half outside). Any help is well received.

By the way. Maybe creating a menu item in a node may help the purpose of @Idrees Ashraf, a reference on how to is Epsilon Wizard Language. There is also an example for showing labels in GMF links easy (endlabels example).


Jean-François Brazeau, 2011/04/19 20:09


I would personally try to create a node with nested nodes like in the fifth tutorial. In the parent node, you should try to draw a rectangle on which you would put the nested nodes (half inside of the rectangle, half outside).



Alex, 2011/05/19 20:24

Thanks for great tutorials, they are really helpful!

I created a GMF editor and model is being saved as XMI, how can save it to XML? Using EMF API for my model it's fairly easy, but what about GMF? I couldn't find anywhere where I can switch from XMI factory to XML one.

Thanks! Alex

Jean-François Brazeau, 2011/05/24 20:09


I am not sure to understand…. In fact, XMI is based on XML… XMI is XML ! Doesn't it suit your need ? You want to personalize the XML format taht is used when EMF persists the data ?


Alex, 2011/05/25 14:26

Meant to reply to your comment…

Sorry, what I mean was that is there anyway to avoid xmi code in model? May be what you mentioned with personalization of XML? Perhaps people are creating another model that is only emf model (personalized) that is subset of generated gmf models? I am starting out with gmf, so sorry if I am asking wrong questions.

Alex, 2011/05/25 14:25

Sorry, what I mean was that is there anyway to avoid xmi code in model? May be what you mentioned with personalization of XML? Perhaps people are creating another model that is only emf model (personalized) that is subset of generated gmf models? I am starting out with gmf, so sorry if I am asking wrong questions.

Jean-François Brazeau, 2011/06/15 18:39

When you say “the model”, are you talking about the generated java model code ? (I mean the EMF model, not the GMF models)


Lewis, 2011/05/29 21:51


First of all, i want to say thanks for these helpful tutorial. well, i'm working on a diagram editor but I've a problem with the initial position of nodes which i must solve as soon as possible.

When i create a node programmatically, it'll be positioned, by default, in the top left corner of the canvas.

my question is, how can i change/set the initial position of a node when created?

Many thanks,


Jean-François Brazeau, 2011/09/01 19:26


To change the position of a created node in the diagram, you have to edit the XXXXContainerCanonicalEditPolicy and override the getCreateViewRequest method like this :

 * @generated NOT
protected CreateViewRequest getCreateViewRequest(List<ViewDescriptor> descriptors ) {
	CreateViewRequest req =  new CreateViewRequest( descriptors );
	req.setLocation(new Point(300, 400)); // Put the location you are expecting here
	req.setSize(new Dimension(200, 200)); // And the figure's size
	return req;

Hope it helps.



Tommy Sadiq Hinrichsen, 2012/05/07 13:14

Hey Lewis

Im also trying to create new nodes programmatically, could i ask how you are doing it

Add to Eclipsepedia?, 2011/07/11 14:54

what do you think to add your tutorials here: ? I think they will be very happy and you could even help more people.

Jean-François Brazeau, 2011/07/19 19:46

Great idea ! Feel free to suggest it to eclipsepedia !!!!!! :)

Mohammad, 2011/07/19 11:21


I wanted to know if it is possible to have labels out of edit parts area.

Thanks for your helpful tutorials.

Jean-François Brazeau, 2011/07/19 19:49


According to me, the only simple way to get a label outside of an edit part area is possible to attach it to a label… But it is maybe not what you want to do. Another solution is to handle a bigger area in which you put your label and a shape. That way, the label may “seem to be” outside of the shape.



Sony, 2011/07/20 00:52

Bonsoir, je suis en cours de faire mon premier éditeur graphique, j'ai reconnu un problème que je doit le résoudre le plus tôt possible, ce problème est au niveau du fichier gmfmap, “containment EReference expected” j'ai pas arrivé à comprendre ce problème, ni le résoudre;

Merci de m'avoir aider Cordialement

Jean-François Brazeau, 2011/08/31 09:23

Bonjour, Cette erreur vous indique simplement que vous avez omis de sélectionner une référence de type conteneur quelque part !!!!! Probablement au niveau d'un “compartment”… Quelque chose du genre. JF

pavithra de alwis, 2011/08/29 03:13

I'm developing an editor to design user Interfaces based on eclipse GMF.Up to now I have developed an editor with a palette. The user can drag and drop UI elements from pallet and design the UI on canvas.

I need to implement the facility to group these UI elements. EX: User first design the UI by dragging and dropping elements to the canvas.Then he select a set of UI elements (say a label and text box) and press “group” button. It will automatically put the elements within a dashed line rectangle.

I'm planning to develop a plugin that can get info about selected ui elements, delete them, create a group element (dashed line rectangular) in canvas and insert deleted elements to it.

But i don't know where to start.So, I want to know how to create/delete nodes programmatically in GMF. Any help is highly appreciated as our project deadline is coming near.

regards, pavithra

Jean-François Brazeau, 2011/08/31 09:26

Hello, I think that the answer to your question is presented in the 5th tutorial here : basic_diagram_generation. You have to modify the code in the commands that create your model objects. Regards, JFB

Kieara Belle, 2011/09/08 11:59


I have been given a project to model a transactional language and allow the User to develop a process from the same in a Graphical Editor. I have done this, in GMF and the user can draw (make) the diagrams in the editor. The next task is to incorporate the semantic rules of the language (like structural congruence and reduction relations) and then based on these rules I am supposed to make a functionality that gives user an option to 'Transform' a particular diagram into a resulting diagram.

For example : if there are 2 processes in an editor diagram (made by the user), one of them Process Q is a SUCCESS and other is a normal process and both are in sequence i.e (Process P followed by another Process Q(which is a SUCCESS) ) then the result of this should be another editor diagram that shows only Process P. (as this is how the language rules defines such a sequence)

The doubts I have are :

1) How do I read the editor diagram in a file/code in order to generate the other editor diagram ? 2) Which files or codes (generated by GMF genmodel / EMF genmodel ) am I supposed to write all this code in ? 3) What structure should I follow ? 4) How do I add the functionality 'Transform' on the context Menu in the Eclipse instance (or the Editor window) ?

Also, I have a node T with 3 compartments, I want that when I click on the compartment, a new diagram editor should open up and allow me to add the same type of components. (i.e the meta-model, gmfgraph, gmfmap, gmftools will be the same ). In simpler terms, the compartments should contain a diagram. Also is it possible to add the diagram within that compartment rather than opening a new editor (Eclipse Instance)?

Thanks Kieara

Jean-François Brazeau, 2011/12/06 20:30


Sorry for the delay.

1. You should probably have to take a look at M2M transformation tools ( Or you can code it manually by opening the source domain model, generating the target model, save it to a new file and open an diagram editor on top of the resulting model… (I don't know if you need all this to be automatized)

2, 3, 4. I think you must add a custom action to your editor or simply to eclipse itself that is enabled for the right resources in the navigator tree (use the org.eclipse.ui.popupMenus extension point). You write your code in the action delegate.



Gopi, 2011/09/08 13:54

I am creating right click context menu for every Component. I want to get instances of every component.I mean if i drag rectangular three times then i get different xmi:id=“some numbers” for every instance of component.Can you please tell me that how can i fetch this id programmatic or Can you please explain that how to handle right click selection event so that i get unique id of my every component instances. Thanks in advance

Jean-François Brazeau, 2011/12/06 20:36

Right click event is maybe not the good approach. I would try to use a custom editor action (see the org.eclipse.ui.popupMenus eclipse extension point).

milon, 2011/11/25 03:17

hi, I have made a editor. Suppose i create two nodes and make a connection between them. after that when i again create a node the previous connection just disappear. What should i do???

Jean-François Brazeau, 2011/12/06 20:32

Hum…. Are you sure you've didn't customize a little bit the GMF generated code…. and that you didn't introduced… a bug ???!!! :) If I were you, I would restart from the generated code without modification to check the default behaviour.

Adalberto Junior, 2012/01/12 17:09

Hi, I have made a editor and now I need that it when drag n drop a node (A) within another node (B), the node B get some properties about node A. But I don't have idea that how start this? You can help me?

Jean-François Brazeau, 2012/02/11 20:19

Maybe should you try to listen to model change events. When A is dropped in B, the A semantic object is added to a containment reference of B. If you listen to this change, you may trigger your specific code.

Adalberto Junior, 2012/01/21 17:16

My problem is:

I have a model that some nodes can have references to another nodes, for example, a ComponentA have one reference to InterfaceA.

My editor permit that I manually set the references selecting them in properties view, but I want to get this references when I drag n drop the referenced node on actual node, for example, when I drag n drop the InterfaceA to ComponentA my component get the interface reference but the interface dont change its position.

My question is how can get references on drag n drop?

Jean-François Brazeau, 2012/02/11 20:21

GMF naturally handles references through edges (I think that this is in fact more a GMF tooling limitation than a GMF runtime limitation). If you drag'n'drop a component into another, it is more classically in a containment reference case. Why don't you use a simple edge for your need ?

Sudipta Dey, 2012/02/15 08:39

hello… i am trying to develop an editor.. i tried to implement inheritance in my ecore diagram..but it gave some errors.. can you tell me how to implemet inheritance in ecore diagram? whats the procedure? thnaks for your help…

Jean-François Brazeau, 2012/04/02 06:20

You simply have to connect your EClasses through an inheritance edge

Oscar Castro, 2012/02/27 17:50

Hello, i have several nodes that inherit from one abstract node, i want to have a full description of the nodes that are available in the diagram, i'm looking for a way to put this description, could it be to add an extra property (ex: description property) or maybe the javadoc description of the class. How can i achieve this?

Thanks for your help

Jean-François Brazeau, 2012/04/02 06:21

Do you want to add a description on you meta-model or do you want to add a possibility to enter a description of the nodes that appears in you diagram ?

eni, 2012/04/02 19:57

Hello, I haven't found a good tutorial on how to add mouse listeners on figures etc. Could you please explain briefly which method should i redefine and what are the steps to achieve something like this.

ThanksBold Text

Sarath, 2012/05/22 10:28


I have followed the tutorial in the following link to create GMF editor

Iam facing following error. I have 3 objects in my Palette - Application,Entity,Relation.

1. Drag to entities onto the editor 2. Try to make relation from source entity to target entity. 3. Result is Target entity is removed from editor and no connection is shown

Thanks for your help


Sarath, 2012/05/25 07:33

Found the solution..Relation object in my palette is connection represented by Entity related to other Entity…..

So Entity should have reference to Entity….In the ecore file i have specified this reference as containment(true). This is the cause of problem…After resetting it everything worked fine.

Almamy, 2012/05/29 08:00

Hi everybody, I'm working with GMF to create a graphic editor. My problem is that I have two classes, A and B linked by an association. When I launch the application, I want to see the properties of the linked class in the property view. Does anybody know how to do this ? PS : Thanks and excuse my bad english, actually I'm french

Sarath, 2012/05/31 11:40

Hi everyone,

I have Few Nodes defined and placed in the Palette. Each Node has an attribute “Name”

which can be set in the property sheet.

I have a rule that in the diagram there shouldn't be multiple Nodes with same “Name”. I have to check this validation that “Name” is not same for any 2 Nodes.

I couldn't find a place in the GMF generated code to set the validator. Can someone help me on this. In the PropertySection code i have set descriptor as EMFCompositeSourcePropertyDescriptor and set validator on that but “isValid” method is not invoked when i change value in the property sheet

Thanks for your help



michael, 2012/06/26 18:00


These tutorials are great even (if i haven't read all of them(lack of time)). Thank you! I am trying to do something simple I think, but i can't make it work. I want to change the style of the label in a node. For example bold, italic or font. I am trying to do this bu modifying the createContents method of the NodeFigure class. I use the semantic element from my model to ckeck some values and after that de[ending on the values i want to change the label. I 've used these lines fFigureNodeLabelFigure.setTextUnderline(true); fFigureNodeLabelFigure.setFont(new Font(Display.getCurrent(), “Tahoma”, 24 , SWT.ITALIC)); I thought it was simple but… Do you have any suggestions?

Thank you in advance.

michael, 2012/06/27 14:34

I found the solution here. :)

michael, 2012/06/29 10:42


I am trying to change the colour of the links. The code I am using LinkEditPart.createConnectionFigure() is:

polyLine.setForegroundColor(new Color(Display.getCurrent(), lineForgrColor.getRed(), lineForgrColor.getGreen(), lineForgrColor.getBlue()));

Do you have any suggestions?

Thank you in advance.

Mayerli Romero, 2012/07/11 04:59

Thanks for do this page, was very usefull. Thank You very much! :)

michael, 2012/07/11 17:12


It's me again. Probably I will not take an answer, but i will try. I want to implement the multiple diagram concept. What I mean is that I want to have in my editor multi - sheets, the same metamodel is used. Do you have any suggestions? From where to start? Please help!!!

Thank you!

Crush Mach, 2012/09/20 10:41

Hi, thx for the tutorial it was very helpful.

But I am stuck ! I have to create a wizard that contains a button. When I click on it, it should open the generated GMF editor . My problem is that I don't really understand the generated code that I can use it. Any help?

dorina, 2013/01/11 20:13


I am working with GEF(Graphical Editing Framework). I have a create a tree and i want to transform it in XML? Can you help me please what kind of plug-in can I use? I need the XML format because i want to work with OWL-S later…

Fjona, 2013/01/11 20:25

Please can anyone help. I have to work on Graphical Editing Framework. And i have to implement something to show the ontological matching of signatures.

Pleaseeeee…. Best Regards Fjona

Zoey, 2013/05/26 01:34

Hi, could we find a approach to read the files defined in this system. What should we do?

lee8400, 2013/10/14 17:54

hello, I am starting GMF.I want to use GMF to make a database editor tool .But I dont known who to do .can you help me ? thank you!

sad , 2013/10/14 17:55

hello, I am starting GMF.I want to use GMF to make a database editor tool .But I dont known who to do .can you help me ? thank you!

javs002, 2013/10/20 04:46

hi anyone know how to change the stereotype of a node in the GMF editor Thanks??

Enter your comment
start.txt · Last modified: 2011/12/07 21:05 by jfbraz
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki