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.
I'm learning about the platform's DnD interfaces and capabilities. In the Node docs for "drag" it says The node can attach a transfer listener to ExTransferable and will be then notified about progress of the drag (accept/reject). But that doesn't seem to work. The following is based on the example at https://blogs.oracle.com/geertjan/entry/node_cut_copy_paste_delete I add "hook" see code below, to the return from clipboardCopy,clipboardCut and never see any log output from listener during DnD operation. Drag a node to the other conatainer, note there is no finish method invoked INFO [debug]: hook-cut: ...ExTransferable@9db941e INFO [debug]: hook-copy: ...ExTransferable@3a31e13e doing a popup menu "Copy" produces the following output, note that this is only the copy menu operation (no paste or DnD or anything else) INFO [debug]: hook-copy: ...ExTransferable@4d71cf43 INFO [debug]: drag-finish lost-owner-copy The following diff leaves out the additional import statements === hook added to clipboardCut, clipboardCopy return === diff --git a/CustomerViewer/src/org/customer/viewer/CustomerNode.java b/CustomerViewer/src/org/customer/viewer/CustomerNode.java @@ -69,7 +73,7 @@ return getLookup().lookup(Customer.class); } }); - return added; + return hook(added, "cut"); } @Override @@ -82,7 +86,20 @@ return getLookup().lookup(Customer.class); } }); - return added; + return hook(added, "copy"); } - + + private static final Logger LOG = Logger.getLogger("debug"); + private ExTransferable hook(ExTransferable t, String tag) { + LOG.info(()->"hook-"+tag+": "+t); + t.addTransferListener(new TransferListener() { + void fin(String s) { + LOG.info(()->"drag-finish " + s + tag); + } + @Override public void accepted(int action) { fin("accepted-"); } + @Override public void rejected() { fin("rejected-"); } + @Override public void ownershipLost() { fin("lost-owner-"); } + }); + return t; + } } Product Version: NetBeans IDE 8.0.2 (Build 201411181905) Java: 1.8.0_40; Java HotSpot(TM) 64-Bit Server VM 25.40-b25 Runtime: Java(TM) SE Runtime Environment 1.8.0_40-b26 System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb)
Also fails in dev build Product Version: NetBeans IDE Dev (Build 20150401-09512dd8aa7b) Updates: Updates available Java: 1.8.0_40; Java HotSpot(TM) 64-Bit Server VM 25.40-b25 Runtime: Java(TM) SE Runtime Environment 1.8.0_40-b26 System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb)
The listener is useless and very ancient IMO, i have found no usage of it throughout NB codebase. I don't even know when accepted/rejected should be called, do you? Should it be called when you drag over a node that accepts/does not accept the drop? Or should it be called when the user releases mouse over drop target? Any opinion? Maybe the best fix is to remove the note from the JavaDoc?
I favor removing the note from JavaDoc :-)
(In reply to Ondrej Vrabec from comment #2) > Should it be called when you drag over a node that > accepts/does not accept the drop? Or should it be called when the user > releases mouse over drop target? Any opinion? I assumed it would be notified at mouse release. > > Maybe the best fix is to remove the note from the JavaDoc? I have done little UI programming, I'm not sure of the utility. If it is removed, then there are several things that should be deprecated; for example ExTransferable.addTransferListener(TransferListener l) and possibly TransferListener
Now the only method in TransferListener that makes sense and works is "ownershipLost". That is called when content of the clipboard is released (i think). So what i'm suggesting is: 1) removing the note from Node's JavaDoc 2) deprecate accepted, rejected methods in TransferableListener with a note that they're useless anyway.