This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 197559

Summary: ExternalDropHandler instances registered at the global lookup are ignored.
Product: platform Reporter: tschlegl <tschlegl>
Component: Window SystemAssignee: Stanislav Aubrecht <saubrecht>
Status: RESOLVED FIXED    
Severity: normal CC: elena_regs
Priority: P3    
Version: 7.0   
Hardware: PC   
OS: Linux   
Issue Type: DEFECT Exception Reporter:

Description tschlegl 2011-04-08 10:30:06 UTC
To facilitate the tabs of the Netbeans TabbedPane for editor components as drop targets, we registered an ExternalDropHandler extension at the global lookup. This
worked fine with 6.9.1 platform - the handler is created and methods are called,
when a Node is dragged to the editor windows decoration. But not with current version 7rc1. With 

    for (ExternalDropHandler dh = Lookup.getDefault().lookupAll(
            ExternalDropHandler.class)) {
        LOGGER.info("drop handler " + dh);
    }

i can see our ExternalDropHandler and also a second one, an instance of 
org.netbeans.modules.openfile.DefaultExternalDropHandler which seems to
belong to the IDE cluster.
In version 6.9.1 our handler is first in the list but order is reverse in
version 7rc1.
The handler's methods seem to get called from 
core.windows/src/org/netbeans/core/windows/view/EditorView.java but there
only the first found handler is asked as you can see in the dragOver method:

    ExternalDropHandler handler = 
            (ExternalDropHandler)Lookup.getDefault().lookup( 
            ExternalDropHandler.class );
    //check if a file is being dragged over and if anybody can process it
    if( null != handler && handler.canDrop( dtde ) ) {
       dtde.acceptDrag( DnDConstants.ACTION_COPY );
    } else {
       dtde.rejectDrag()
    }

I thing, this is a bug and all ExternalDropHandler that are registered at
the global lookup must be asked there.
Comment 1 tschlegl 2011-04-08 14:04:38 UTC
I've seen that I can influence the order of the instances delivered from
the lookup which helps a lot. But I haven't found a way to get all my registered
handlers called when performing a mouse drop.
Comment 2 Jaroslav Tulach 2011-04-11 12:25:06 UTC
If the code in question is in core.windows/src/org/netbeans/core/windows/view/EditorView.java then the proper component is Window System. Btw. consider donating patch with test.
Comment 3 Stanislav Aubrecht 2011-04-13 10:18:13 UTC
reporter, is this the behavior you're looking for?

# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -237,24 +237,27 @@
                 public void dragExit(DropTargetEvent dte) {
                 }
                 public void dragOver(DropTargetDragEvent dtde) {
-                    ExternalDropHandler handler = (ExternalDropHandler)Lookup.getDefault().lookup( ExternalDropHandler.class );
+                    for( ExternalDropHandler handler : Lookup.getDefault().lookupAll( ExternalDropHandler.class ) ) {
                     //check if a file is being dragged over and if anybody can process it
-                    if( null != handler && handler.canDrop( dtde ) ) {
+                        if( handler.canDrop( dtde ) ) {
                         dtde.acceptDrag( DnDConstants.ACTION_COPY );
-                    } else {
-                        dtde.rejectDrag();
+                            return;
                     }
                 }
+                    dtde.rejectDrag();
+                }
                 public void drop(DropTargetDropEvent dtde) {
                     boolean dropRes = false;
                     try {
-                        ExternalDropHandler handler = (ExternalDropHandler)Lookup.getDefault().lookup( ExternalDropHandler.class );
+                        for( ExternalDropHandler handler : Lookup.getDefault().lookupAll( ExternalDropHandler.class ) ) {
                         if( handler.canDrop( dtde ) ) {
                             //file is being dragged over
                             dtde.acceptDrop( DnDConstants.ACTION_COPY );
                             //let the handler to take care of it
                             dropRes = handler.handleDrop( dtde );
+                                break;
                         }
+                        }
                     } finally {
                         dtde.dropComplete( dropRes );
                     }
Comment 4 tschlegl 2011-04-13 11:23:25 UTC
I'm not completely sure what the patched code will look like but I'm thinking it is working, as it's the best solution to pass the DropTargetDropEvent only to the first handler that canDrop it. As i remember correctly the collection returned by the the lookupAll() call is implemented as a List so the handlers asked in the dragOver() and the drop() methods are always in the same order.

Thank you,
Tobias
Comment 5 Stanislav Aubrecht 2011-07-18 14:34:53 UTC
core-main d91dcdf2705e
Comment 6 Quality Engineering 2011-07-19 13:57:04 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/d91dcdf2705e
User: S. Aubrecht <saubrecht@netbeans.org>
Log: #197559 - check all ExternalDropHandlers registered in the global Lookup
Comment 7 Stanislav Aubrecht 2011-09-12 14:29:27 UTC
*** Bug 201814 has been marked as a duplicate of this bug. ***