In this tutorial we will build a simple editor allowing to create folders and files.
Full code is availabale through :
This tutorial has been built with :
In this section, we will create a new model via annotated interfaces (cf. Model creation via annotated interfaces for more information).
Filesystem
jfb.examples.gmf.filesystem
Filesystem
:package jfb.examples.gmf.filesystem; import java.util.List; /** * @model */ public interface Filesystem { /** * @model containment="true" */ List<Folder> getFolders(); /** * @model containment="true" */ List<File> getFiles(); }
Folder
:package jfb.examples.gmf.filesystem; import java.util.List; /** * @model */ public interface Folder { /** * @model */ String getName(); /** * @model */ List<Folder> getFolders(); /** * @model */ List<File> getFiles(); }
File
:package jfb.examples.gmf.filesystem; /** * @model */ public interface File { /** * @model */ String getName(); }
New > Other
, select EMF Generator Model
, and click Next
model
folder and type the file name : model.genmodel
, and click Next
Annotated java
, and click Next
Finished
Initialize ecore_diagram diagram file
) :filesystem.genmodel
Generate Model Code
; This will generate two new packages and override the model interfaces initially created :META-INF/MANIFEST.MF
, go to the Runtime
tab and check that the 3 packages are present in the exported packages
list :GMF comes with a dashboard view that helps to generate severals files required to build your diagram editor.
To show this view, use the menu Window > Show views > Other
and select GMF Dashboard
in the General
node.
Domain Gen Model
of the dashboard, click on select
and choose the file filesystem.genmodel
.Domain Model
of the dashboard, click on select
and choose the file filesystem.ecore
.This step allows to define the tools that will be present in the palette of the editor.
In our example, we want :
These are the steps to follow to accomplish this :
Derive
label which is on the left of the Tooling Def Model
rectangle.filesystem.gmftool
in the folder model
:Filesystem
and click Next
:File
and Folder
are checked in the nodes column, and that the folders
and files
associations are checked in the connections column and the click Finish
:filesystem.gmftool
should be generated :With this model we will get a tool palette in the diagram editor like this :
This step allows to define the graphical items to use to represent our model in the diagram.
These are the steps to follow to accomplish this :
Derive
label which is on the left of the Graphical Def Model
rectangle.filesystem.gmfgraph
in the folder model
:Filesystem
and click Next
:File
and Folder
are checked in the nodes column ; Check that the folders
and files
associations are checked in the connections column ; Check also that the file's name
and the folder's name
are checked in the labels column and then click Finish
:filesystem.gmfgraph
should be generated :Rectangle FolderFigure
, add a child Background Color Constant Color
; select it and choose lightGray
in the properties view (this will allow to distinguish the folder nodes from the file nodes) :The mapping definition model allows to bind the three models (domain / graphical definition / tooling definition).
These are the steps to follow to accomplish this :
Combine
labelfilesystem.gmfmap
in the folder model
:Filesystem
and click Next
:Next
:Next
:Finish
:filesystem.gmfmap
should be generated :<Folder/Folder>
node mapping and in the property view correct if necessary :Diagram Node
= Node Folder (FolderFigure)
Tool
= Creation Tool Folder
<File/File>
node :Diagram Node
= Node File (FileFigure)
Tool
= Creation Tool File
<{Folder.files:File}/FolderFolders>
link:Diagram Node
= Connection FolderFiles
Tool
= Creation Tool FolderFiles
<{Folder.folders:Folder}/FolderFolders>
link:Diagram Node
= Connection FolderFolders
Tool
= Creation Tool FolderFolders
Befor generating the editor, we have to generate the last model : the Diagram Editor Gen Model.
To create it, click on the label Transform
of the dashboard.
A file named filesystem.genmodel should be generated :
At this point it possible to modify the general behavior of the editor :
Now it is time to generate the diagram by clicking on the Generate diagram editor
in the dashboard.
After a few seconds, the diagram editor is generated :
At this point you should have four projects :
Now that the editor have been generated, it is possible to run it.
Run > Run configurations…
Eclipse Application
configuration, call it filesystem app
Plugin
configuration tabplugins selected below only
for the Launch with
fieldTarget Platform
Filesystem.diagram
plugin checkboxFilesystem.editor
plugin checkboxAdd Required Plugins
buttonRun
Filesystem diagram
:You can get the filesystem model files described in this tutorial following this link : gmf-tutorial1-filesystem-model.zip
I hope that this material will be helpful for you. If you want to support it, your help is welcome :
Discussion
Thank you very much for your great tutorial, it really helped me.
I have 2 problems: I cannot view the diagram (class diagram) with (FileSystem, File, Folder) and I cannot view the last important diagram: default.filesystem_diagram. Also I want to ask, how the data in the last diagram appeared, do I edit them or there is something else that I should do?
Thank you very much again.
Hum… Could you be more precise ? Can you tell which section of this tutorial is problematic for you ? Did you follow every step ?
JFB
Bonjour,
Pour voir le diagramme de classes vous pouvez cliquer sur filesystem.ecore avec bouton droit ensuite initialize ecore_diagram diagram file vous aurez ainsi un fichier filesystem.ecorediag.
Thank you very much, it worked with me.
Tout à fait ! A l'époque de la rédaction de ce tutoriel je ne connaissais pas cette fonctionnalité ! C'est à présent corrigé.
Great turorial!!!!
Hi During the generation of the generator model I am getting “Errors while creating generator model java.lang.NullPointerException”. I have tried a lot of times rectifying this error. Kindly help me clearing this error.
Hum… It looks like a GMF's bug… Maybe you should try to update your eclipse environment ?
Hi… Are you sure this is a GMF's bug??? because I updated my GMF in Juno again, but my problem do not resolve! I am using Version 3.0.2 of GMF
I really like your tutorial: very clear and simple.
I am discovering GMF and I dont know exactly what it may offer. I have 3 questions.
- Is it possible to load a file that contains (in the case of this tutorial) a description of files and folders? If yes, what should be the to-be-loaded file's extention?
- Can I generate an image (.jpg for example) from a diagram I drew?
- I want to draw a diagram then associate some actions when I select a node (in our case a folder or a file). Can GMF (in general) offer that?
Hope you will be able to answer me as soon as you can. Thanks in advance ^^
Hi, In this example, the model file and the diagram file are mixed. It is possible to separate them, you just have to set not the
Same File for Diagram
property to true. It is possible to generate an JPG file (or PNG, …) by right clicking in the background of you diagram editor and selectingFile > Save As Image File
. I think it is possible to add a special behaviour in your diagram editor when nodes are selected but I never did it. You will maybe have to use selection listeners to handle such events. Regards, JFBThanks a lot for this tutorial, dude.
Apparently, all the Eclipse tutorials are messed up since GMF went inside GMP.
So I finally found yours, which works fine on Eclipse Helios.
Congratulations for these tutorials.
I need help creating GMF node element with another element in the border, but without using templates.
Can you help me please?
Thanks in advance.
Maybe could you take a look at the
Affixed Parent Side
property (gmfgraph) ?Hello
At the mapping model step I don’t have nodes and links
Any help please
Have you tried to replay the tutorial step by step ?
Hi, it is a nice tutorial. but i am having some problem. Finally when u run the diagram u said,
“When the new window is opened, create a new projet, and a new file of type Filesystem diagram”
It means i have to create a project then create the diagram file. that is, the diagram should be under the project. with out creating the project i cannot create the diagram. is it rit?
my problem is, with out creating the project i can create the diagram and the diagram file is in a defalut location(c:\user\iqbal). ans also the icon color is diffrent.in ur tutorial the icon beside filesystem diagram is green, but for my case it is violate. is there any significant meaning of this?
thank you
Hello,
You are right, you must first create the project and then the diagram file. The icon does not matter so much, you are also right !
Regards,
JFB
nice tutorial..thankks alott
I like your tutorial: very clear and simple example.
I have 1 problem: After creation of filesystem.gmfmap when I am trying to select NodeMapping <Folder/Folder> or anything in gmfmap. I am getting popup message. Problem Occurred with following error message while creating label mapping from the graphical definition.
java.lang.NoSuchMethodError org.eclipse.gmf.mappings.GMFMapFactory.createExpressionLabelMapping()Lorg/eclipse/gmf/mappings/ExpressionLabelMapping;
Which version of eclipse and GMF do you use ?
thanks for this tutot…very good
i am working with eclipse INDIGO, i am not able to view the link “initialize ecore_diagram diagram file ” by clicking my .ecore file.. do i need other plugins?
thanks and regards
Maybe do you have “Initialize Ecore Diagram File” instead ? (it is the same) Or maybe you haven't installed GMF Tooling (it is available from market place).
Amazing tutorial!. Thanks for your effort in educating several GMF users!
Tout d'abord, merci beaucoup pour le tutoriel.
Je le réalise avec : Eclipse Juno Graphical Modeling Framework SDK 2.3.0 Eclipse Modeling Framework SDK 2.6.1
J'ai un problème. Pourriez-vous m'aider ?
Après avoir suivi toutes les étapes (sans problème), je suis bloqué à l'étape “Diagram Editor generation”. Lorsque j'appuie sur “Generate diagram editor” dans le Dashboard, j'ai le message d'erreur suivant : 'Execute Templates' has encountered a problem Problems while generating code Problems while generating code Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 77) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 77 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 83) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 83 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 83) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 83 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 19) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 19 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 19) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 19 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 83) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 83 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 77) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 77 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 77) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 77 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 49) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 49 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 49) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 49 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 49) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 49 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in CodeStyle, line 18 Exception (Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in xpt::plugin::manifest, line 78) while generating code Boolean expected (was: org.eclipse.ocl.ecore.internal.OCLStandardLibraryImpl$1)!:in xpt::plugin::manifest, line 78
Bonjour, J'ai le même problème que vous et je voulais savoir si vous êtes arrivés à le résoudre
Non, toujours pas. Peut-être que Jean-François pourrait nous aider…
Thank you very much!!
Thank you very much … this tutorial was easy to follow and it worked straight away !
Bonjour,
s'il vous plaît, j'ai besoin le code pour exporter le diagramme constitué en format xml.
Merci d'avance!
For anyone who's looking for the fix for this problem; set the Compliance Level of the .genmodel to 6.0 in order to remove these notices. It may not completely remove all the errors, am still looking into that. Found the solution in http://www.eclipse.org/forums/index.php/m/901020/
Thanks for nice tutorial! I tried to run all this in [Eclipse 4.2.1,GMF tools sdk 3.0.2,EMF 2.8.1] (actually it is Eclipse Modeling Tools 1.5.1.20121004-1506 + (GMF) Tooling SDK 3.0.2)
and I have a runtime exception: Application “org.eclipse.ui.ide.workbench” could not be found in the registry.
eclipse.buildId=unknown java.version=1.7.0_11 java.vendor=Oracle Corporation BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=ru_RU Framework arguments: -product org.eclipse.platform.ide Command-line arguments: -product org.eclipse.platform.ide -data D:\modelling/../runtime-filesystemapptest -dev file:D:/modelling/.metadata/.plugins/org.eclipse.pde.core/filesystem app test/dev.properties -os win32 -ws win32 -arch x86_64 -consoleLog
!ENTRY org.eclipse.osgi 4 0 2013-02-22 16:38:19.823 !MESSAGE Application error !STACK 1 java.lang.RuntimeException: Application “org.eclipse.ui.ide.workbench” could not be found in the registry. The applications available are: org.eclipse.ant.core.antRunner, org.eclipse.e4.ui.workbench.swt.E4Application, org.eclipse.e4.ui.workbench.swt.GenTopic, org.eclipse.equinox.app.error, org.eclipse.help.base.infocenterApplication, org.eclipse.help.base.helpApplication, org.eclipse.help.base.indexTool.
What can I do here?..
I have to say, that my previous problem (see above) hadbeen caused because Eclipse doesn't add all requiered plugins in “Run Configuration” window, so you should add 2 plug-ins below,too:
org.eclipse.core.net org.eclipse.ui.ide.application
Same problem with ubuntu 12.04, thank you Tatiana, your solution works fine.
nice artical! tks~
Hi,
That's a great tutorial. But as it is kind of a flat model hierarchy. Hence, I was wondering if it is possible to generate things even if my model doesn't have flat hierarchy but somehow like graph hierarchy? I am getting stuck at the time of Mapping phase when after combining all the domain model, graphical model and tool model, I got the Nodes which are only in the immediate next in my model Hierarchy. In my model, I don't have something root like FileSystem.
Thanks.
Very good article
Did it have any example like this but agreagando generation with Acceleo MTL.
Thank you.
During the generation of the generator model I am getting “Errors while creating generator model java.lang.NullPointerException”. I have tried a lot of times rectifying this error. Help me, clear this error
Hi,
I have to say it is a great tutorial, very useful and easy to follow.
I am facing a problem in the generated XML final diagram, and I'd like to know if it is possible to change the entity nodes generated (using the .ecore node name) e.g. I'd like to change <files> to <file or File>; and <folders> to <folder or Folder> in the following example. Is there any way to do it?
Thank you very much.
Hello, very nice tutorial, thanks. I have a problem when generating the .genmap . I don't have any nodes or links . any ideas ? a missing plugin may be ?
hello i'm not an expert on java and eclipse :( can any one help me ? i need to build a project GMF from an ecore model i would like to have in pallette a figur of a person (actor) and ellipse yellow (use case) and links in which i find the differents connection such as extend and include . please i wait your answer and thanks a lot.
Hello;
I am looking for the development of a graphical editors for high level Petri nets using GMF. I want that the editor allows the openning of many views where many nets can be seen at the same time, and where a place from one editor can be developped in another editor.
any idea please