Bug 200833

Summary: DropTargetListener attached to Zest GraphViewer doesn't get event.item set properly
Product: [Tools] GEF Reporter: Nathan Tolbert <gauauu>
Component: GEF-Legacy ZestAssignee: gef-inbox <gef-inbox>
Status: NEW --- QA Contact:
Severity: minor    
Priority: P3 CC: ahunter.eclipse
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

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.