Published by Arto Jarvinen on 06 Apr 2012 at 10:22 pm
A lot of screams for so little wool
Many hours and a lot of unstructured reading later I think I got the hang of the copy-paste problem i introduced in my previous post. I had very good help from [1]. The first kindle of hope came when I looked at the XML files used to store (“persist” in the sophisticated Eclipse lingo) the data from the generated editor. There is one file to store the domain model (the representation of real world “things”) and another file to store the view model (the descriptions of the user created diagrams depicting various parts of the domain model). What confused me a lot in the beginning was that the word “model” is used in the GMF documentation to denote the union of the domain model and the view model whereas I have always wanted to keep them strictly apart.
I want the same domain model object to be represented in several diagrams, i.e. the icons in all these diagrams shall point at the same domain model object. When I achieved this by manually adding a diagram node into one of the XML files storing one of the diagrams, I knew I was on the right track. What remained was to find a way to do the same thing in the GMF internal data structure.
![]() |
| Cloning people. |
Let me digress for a minute: Eclipse is an impressive set of tools and frameworks. The developers know their design patterns and their Java. But it is also fiendish and uninviting for the novice. Nothing is straightforward (for a good reasons I assume). To copy and paste something into your diagram you don’t just override some copy-paste method. You modify an “extension” and create a “command” that in turn creates a “transactional command” that is then passed on to some sort of command executing machinery that, if you are lucky does the copy or the paste. (The stack trace is about a hundred lines deep when it all crashes.) And the stuff to copy and paste is passed along and typecast hither and thither.
One other thing to note if you want to get started with GMF is that the GMF documentation is not included in the latest (Indigo) version of the Eclipse documentation. One has to go back to the Helios documentation [4] to find it. (For basic EMF documentation you have to go back two releases to the Galileo version docs.)
I guess what I want to say is that if you decide to dive into Eclipse, be prepared to read a lot of code and to use traces and the debugger to understand where you are coming from and where you are going. The articles [2] and [3] give some useful background.
As for copy-paste, I managed to copy a view (icon in a diagram together with its associated data) and paste it both to the same diagram and to another diagram while the view was still pointing at the same domain model object (see image). The delete command doesn’t work as intended though. After a while it deletes all items in the diagram in one fell swoop. I guess I need to write my own delete too.
I think it’s fair to say that I still don’t quite understand what I’m doing but it is always easier to start understanding with a somewhat working example than one that doesn’t execute at all.
Links
[1] The copy-paste problem and its solution.
[2] GEF description.
[3] Create an Eclipse-based application using the Graphical Editing Framework.
[4] Open source articles at IBM.
[5] The latest GMF on-line documentation (from the Helios release).

