Moving elements to the back on creation [message #1861524] |
Tue, 17 October 2023 06:45  |
Eclipse User |
|
|
|
Hello,
I made a tool to create an element and now i would like these elements to always be in the back behind other elements. I can manually do this in the context menu for each element, but i would like this to be done automatically on creation.
How can i achieve this behavior?
What i found so far is "org.eclipse.sirius.diagram.tools.api.command.view.SendElementsToBack", however i am unsure if this is for edges only and how to implement it properly.
I thought of using a IExternalJavaAction, but i don't know how to get the view required by this (SendElementsToBack) class.
Any help is appreciated.
|
|
|
Re: Moving elements to the back on creation [message #1861659 is a reply to message #1861524] |
Wed, 25 October 2023 10:47  |
Eclipse User |
|
|
|
Hi.
You cant't do it directly inside the body of your creation tool, as you need to manipulate the order of the GMF View element for the new node, which will only exist after Sirius has refreshed the state of the diagram, which happens after your tool has executed.
You *may* be able to do it using a ModelChangeTrigger, which can perform changes in the model before a change is commited (it's a pre-commit listener in EMF Transaction parlance).
It's quite involved if you're not familiar with all the APIs involved, but some pointers:
* Ecore Tools has examples of https://github.com/eclipse-ecoretools/ecoretools/blob/master/org.eclipse.emf.ecoretools.design/plugin.xml#L24, for example https://github.com/eclipse-ecoretools/ecoretools/blob/master/org.eclipse.emf.ecoretools.design/src/org/eclipse/emf/ecoretools/design/service/AutosizeTrigger.java
* You'll need to have a SessionListener to install your ModelChangeTrigger, see https://github.com/eclipse-ecoretools/ecoretools/blob/master/org.eclipse.emf.ecoretools.design/src/org/eclipse/emf/ecoretools/design/internal/EcoreToolsSessionListener.java for an example
* The SessionListener itself needs to be registered with an extension point. See https://github.com/eclipse-ecoretools/ecoretools/blob/master/org.eclipse.emf.ecoretools.design/plugin.xml#L24.
* Assuming all of this is properly setup, your ModelChangeTrigger will need to identify changes which correspond to the invocation of your tool/creation of the new element, find the GMF Node that Sirius/GMF will have created to represent it, and use code similar to "ViewUtil.repositionChildAt(containerView, view, 0)" (found in SendElementsToBack) to move the new Node as the first of its siblings (which corresponds to placing it below all of them).
|
|
|
Powered by
FUDForum. Page generated in 0.49260 seconds