Zest5: getting the model node from the displayed node [message #1783560] |
Wed, 14 March 2018 03:15  |
Eclipse User |
|
|
|
Hello,
My graph model is implemented as an IGraphContentProvider, it is displayed with Zest (Oxygen release version).
I want to know which node is selected (the node given by my provider, I call it modelNode), I was thinking that it is a common use case, but I didn't find an easy way to do it.
There was a IFXOnClickPolicy in Gef4, I don't see it anymore in current version.
Here is my current design:
I follow the advice given in this forum, that is: I create a new MyModule class that extends ZestFxModule and override the #bindNodePartAdapters() method to attach my handler.
In my handler, The #click(MouseEvent e) give me access to the org.eclipse.gef.zest.fx.parts.NodePart object with getHost()
The NodePart is created by ZestFxContentPartFactory.createContentPart() when the content is a graphNode, an instance of org.eclipse.gef.graph.Node (no links is kept between the NodePart and the graphNode, but we could have it by subclassing the Factory)
The graphNode itself is created by ZestContentViewer.createNode() who has access to my modelNode (given by my IGraphContentProvider) but if the ZestContentViewer maintains a map (called contentNodeMap) from modelNode to graphNode, I need the reverse; Again, I need to subclass to viewer to keep this needed link.
So my question is: is there a simple way to get from the mouse click to my modelNode ?
Regards,
Dominique
|
|
|
Re: Zest5: getting the model node from the displayed node [message #1783948 is a reply to message #1783560] |
Tue, 20 March 2018 11:43   |
Eclipse User |
|
|
|
Hello,
I have simplified my design, here is it for anyone interested.
Quote:I follow the advice given in this forum, that is: I create a new MyModule class that extends ZestFxModule and override the #bindNodePartAdapters() method to attach my handler.
In my handler, The #click(MouseEvent e) give me access to the org.eclipse.gef.zest.fx.parts.NodePart object with getHost()
There is already an attached handler (FocusAndSelectOnClickHandler), we can benefit from it because y using Viewer.addSelectionChangedListener().
Quote:
The NodePart is created by ZestFxContentPartFactory.createContentPart() when the content is a graphNode, an instance of org.eclipse.gef.graph.Node (no links is kept between the NodePart and the graphNode, but we could have it by subclassing the Factory)
The graphNode is set as the primary content of the contentPart, so the above is not needed. Moreover, the registered listener receives directly the graphNode in the selection (it get it of course with the primary content, that's how I discover this).
Quote:
The graphNode itself is created by ZestContentViewer.createNode() who has access to my modelNode (given by my IGraphContentProvider) but if the ZestContentViewer maintains a map (called contentNodeMap) from modelNode to graphNode, I need the reverse; Again, I need to subclass to viewer to keep this needed link.
I didn't find a better way, so I have added a nodeContentMap in my viewer subclass.
Regards,
Dominique
|
|
|
|
Powered by
FUDForum. Page generated in 0.03865 seconds