Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » how to swap positions of two nodes handled by XYLayout?
how to swap positions of two nodes handled by XYLayout? [message #201110] Fri, 08 August 2008 10:06 Go to next message
Seweryn Niemiec is currently offline Seweryn NiemiecFriend
Messages: 80
Registered: July 2009
Member
Hi.

I've successfully overridden RepositionEObjectCommand so that it moves a
child node of my compartment in booth: semantic model and notation
model. If I call ArrangeAll action after my RepositionCommand I can see
children swapping their positions, but it would be much better to see
graphical effect of repositioning without the need of calling the
arrange action.

What should I do in my RepositionCommand to swap x, y coordinates of two
nodes and get instant visual effect? Of course I need undo working too.

Greetings,
Seweryn
Re: how to swap positions of two nodes handled by XYLayout? [message #201146 is a reply to message #201110] Fri, 08 August 2008 13:13 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Seweryn,

Try creating subclass of AbstractTransactionalCommand and execute it as a
"RepositionCommand" - diagram elements should change their places as a result
of this command.

-----------------
Alex Shatalin
Re: how to swap positions of two nodes handled by XYLayout? [message #201207 is a reply to message #201146] Fri, 08 August 2008 14:48 Go to previous messageGo to next message
Seweryn Niemiec is currently offline Seweryn NiemiecFriend
Messages: 80
Registered: July 2009
Member
Alex Shatalin wrote:
> Hello Seweryn,
>
> Try creating subclass of AbstractTransactionalCommand and execute it as
> a "RepositionCommand" - diagram elements should change their places as a
> result of this command.

Thx for a hint. I was already trying to do it in a subclass of
AbstractTransactionalCommand but I didn't know what properties should I
change. After examination of SetBoundsCommand I've found this code working:

(I dunno why swapping x,y positions has to be so complicated, but
everything works fine. magically undo/redoo too, probably some day I
will understand why it works :) )

public CommandResult doExecuteWithResult(
IProgressMonitor progressMonitor, IAdaptable info)
throws ExecutionException {

EditPart compartment = (EditPart)this.sourceEP.getParent();
int newIndex = compartment.getChildren().indexOf(sourceEP) +
this.displacement;
EditPart targetEP = (EditPart)compartment.getChildren().get(newIndex);

// reposition on the list in semantic model
CommandResult rs = super.doExecuteWithResult(progressMonitor, info);

// reposition on the list in notation model
ViewUtil.repositionChildAt((View)compartment.getModel(),
(View)sourceEP.getModel(), newIndex);

// swap x,y positions in compartment
Node firstNode = (Node)sourceEP.getModel();
Node secondNode = (Node)targetEP.getModel();

int firstX = (Integer)ViewUtil.getStructuralFeatureValue(firstNode,
NotationPackage.eINSTANCE.getLocation_X());
int firstY = (Integer)ViewUtil.getStructuralFeatureValue(firstNode,
NotationPackage.eINSTANCE.getLocation_Y());
int secondX = (Integer)ViewUtil.getStructuralFeatureValue(secondNode,
NotationPackage.eINSTANCE.getLocation_X());
int secondY = (Integer)ViewUtil.getStructuralFeatureValue(secondNode,
NotationPackage.eINSTANCE.getLocation_Y());

ViewUtil.setStructuralFeatureValue(firstNode,
NotationPackage.eINSTANCE.getLocation_X(), secondX);
ViewUtil.setStructuralFeatureValue(firstNode,
NotationPackage.eINSTANCE.getLocation_Y(), secondY);
ViewUtil.setStructuralFeatureValue(secondNode,
NotationPackage.eINSTANCE.getLocation_X(), firstX);
ViewUtil.setStructuralFeatureValue(secondNode,
NotationPackage.eINSTANCE.getLocation_Y(), firstY);

compartment.refresh();

return rs;
}

Now it's time to animate it.

Greetings,
Seweryn
Re: how to swap positions of two nodes handled by XYLayout? [message #201228 is a reply to message #201207] Fri, 08 August 2008 16:07 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Seweryn,

So, the nodes were repositione correctly, but you'd like to see it in "real-time".
I see.
M.b. somebody from the Runtime Team can add some comments here in this case.

-----------------
Alex Shatalin
Re: how to swap positions of two nodes handled by XYLayout? [message #201253 is a reply to message #201228] Fri, 08 August 2008 17:07 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse.[REMOVE]stefan-kuhn.eu

you have to call
Animation.markBegin();
cmd.execute(monitor, info);
Animation.run();
for animation. Note that this -as it is- just works if you call
Animation.run() after the whole transactional command is executed.

It doesn't work in command execution because the editParts are just
updated after the transactional cmd is finished. You can update them
manually in the command, but watch out: editParts which are destroyed
and re-created mustn't be _stored_ in a command. So you can use the
Viewers view->editPart map to receive the correct editPart in you cmd.
But that's all a bit more complicated than the first approach ... ;)

-stefan ... gentleware AG not runtime-team :p




Alex Shatalin schrieb:
> Hello Seweryn,
>
> So, the nodes were repositione correctly, but you'd like to see it in
> "real-time". I see.
> M.b. somebody from the Runtime Team can add some comments here in this
> case.
>
> -----------------
> Alex Shatalin
>
>
Previous Topic:Auto Arrange and Link Mappings GMF 2.1
Next Topic:Layout: How to modify TopDownProvider?
Goto Forum:
  


Current Time: Fri Apr 26 13:41:43 GMT 2024

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

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

Back to the top