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 :
Known bugs and fixes :
In order to use the compartment feature, the ecore model has to evolve ; the Folder
associations must be turned into agregations
:
filesystem.ecore
fileFolder
EClass, select the folders attribute
.Containment
property to true
.files
attribute of the Folder
EClass.filesystem.genmodel
fileThe new model diagram becomes like this :
The two links creation tools become unusefull. We have to delete it.
filesystem.gmftool
fileCreate new FolderFolders
and Create new FolderFiles
The two Connection become unusefull. We have to delete it.
filesystem.gmfgraph
fileConnection FolderFolders
Connection FolderFiles
Polyline decoration FolderFoldersTargetDecoration
Polyline decoration FolderFilesTargetDecoration
Figure Descriptor FolderFoldersFigure
Figure Descriptor FolderFilesFigure
Rectangle Folder Figure
node add a Rectangle
child node ; this will be the graphical representation our compartment.FolderCompartmentFigure
Figure Descriptor FolderFigure
, add a Child Access
child node.Rectangle FolderCompartmentFigure
for the figure propertyCanvas filesystem
node, add a Compartment
child node.Accessor
= Child Access getFigureFolderCompartmentFigure
Collapsible
= true
Figure
= Figure Descriptor FolderFigure
Name
= FolderCompartment
Needs title
= false
Rectangle Folder Figure
node :Flow Layout false
nodeBackground lightGray
nodeBorder Layout
child nodeLabel FolderNameFigure
node :Boder Layout Data
Alignment
= BEGINNING
Vertical
= true
Rectangle FolderCompartmentFigure
node :Boder Layout Data
Alignment
= CENTER
Vertical
= true
The two Linksbecome unusefull. We will delete it.
filesystem.gmfmap
fileLink Mapping
nodesNode Mapping <Folder/Folder>
node, add two Child Reference
child nodes.Child Reference
, set the properties like this :Containment Feature
= Folder.folders:Folder
Referenced Child
= Node Mapping <Folder/Folder>
Child Reference
, set the properties like this :Containment Feature
= Folder.files:File
Referenced Child
= Node Mapping <File/File>
Node Mapping <Folder/Folder>
node, add aCompartment Mapping
child node.Children
, select both Child reference <folders:Folder/Folder>
and Child reference <files:File/File>
Compartment
= Compartment FolderCompartment (FolderFigure)
filesystem.gmfgen
filefilesystem.gmfgen
filefilesystem.gmfgen
fileGen Compartment FolderFolderCompartmentEditPart
node.List Layout
property is set to false (set it to false if not).Gen Compartment FolderFolderCompartment2EditPart
nodeFilesystem.diagram
(delete also project contents on disk) or at least delete the sources of this project (src
folder content)Generate diagram editor
in the dashboard.You can get the filesystem model files described in this tutorial following this link : gmf-tutorial2-filesystem-model.zip
I hope that this material will be helpful for you. If you want to support it, your help is welcome :
Discussion
Pixies!
Bingo !
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
Hi,
Check the
List layout
property corresponding to your compartment in the gmfgen file. It is probably set to true.JFB
Hello Jean-François,
It was exactly that! Thanks very much for your help and those great tutorials!
Thierry
Nice to see that these tutorials help some people in the world !…
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
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
Excellent. Merci beaucoup pour votre réponse, effectivement en faisant comme ça j'ai le comportement attendu. Merci encore une fois.
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.
Solved this, I discovered under Figure Descriptor FolderFigure a child node name : ChildAccess getFigureFolderNull. Removed this node, and vola …
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
Hey, the answer to my problem is documented on the GMF forum now: http://www.eclipse.org/forums/index.php/t/222580/
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.
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
Really a great tutorial (very helpful towards moving from beginner to expert). Waiting for more tutorials on GMF.
Thanks a lot !
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 :)
okay seems to be a bug im 2.3: https://bugs.eclipse.org/bugs/show_bug.cgi?id=318585
Hello,
Thanks for this nice tutorial!
Hello,
please,i would like the code to export the diagram to xml file.
Thanks in advance.