Bug 192831 - [DND] New SWT Drag'n'Drop API should provide bounds of target item
Summary: [DND] New SWT Drag'n'Drop API should provide bounds of target item
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.3   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted, triaged
Depends on:
Blocks:
 
Reported: 2007-06-15 05:49 EDT by Mark-Oliver Reiser CLA
Modified: 2017-07-28 09:39 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark-Oliver Reiser CLA 2007-06-15 05:49:45 EDT
Hi,

I have just added DND support for a custom widget (Nebula Grid).  Thanks to the new SWT API for DND this worked fine.  As a test, I replaced in an EMF generated editor a TreeViewer with ViewerColumns by the custom widget and all the nifty DND functionality of the EMF editor was available almost at once.  I think this shows how useful this new DND API is.

(A) Location

However, there is still some widget specific stuff left in the client code.  This is what the DropTargetListener in my testing snippet looks like:

dropTarget.addDropListener(new DropTargetAdapter() {
  @Override
  public void dragOver(DropTargetEvent event) {
    event.feedback = DND.FEEDBACK_SCROLL | DND.FEEDBACK_EXPAND;
    float relPos = getLocation(event);
    if (relPos<0.2F)
      event.feedback |= DND.FEEDBACK_INSERT_BEFORE;
    else if (relPos>0.8F)
      event.feedback |= DND.FEEDBACK_INSERT_AFTER;
    else
      event.feedback |= DND.FEEDBACK_SELECT;
  }
  private float getLocation(DropTargetEvent event) 
  {
    if (event.item instanceof GridItem)
    {
      GridItem gridItem = (GridItem)event.item;
      Grid grid = gridItem.getParent();
      Point point = grid.toControl(new Point(event.x, event.y));
      GridColumn column = grid.getColumn(point);
      Rectangle bounds = gridItem.getBounds(grid.indexOf(column));
      return (float)(point.y - bounds.y) / (float)bounds.height;
    }
    else
    {
      return 0.0F;
    }
  }
});

As you can see, the method getLocation() is still widget specific.  I think
it would be good to consider adding a method DropTargetEffect#getLocation() in addition to DropTargetEffect#getItem(int,int).

I am not sure if a method that returns a float (as in the snippet) would be the best choice.  Probably it would be preferable to be more generic and allowing more flexibility: by returning the bounds of the target item (= event.item) or the coordinates of the mouse pointer relative to the origin of the target item.

I think returning the bounds relative to the display would be best.


(B) Insert mark left/right

Another limitation is that the current DND framework (both old and new API) only supports insert marks above and below the target item.  For some custom widgets (e.g. table widgets with cells selection behaviour) it would be good to have insert marks on the left and on the right side of the target item.
For this, new values could be added in DND:
DND#FEEDBACK_INSERT_NORTH (gets same value as FEEDBACK_INSERT_BEFORE)
DND#FEEDBACK_INSERT_SOUTH (gets same value as FEEDBACK_INSERT_AFTER)
DND#FEEDBACK_INSERT_EAST
DND#FEEDBACK_INSERT_WEST
(or only to new values *_LEFT and *_RIGHT)

However, there is a possible workaround for that, so this might not be very urgent: normaly FEEDBACK_SELECT/INSERT_BEFORE/INSERT_AFTER are mutually exclusive.  If left/right is needed, one could use the FEEDBACK_SELECT to indicate that the FEEDBACK_INSERT_* values are to be interpreted horizontally.


Greetings,

Oliver
Comment 1 Eric Williams CLA 2017-07-28 09:39:58 EDT
No response in awhile. However since this is a request for an enhancement, patches are welcome. :)