gmf_tutorial2 [GMF Samples And Tutorials]
 

Overview

In this tutorial we will illustrate the compartment feature of GMF.

This tutorial is based on the model built in the first tutorial.

The model files can be downloaded from this location.

Full code is availabale through :

This tutorial has been built with :

  • Eclipse 3.5.1
  • Graphical Modeling Framework SDK 2.2.1
  • Eclipse Modeling Framework 2.5.0

Known bugs and fixes :

  • This tutorial doesn't show how to avoid compartment deletion : see this page to see how to fix it

Ecore Model modification

In order to use the compartment feature, the ecore model has to evolve ; the Folder associations must be turned into agregations :

  • Open the filesystem.ecore file
  • In the Folder EClass, select the folders attribute.
  • In the property view, set the Containment property to true.
  • Repeat this operation with the files attribute of the Folder EClass.

  • Regenerate the model and the EMF editor with these steps :
    • Open the filesystem.genmodel file
    • On the root item, right click and select Generate Model Code
    • Right click again on the root and select Generate Edit Code.
    • Right click again on the root and select Generate Editor Code.

The new model diagram becomes like this :

GMF Tool model modification

The two links creation tools become unusefull. We have to delete it.

  • Open the filesystem.gmftool file
  • Delete the nodes Create new FolderFolders and Create new FolderFiles
  • Save the file

GMF Graph model modification

The two Connection become unusefull. We have to delete it.

  • Open the filesystem.gmfgraph file
  • Delete the nodes :
    • Connection FolderFolders
    • Connection FolderFiles
    • Polyline decoration FolderFoldersTargetDecoration
    • Polyline decoration FolderFilesTargetDecoration
    • Figure Descriptor FolderFoldersFigure
    • Figure Descriptor FolderFilesFigure
  • Under the Rectangle Folder Figure node add a Rectangle child node ; this will be the graphical representation our compartment.
  • In the property view, set this rectangle's name to FolderCompartmentFigure
  • Under the Figure Descriptor FolderFigure, add a Child Access child node.
  • Select this child access node and in the property view, select the Rectangle FolderCompartmentFigure for the figure property
  • Under the Canvas filesystem node, add a Compartment child node.
  • Select this node and fix its properties :
    • Accessor = Child Access getFigureFolderCompartmentFigure
    • Collapsible = true
    • Figure = Figure Descriptor FolderFigure
    • Name = FolderCompartment
    • Needs title = false
  • Under the Rectangle Folder Figure node :
    • Delete the Flow Layout false node
    • Delete the Background lightGray node
    • Add a new Border Layout child node
  • Under the Label FolderNameFigure node :
    • Add a Boder Layout Data
    • Select this node and set its properties in tehe property view :
      • Alignment = BEGINNING
      • Vertical = true
  • Under the Rectangle FolderCompartmentFigure node :
    • Add a Boder Layout Data
    • Select this node and set its properties in tehe property view :
      • Alignment = CENTER
      • Vertical = true
  • Save the file

Mapping model modification

The two Linksbecome unusefull. We will delete it.

  • Open the filesystem.gmfmap file
  • Delete the two Link Mapping nodes
  • Under the Node Mapping <Folder/Folder> node, add two Child Reference child nodes.
  • For the first Child Reference, set the properties like this :
    • Containment Feature = Folder.folders:Folder
    • Referenced Child = Node Mapping <Folder/Folder>
  • For the second Child Reference, set the properties like this :
    • Containment Feature = Folder.files:File
    • Referenced Child = Node Mapping <File/File>
  • Under the Node Mapping <Folder/Folder> node, add aCompartment Mapping child node.
  • Select this node and set its properties like this :
    • For the property Children, select both Child reference <folders:Folder/Folder> and Child reference <files:File/File>
    • Compartment = Compartment FolderCompartment (FolderFigure)

Diagram Editor Generation

  • Delete the filesystem.gmfgen file
  • Click on the label Transform of the dashboard ; this will recreate the filesystem.gmfgen file
  • Open the filesystem.gmfgen file
  • Select the Gen Compartment FolderFolderCompartmentEditPart node.
  • Check that the List Layout property is set to false (set it to false if not).
  • Do the same with the Gen Compartment FolderFolderCompartment2EditPart node
  • Delete the project Filesystem.diagram (delete also project contents on disk) or at least delete the sources of this project (src folder content)
  • Generate the diagram by clicking on the Generate diagram editor in the dashboard.

Run and test

  • Run the eclipse configuration that had been created in the first tutorial.
  • Create a new diagram as in the first tutorial.
  • And this is the result…

Model files

You can get the filesystem model files described in this tutorial following this link : gmf-tutorial2-filesystem-model.zip

Thank you

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

Discussion

Judah Mu, 2010/06/30 04:16

Pixies!

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

Bingo !

Thierry Templier, 2010/07/29 14:32

