Home » Modeling » GMF (Graphical Modeling Framework) » Diagram editor support for model extensions(Adding editor tools for contributed metamodel extension)
|Diagram editor support for model extensions [message #1512145]
||Mon, 15 December 2014 13:43
| Mathias K
Registered: March 2014
I have been struggling with this problem for some time, despite some previous posts I've seen on the subject, and hope someone here can help or at least point me in the right direction.
An archive containing all the test projects discussed below is attached.
I have an EMF plugin which contributes a main metamodel (project "graph") with one class "Graph" that contains a class "Node", and a GMF editor (project "graph.diagram").
I also have another EMF plugin (project "extension") which contributes a specialized class to Node ("CustomNode"). Graph's genmodel has 'Extensible Provider Factory" option set true, while extension's genmodel has "Child Creation Extenders" set true. This allows EMF reflective editors to take the new node into account.
Now I want the gmf editor for graph to be able to handle this contributed node.
Without any modifications, GMF's diagram editor is able to open a graph that contains a custom node, even using its parent's figure, so far so good.
Now there is no tool for CustomNode in the palette. From my understanding, there is no magic to create tools for such contributed classes, and there would be (at least) 2 ways of adding this support :
1) using a palette contribution through the extension point "paletteProvider".
I have created another GMF project (project "extension.diagram") which contributes to this extension point with a factory class "GraphExtensionPaletteFactory".
Within this factory, I have tried 2 options for creating the tool, both without success.
I first generated GMF's editor code for "extension" using a dummy ExtendedGraph node as the canvas. This was only so I could have an ElementType to refer to in option a, and a creation tool factory for option b. I do not plan on using the extension editor and could remove most of the generated code, it just seemed easier to do that than creating all the EditPart/ElementTypes parts of the code by myself.
a) using the CreationTool constructor with the ElementType:
tools.put("graph.extension.diagram.tools.extendednode", new CreationTool(ExtensionElementTypes.ExtendedNode_2001));
Result: the tool appears in the main editor's palette, but trying to click on the canvas shows a "no entry" sign cursor.
b) using GMF's generated factory to create the tool:
ExtensionPaletteFactory factory = new ExtensionPaletteFactory();
Result: the tool appears also, but trying to click on the canvas shows a "cross" cursor.
There are no exceptions thrown, so I have no idea where this behaviour comes from in both cases. My guess would be that there is some kind of check being done in editor to see if the semantic element is applicable to the canvas, and for some reasons it fails.
I saw there is another extension point for declaring element types, and tried to register my ExtendedNode using it but didn't see any difference.
At that point, for way 1), I'm out of ideas for going on.
2) creating a custom extension point in my graph.diagram GMF project, allowing such contributions to the diagram editor, and dealing with it in the main editor's code.
I'm don't know much about GMF's generated code, but from what I've seen, ElementTypes/EditParts/Tools are generated for each class using a bunch of static fields. It seems like I could try to hook in different places (such as method "fillPalette" for the contributed tool), but I'm under the impression that there are many parts of the code where I should "register" my extended type, otherwise I'll just end creating something inconsistent, and probably fall back to the same problems as 1). If someone has experience with this however, I'm willing to try.
That's about it. I may have missed something obvious, or maybe I'm going the wrong track. I've read several posts about related problems, most of them try to add nodes dynamically during runtime, some were useful to coin the issue but none of them helped me debug my problem.
For the paletteProvider extension, I mostly followed GMF's FAQs/tutorial, as well as IBM's article ( edit: forum does not let me post the link ).
I also read the (deprecated) GMF FAQ which briefly discusses the issue ( wiki.eclipse.org/Graphical_Modeling_Framework/Archived_Newsgroup_Q_and_A#How_can_I_contribute_new_palette_extensions.3F ).
Finally, many other related issues posts I've read point to non-existing documentation or web pages.
|Re: Diagram editor support for model extensions [message #1688433 is a reply to message #1512145]
||Fri, 20 March 2015 17:39
| Mathias K
Registered: March 2014
I have made no progress on this issue on my own. Below some things I tried. Is any GMF developer or expert reading these forums ?
- I have tried many combinations of the "element types" extension points with the different options I wrote in my first post, using either the specialization type extension or the new element type extension. This does not seems to have any effect whatsoever.
- I also tried without using the GMF code generator for the extension node, as I thought the fact that i was declaring a new canvas (extending the main one) might be the issue. Indeed, in some of my tries, I tracked down the error when trying to add the node to the diagram to an "assert_is_not_null" on what I believe is the canvas.
Therefore I created the extension node code (edit parts, etc.) directly, taking the original node as example. I tried with or without extending the main diagram corresponding classes, always declaring the new node using the element types extension. As before, I can see the node in the diagram when it previously existed in the model, but I can't ccreate a working tool for it. The symptoms are slightly different: I can't even click on the tool, it seems "inactive" (no error is thrown).
If creating my own extension point in the main diagram code is the only way to go, I'd like to know and possibly have some hints about that. I did look a bit into it, and it is not clear to me how I could hook in to allow for externally-defined elements being accepted by the canvas (if that is even the problem with the tooling). I can only see there are many places where diagram elements validity/properties are checked, and the GMF code is a lot based in elements declared as static fields which makes it complicated to find an entry point.
I'm not attaching a project with the new tries, as it wouldn't add much value and I believe the first one is enough to understand the issue. I can of course run any tests or provide any additional input that might be useful.
Thank you to anyone taking some time to answer this.,
[Updated on: Fri, 20 March 2015 17:40]
Report message to a moderator
Current Time: Tue Dec 01 16:19:33 GMT 2020
Powered by FUDForum
. Page generated in 0.01985 seconds