Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Diagram tools create node location
Diagram tools create node location [message #1848497] Sun, 05 December 2021 17:51 Go to next message
Erik Danielsson is currently offline Erik DanielssonFriend
Messages: 14
Registered: September 2021
Junior Member
Hi, I have a diagram with a few tools to create nodes. When a node is dropped on the diagram I want to trigger an arrange-all action.

The issue is that with my current implementation, the placement of the node happens after my layout is triggered. So the node is moved back to the cursor location.

Is there a way to either disable the action that moves the node to where it was dropped, or to add something like a post execution to happen after the node is fully placed?

Thanks in advance!
Re: Diagram tools create node location [message #1848517 is a reply to message #1848497] Mon, 06 December 2021 17:44 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 570
Registered: May 2011
Senior Member
Hi Erik,

Good question, I do not think I ever tried that. Can you try to trigger the arrange-all from within an UIJob that you schedule with a little delay (I guess 100ms is enough)?
Otherwise, you can provide your own layout provider so when a new Edit Part is created on your diagram, you can place it where you want [1].

Best regards,
Steve

[1] https://www.eclipse.org/sirius/doc/developer/extensions-provide_custom-arrange-all.html#Writeyourcustomlayoutalgorithm


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Diagram tools create node location [message #1848672 is a reply to message #1848517] Mon, 13 December 2021 16:09 Go to previous messageGo to next message
Erik Danielsson is currently offline Erik DanielssonFriend
Messages: 14
Registered: September 2021
Junior Member
Thanks Steve!

That seems to be working alright for my diagrams. Is it possible to get the arrange action before the diagram is updated visually you think? Right now the node first displays in one location, then after a slight delay it moves to the arranged place. Which looks a bit strange. And I am worried that lowering the delay would lead to the race condition triggering again.

Thanks, Erik
Re: Diagram tools create node location [message #1848679 is a reply to message #1848672] Mon, 13 December 2021 18:35 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 570
Registered: May 2011
Senior Member
Hi Erik,

Do you have a custom layout or custom code that trigger the arrange? By default, Sirius should create the element on the location where you clicked on the diagram. That could explain why you see this change in location.
We have started to discuss among the team on how we could improve the Sirius tool process regarding triggering or not an arrange (all) at the end but I do not know if and when that will be done unfortunately.

Best regards,
Steve


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Diagram tools create node location [message #1848685 is a reply to message #1848679] Tue, 14 December 2021 01:34 Go to previous messageGo to next message
Erik Danielsson is currently offline Erik DanielssonFriend
Messages: 14
Registered: September 2021
Junior Member
Hi again,

Yes, I am using a custom Elk layout that I call using an ArrangeRequest in an ui job scheduled with 100ms delay. This is done in all services related to adding nodes in my .odesign file.

Thanks a lot for your help!

Erik

[Updated on: Tue, 14 December 2021 05:12]

Report message to a moderator

Re: Diagram tools create node location [message #1848713 is a reply to message #1848685] Tue, 14 December 2021 19:12 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 570
Registered: May 2011
Senior Member
Hi Erik,

Oh right, I replied yesterday without reading again the previous posts and I forgot about the context, sorry. Indeed that explains the "blinking effect" that you have. Now that I think of it, I have an idea for a workaround that might be stupid (unless it works, then its genius), in your creation tool, before the "create instance" task (or equivalent you may have), have a set task (or java servce) that changes the DDiagram.setSynchronized to false. If a diagram is not syncrhonized, it will not display new semantic element, unless a view element is created for it. Normaly we would use a task "create view" for that, but we would end up with the same bliking effect. Instead, in your code that trigger the arrange request, just before that call, you set back DDiagram.setSynchronized to true. Hopefully that will sync the diagram and immediately trigger your custom ELK layout. If the new node is created to late, you may have to create it manually though. You can look at org.eclipse.sirius.diagram.business.internal.helper.task.operations.CreateViewTask for an example.
I do not guaranty that it will work, but it should be quick to give it a try. Either way, I am interested in your feedback on this :).

Best regards,
Steve


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Diagram tools create node location [message #1848790 is a reply to message #1848713] Fri, 17 December 2021 06:44 Go to previous messageGo to next message
Erik Danielsson is currently offline Erik DanielssonFriend
Messages: 14
Registered: September 2021
Junior Member
Hi again. I'm having some issues trying out your solution, I did what you said, but in between the two calls to setSynchronized, there is another call from somewhere else, setting it back to true and throwing an exception.
I am using a change service action to create the model changes, which in turn is automatically updated in the diagram, if that makes any difference. I'm not sure why it is being set back...
Here is the stack from when setSynchronized is mysteriously called:
  • Attachment: stack.jpg
    (Size: 515.34KB, Downloaded 36 times)
Re: Diagram tools create node location [message #1848811 is a reply to message #1848790] Fri, 17 December 2021 17:15 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 570
Registered: May 2011
Senior Member
Hi Erik,
Can you run it in debug mode and place a breakpoint in GMFCommandWrapper.rollback? In the middle of the stack you see that the execute method calls the rollback (that is why you have a setSynchronized at false, it is reverting your change). You probably have an exception that cause this, you may find the reason there. Did you had anything more than the setSynchronized(false) to your creation tool?

Best regards,
Steve


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Diagram tools create node location [message #1848955 is a reply to message #1848811] Mon, 27 December 2021 03:30 Go to previous messageGo to next message
Erik Danielsson is currently offline Erik DanielssonFriend
Messages: 14
Registered: September 2021
Junior Member
Hi again, sorry for the delay.

I think maybe something is wrong with using a set operation, or maybe I just misunderstood? The service is being called correctly, which sets synchronized to false on the diagram. But then the rollback happens because it is trying to find an eStructualFeature of the target of the diagram with whatever name I put in the set operation in the .odesign. But the target of the diagram is just a node from our model, which doesn't have any features with whatever name I give, so the rollback happens. I also tried it as a change context instead of a set operation, which throws:
java.lang.IllegalStateException: Cannot modify resource set without a write transaction

I attached an image of the relevant parts in the odesign.

Thanks, and happy holidays!

Regards,

Erik
  • Attachment: odesign.jpg
    (Size: 213.80KB, Downloaded 30 times)
Re: Diagram tools create node location [message #1848970 is a reply to message #1848955] Mon, 27 December 2021 15:16 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 570
Registered: May 2011
Senior Member
Hi Erik,

No problem. Indeed, you can change the synchronization, only on a DDiagram element (see org.eclipse.sirius.diagram.DDiagram.isSynchronized()) so in you service disableSync from your DDiagramElement you will need to call getParentDiagram.
From a ChangeContext Sirius only expect that you return a semantic element, you should call services that modifies the model from a "Set" model operation so it will be executed in a RecordingCommand (EMF Transaction).

Happy holidays to you too,
Steve


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Diagram tools create node location [message #1849048 is a reply to message #1848970] Thu, 30 December 2021 18:52 Go to previous messageGo to next message
Erik Danielsson is currently offline Erik DanielssonFriend
Messages: 14
Registered: September 2021
Junior Member
I think that's basically what I am doing. I am passing through the view (which is a DSemanticDiamgramSpec, which extends DDiagram).

public static void disableSync(final EObject eObject, final EObject elementView) {
if (elementView instanceof DDiagram) {
((DDiagram) elementView).setSynchronized(false);
}
}

But your explanation about the set operations make a lot of sense, I have been wondering about using change contexts when we don't care about the context. That might resolve some other problems we have been having with "undo". Is there a place where I can read about these things in more detail? I saw a little bit of info in the starter tutorial, but it doesn't mention stuff like the recording command. I was wondering about the "feature name" aspect, and if we could use set operations for the node creations instead to make them record.

Kind regards,

Erik
Re: Diagram tools create node location [message #1849118 is a reply to message #1849048] Tue, 04 January 2022 19:19 Go to previous message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 570
Registered: May 2011
Senior Member
Hi Erik,

You can find more information about the model operations here: https://www.eclipse.org/sirius/doc/specifier/general/Model_Operations.html
Recording commands comes from a different framework: EMF Transaction. The advantage of the model operations is that we "hide" this transaction aspect (Model operations are executed in Recording Commands). However, if you call a java service that modifies the model it is mandatory to use recording commands so modifications are done in a transaction.

Best regards and happy new year,
Steve


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Previous Topic:Association Ecore properties empty
Next Topic:Wardley maps
Goto Forum:
  


Current Time: Wed Sep 28 15:21:11 GMT 2022

Powered by FUDForum. Page generated in 0.02646 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top