Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » [Zest/Draw2D] Drag and drop
[Zest/Draw2D] Drag and drop [message #247242] Thu, 12 February 2009 09:52 Go to next message
Bianca Thelen is currently offline Bianca Thelen
Messages: 26
Registered: July 2009
Junior Member
Hello,

I have a shell that contains a JFace table viewer on the left side and a
Zest graph on the right side. I added drag capability to the table
viewer and drop capability to the graph. I want to allow drop only when
the dragged item is dropped onto a graph node.

The drop event gives me x and y coordinates but they are not the same as
the coordinates given by a mouse move listener added to the graph
(example: drop x 225 drop y 219, mouse move x 40 mouse move y 39). I
tried to call graph.getRootLayer().translateToRelative(drop coordinates)
but that just returned the old coordinates. Can anybody help me as to
how I have to translate the drop coordinates into the right coordinates
for Graph#getFigureAt?

Kind regards
Bianca
Re: [Zest/Draw2D] Drag and drop [message #247290 is a reply to message #247242] Fri, 13 February 2009 16:47 Go to previous messageGo to next message
Eclipse User
Originally posted by: irbull.cs.uvic.ca

hum...

this seems like a bug. Are you using nested (or any zooming)?

cheers,
ian

Bianca wrote:
> Hello,
>
> I have a shell that contains a JFace table viewer on the left side and a
> Zest graph on the right side. I added drag capability to the table
> viewer and drop capability to the graph. I want to allow drop only when
> the dragged item is dropped onto a graph node.
>
> The drop event gives me x and y coordinates but they are not the same as
> the coordinates given by a mouse move listener added to the graph
> (example: drop x 225 drop y 219, mouse move x 40 mouse move y 39). I
> tried to call graph.getRootLayer().translateToRelative(drop coordinates)
> but that just returned the old coordinates. Can anybody help me as to
> how I have to translate the drop coordinates into the right coordinates
> for Graph#getFigureAt?
>
> Kind regards
> Bianca
Re: [Zest/Draw2D] Drag and drop [message #247307 is a reply to message #247290] Sun, 15 February 2009 15:47 Go to previous messageGo to next message
Bianca Thelen is currently offline Bianca Thelen
Messages: 26
Registered: July 2009
Junior Member
> this seems like a bug. Are you using nested (or any zooming)?

I am not sure what you mean by nested. I just create a graph to which I
add GraphNodes. I'm not using zooming.

I've found a formula (of sorts), however, which gives me the correct
coordinates for a figure:

public void drop(DropTargetEvent event) {
Point point = new Point(event.x, event.y);
IFigure figureAt = graph.getFigureAt(
(point.x
- graph.getLocation().x
- graph.getShell().getLocation().x),
(point.y
- graph.getLocation().y
- graph.getShell().getLocation().y
- 30));
}

I'm not happy with it but it seems to work. I'm not sure how failsafe it
is though. Probably not very... What I'm bugged most by is the random 30
that I have to substract to get the y-coordinate.

Kind regards
Bianca
Re: [Zest/Draw2D] Drag and drop [message #767936 is a reply to message #247307] Mon, 19 December 2011 08:28 Go to previous message
Erdal Karaca is currently offline Erdal Karaca
Messages: 747
Registered: July 2009
Senior Member
I have the same problem.

I am using this to calculate the relative coords:


protected Object determineTarget(DropTargetEvent event) {
		Graph g = viewer.getGraphControl();
		Point p = g.getDisplay().map(g.getShell(), g, event.x, event.y - 30);
		IFigure fig = g.getFigureAt(p.x, p.y);

		if (fig != null) {
			for (Object o : g.getNodes()) {
				GraphNode gn = (GraphNode) o;

				if (gn.getFigure() == fig) {
					return gn.getData();
				}
			}
		}

		return null;
	}


As you can see, I still have to subtract those magic 30 Pixels, though those 30 Pixels dont seem to be sufficient...

Anyone with new/fresh hints?

Bianca Thelen wrote on Sun, 15 February 2009 10:47
> this seems like a bug. Are you using nested (or any zooming)?

I am not sure what you mean by nested. I just create a graph to which I
add GraphNodes. I'm not using zooming.

I've found a formula (of sorts), however, which gives me the correct
coordinates for a figure:

public void drop(DropTargetEvent event) {
Point point = new Point(event.x, event.y);
IFigure figureAt = graph.getFigureAt(
(point.x
- graph.getLocation().x
- graph.getShell().getLocation().x),
(point.y
- graph.getLocation().y
- graph.getShell().getLocation().y
- 30));
}

I'm not happy with it but it seems to work. I'm not sure how failsafe it
is though. Probably not very... What I'm bugged most by is the random 30
that I have to substract to get the y-coordinate.

Kind regards
Bianca

Previous Topic:[Zest] How to use Drag and Drop (DND) with zest?
Next Topic:Disabling animation in gef ui palette ??
Goto Forum:
  


Current Time: Wed Oct 01 18:33:49 GMT 2014

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

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