Bug 200833 - DropTargetListener attached to Zest GraphViewer doesn't get event.item set properly
Summary: DropTargetListener attached to Zest GraphViewer doesn't get event.item set pr...
Status: NEW
Alias: None
Product: GEF
Classification: Tools
Component: GEF-Legacy Zest (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: gef-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-08-22 10:43 EDT by Nathan Tolbert CLA
Modified: 2015-01-22 02:45 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Tolbert CLA 2007-08-22 10:43:16 EDT
Build ID: I20070621-1340

Steps To Reproduce:
1.  Create a zest GraphViewer
2.  Attach a DropTargetListener
3.  Drag an object over the GraphViewer

In the dropTargetListener's dragOver() and drop() methods, the event parameter (of type DropTargetEvent) doesn't have its item field set properly.  This field is null, where in other jface viewers, it is set to the child element of the viewer that is being dragged/dropped over.

I am using the same code snippet to reproduce this as in Bug 200732


More information:
This can be worked around by examining the event.x and event.y and doing a search of the graph's nodes to determine which object is actually being hovered over.  I do something like this, and call setEventItem() before I query event.item:

    private void setEventItem( DropTargetEvent event )
    {
        List nodes = viewer.getGraphControl().getNodes();

        for ( Object nodeObj : nodes ) {
            GraphNode gn = (GraphNode) nodeObj;
            Point location = gn.getLocation();
            Dimension size = gn.getSize();
            Control displayControl = null;
            org.eclipse.swt.graphics.Point map = 
                        gn.getDisplay().map( viewer.getControl(),
                        displayControl, location.x, location.y );
            if ( (map.x < event.x) && (map.y < event.y) && 
                 (map.x + size.width > event.x) && 
                 (map.y + size.height > event.y) ) {
                event.detail = DND.DROP_COPY;
                event.item = gn;
                return;
            }
        }

    }
Comment 1 Alexander Nyßen CLA 2015-01-22 02:45:03 EST
Re-assigning back to inbox, as Ian is no longer active committer.