how to swap positions of two nodes handled by XYLayout? [message #201110] |
Fri, 08 August 2008 06:06  |
Eclipse User |
|
|
|
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 #201207 is a reply to message #201146] |
Fri, 08 August 2008 10:48   |
Eclipse User |
|
|
|
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 #201253 is a reply to message #201228] |
Fri, 08 August 2008 13:07  |
Eclipse User |
|
|
|
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
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.06657 seconds