Asynchronous drag n drop
I found the following comments in the java Drag-n-Drop tutorial:
<br /> //A real application would load the file in another<br /> //thread in order to not block the UI. This step<br /> //was omitted here to simplify the code.
However, I have tried to do exactly that and it does not seem possible. I doubt the person who wrote this comment actually tried moving the import into another thread.
It seems like Transferable.getTransferData() works OK when I call it within TransferHandler.importData(JComponent c, Transferable t), but when I try to make importData() a non-blocking method (i.e., perform the import by launching another thread), then I always end up with the following exception:
<br /> java.awt.dnd.InvalidDnDOperationException: No drop current<br /> at sun.awt.dnd.SunDropTargetContextPeer.getTransferData(SunDropTargetContextPeer.java:210)<br /> at sun.awt.datatransfer.TransferableProxy.getTransferData(TransferableProxy.java:56)<br /> at java.awt.dnd.DropTargetContext$TransferableProxy.getTransferData(DropTargetContext.java:359)
I think this exception makes sense. It is saying that when user drops something, we need to handle it at that moment. It implies that we cannot wait an arbitrarily long time (like days or weeks) before we handle the drop.
(1) is Transferable.getTransferData() a long-running task?
(2) If the answer to (1) is yes, then how do I call getTransferData() without blocking the EDT thread?