"Relative to display" To "Relative to TableItem" [message #465177] |
Thu, 08 December 2005 00:35 |
Eclipse User |
|
|
|
Originally posted by: dank.webreachinc.com
Hello,
To make a long story short, I've got coordinates that are relative to the
display. I want to find out which TableItem in a table this coordinate is
refering to.
Here's the long story: I've implemented some drag and drop functionality
between two tables on my UI. You can drag a row from one table and drop
it into the other table. When you drop it, I need to figure out where the
mouse was when the user released the mouse's button. This is how I will
figure out *where* to insert the item that was dragged. I tried adding a
mouse adapter on the target, but mouseup() doesn't get triggered from a
(drag and) drop.
The DropTargetEvent does come with a .x and a .y that are filled with
coordinates but they are relative to the display. I can go through every
tableitem and use getBounds to get it's coordinates but these coordinates
will be relative to the table, not the display.
It seems insanely hard/impossible to accomplish this. How do i convert
"Relative to Display" coordinates into "Relative to some-part-of-the-UI"
coordinates and/or vice versa?
Thanks for the help,
Dan
|
|
|
Re: "Relative to display" To "Relative to TableItem" [message #465190 is a reply to message #465177] |
Thu, 08 December 2005 01:48 |
Eclipse User |
|
|
|
Originally posted by: dank.webreachinc.com
I found the answer and I feel i should give back by explaining it. This
is what you do:
private int getIndexToInsertFrom(DropTargetEvent event) {
Point p = table.getDisplay().map(null, table, event.x, event.y);
TableItem [] items = table.getItems();
for (int i = 0; i < items.length; ++i) {
TableItem itemAtPoint = table.getItem(p);
TableItem item = items[i];
if (item.equals(itemAtPoint)) {
return i;
}
}
return -1;
}
|
|
|
Powered by
FUDForum. Page generated in 0.03417 seconds