Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Providing a correct MoveShapeFeature
Providing a correct MoveShapeFeature [message #1004591] Wed, 23 January 2013 09:06 Go to next message
Cedric Moonen is currently offline Cedric Moonen
Messages: 270
Registered: August 2009
Senior Member
Hello,

I'm trying to provide my own MoveShapeFeature and from what I understood by debugging (there's not too much documentation about this) the IMoveShapeContext doesn't contain any information about the mouse pointer location, but only information relative to the top-left corner of the shape being dragged.

Suppose that you drag a shape by clicking on a middle point, and you move it above another shape. What you get in the x value of the IMoveShapeContext is the position of the top-left corner of the shape at its new position relative to the top-left corner of the destination shape. So, this value can very well be in negative, which doesn't make too much sense.

What I would like to have as a value is the position of the mouse cursor relative to the top-left corner of the destination shape (to verify whether the shape can be dropped at this position on the destination shape). How can I get such a value ? Unfortunately, there is no information about the delta of the drag point (the delta between the mouse position and the top-left corner of the source shape at the beginning of the drag) in the IMoveShapeContext.

I don't know if I made myself clear enough...
Re: Providing a correct MoveShapeFeature [message #1005062 is a reply to message #1004591] Thu, 24 January 2013 06:59 Go to previous messageGo to next message
Felix Velasco is currently offline Felix Velasco
Messages: 43
Registered: July 2009
Member
You can call getDiagramEditor().getCurrentMouseLocation() to obtain the mouse coordinates relative to the diagram. Then call Graphiti.getPeLayoutService().getLocationRelativeToDiagram(shape) to obtain the destination shape location, and subtract.
Re: Providing a correct MoveShapeFeature [message #1005101 is a reply to message #1005062] Thu, 24 January 2013 08:37 Go to previous messageGo to next message
Cedric Moonen is currently offline Cedric Moonen
Messages: 270
Registered: August 2009
Senior Member
Thanks for your reply. I was already using getDiagramEditor().getCurrentMouseLocation(), but unfortunately:
1) You get a discouraged access warning
2) It doesnt really work as I expected. As long as your diagram scroll bars are located at position 0, everything works fine. However, when you scroll your diagram, the mouse location is relative to the visible part of the diagram, not the point 0,0 of the diagram. So, substracting the result of Graphiti.getPeLayoutService().getLocationRelativeToDiagram(shape) to the mouse location doesn't work if the scroll bars are not at the origin.

I don't know if point 2 is the expected behavior or if this is a bug ?
Re: Providing a correct MoveShapeFeature [message #1005177 is a reply to message #1005101] Thu, 24 January 2013 10:37 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1590
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Cedric,

the class DiagramEditor offers 2 methods for retrieving the mouse position:
getMouseLocation does not take the offset caused by scrollbars into account,
while calculateRealMousePosition does.

Regarding your first question I'm a little confused: getCurrentMouseLocation
was the name of the first method before the editor API restructuring done in
Graphiti 0.9.0. Are you using an older version? In 0.9.0 there should be no
access warnings any more.

Michael
Re: Providing a correct MoveShapeFeature [message #1005191 is a reply to message #1005177] Thu, 24 January 2013 11:02 Go to previous messageGo to next message
Cedric Moonen is currently offline Cedric Moonen
Messages: 270
Registered: August 2009
Senior Member
Michael,

Thanks for your answer.

I tried to upgrade to 0.9 some time ago but unfortunately I'm still stuck with the problem I was referencing here.

So, I reverted back to 0.8.1. I would like to upgrade to the new version of graphiti because there a couple of interesting things there but I have no clue how I can solve my problem...

Do you have any idea how to do that (maybe best to answer in the original discussion, if other people are interested in a solution).

Thank you.
Cédric
Re: Providing a correct MoveShapeFeature [message #1005451 is a reply to message #1005191] Fri, 25 January 2013 08:50 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1590
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Cédric,

in the thread is an answer by Joao S, that shows the right way. You should
subclass DefaultUpdateBehavior, return that subclass in
DiagramEditor.createUpdateBehavior and within your sublass create your own
editing domain or retrieve the one you want to use.

Does that help?

Michael
Re: Providing a correct MoveShapeFeature [message #1005475 is a reply to message #1005451] Fri, 25 January 2013 10:32 Go to previous message
Cedric Moonen is currently offline Cedric Moonen
Messages: 270
Registered: August 2009
Senior Member
Hi Michael,

I investigated that solution at the time but unfortunately, it didn't bring me any further because I was still not able to pass my editing domain. So I finally dropped the case and stayed with version 0.8.

I'll add some more information about the reason why I was not able to work out a solution in the other thread.

Thanks
Previous Topic:Adding a new shape to diagram by double-click
Next Topic:invoke addifpossible after creating diagram is not showing shapes
Goto Forum:
  


Current Time: Fri Aug 29 16:25:03 EDT 2014

Powered by FUDForum. Page generated in 0.01674 seconds