Hello,

Thanks very much for these really interesting and useful tutorials!

I have a question regarding compartments. I'm trying to use compartments and I adapted what you have done. The problem is that elements within my compartment can't be resized and selected. However, when I click on an element, the properties view is filled with the corresponding data. Any idea to diagnose and solve this problem?

Thanks very much by advance for your help! Thierry

Jean-François Brazeau, 2010/08/01 16:27

Hi,

Check the List layout property corresponding to your compartment in the gmfgen file. It is probably set to true.

JFB

Thierry Templier, 2010/08/03 07:53

Hello Jean-François,

It was exactly that! Thanks very much for your help and those great tutorials!

Thierry

Jean-François Brazeau, 2010/09/18 13:22

Nice to see that these tutorials help some people in the world !…

YR, 2010/10/07 14:05

Bonjour Jean-François,

Merci pour ces tutoriaux. ça m'aide à bien avancer sur mon projet. J'ai une petite question et j'espère que vous pourrez m'aider: J'ai un metamodèle qui ressemble un peu au votre sauf que dans le mien j'ai enlevé la relation containmenent entre File et FileSystem. J'ai fait ça pour que l'utilisateur ne puisse pas ajouter des File ailleurs que dans un Folder. Mais j'ai l'erreur suivante: “Top level node 'Containment Feature' must be available in the diagram 'Domain Element' or its super-class”.

Est-ce que c'est faux de faire comme je le fais? Comment je pourrais exprimer la contrainte autrement?

Merci beaucoup

Jean-François Brazeau, 2010/10/13 18:57

Bonjour,

Je pense que pour parvenir à vos fins, il faut au préalable supprimer la relation entre l'EClass Filesystem et l'EClass File dans le fichier ecore. Dans le fichier gmfmap, le 'Node Mapping <File/File>' doit être déplacé vers le 'Child Reference <files:File/File>', vider la propriété 'Referenced Child' de ce dernier noeud, puis supprimer le noeud 'Top Node Reference <files:File/File>' (en clair la description des fichiers ne peut plus exister que dans les Folders). Après regénération du tout, je pense que vous devriez obtenir le fonctionnement attendu.

Bon courage,

JFB

YR, 2010/10/14 14:05

Excellent. Merci beaucoup pour votre réponse, effectivement en faisant comme ça j'ai le comportement attendu. Merci encore une fois.

HoangTK, 2010/11/26 15:48

Great tutorial, I met this error while Generate diagram editor : “Problems while generating code Can't organize imports due to syntax errors in the compilation unit FolderEditPart.java Can't organize imports due to syntax errors in the compilation unit Folder2EditPart.java” I missed some steps or did I do something wrong ? Thanks in advance.

HoangTK, 2010/11/26 16:00

Solved this, I discovered under Figure Descriptor FolderFigure a child node name : ChildAccess getFigureFolderNull. Removed this node, and vola …

Greg Jansen, 2011/07/26 21:03

Hey, Your tutorial was useful and resembles my own project, which involved nested objects that represent XML elements. My problem is with the palette. when I select my equivalent of “Folder” in the palette (in my case this is the Element tool) and click on the canvas or another Folder, I see two drop-down choices instead of one.. One choices only works on the Canvas and the other only works in a nested context, within other folders.

Did you see this behavior and do you know where to look for a fix?

many thanks, Greg

Greg Jansen, 2011/08/19 17:49

Hey, the answer to my problem is documented on the GMF forum now: http://www.eclipse.org/forums/index.php/t/222580/

Stephane Ben, 2011/11/08 15:32

Hello, i have one question. After doing this, i can't see the children of the container in the outline view. is it normal ? how can i change this ?

Thank you.

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

Hello,

I've just checked it with an indigo eclipse distribution. I perfectly see the children of the container in the outline view… You may try to checkout the code from svn to check it again : https://gmfsamples.svn.sourceforge.net/svnroot/gmfsamples/Filesystem/tags/tuto2-final-diagram/

Regards,

JFB

Srini, 2011/11/13 17:46

Really a great tutorial (very helpful towards moving from beginner to expert). Waiting for more tutorials on GMF.

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

Thanks a lot !

Faraari, 2012/05/13 18:36

Hi,

thx for the greate tutorial. I have just a problem, if I add a file to a folder, the figure becomes duplicated?

Can you help me with this problem?

Thx Faraari :)

Faraari, 2012/05/13 19:48

okay seems to be a bug im 2.3: https://bugs.eclipse.org/bugs/show_bug.cgi?id=318585

bandyt, 2012/07/03 11:46

Hello,

Thanks for this nice tutorial!

Fechal Bat, 2012/11/02 18:30

Hello,

please,i would like the code to export the diagram to xml file.

Thanks in advance.

 
gmf_tutorial2.txt · Last modified: 2011/08/08 20:06 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