InvalidDnDOperationException: No drop current in Java Version 1.6
843806Feb 6 2009 — edited Apr 11 2009Hello,
I'm trying a paste of a file list that comes from a native application, a filemanager.
In my TransferHandler's can import method, I check the DataFlavor to reject non-files. If that check is passed, we obtain the file list from the Transferable and check the actual file names for the proper extension. If the extension doesn't match, canImport rejects the Transferable by returning false. So far, so good and it works as expected for the drag-over behaviour. The mouse icon shows whether the file can be dropped or not. However, the moment I release the mouse button to initiate a drop action, the canImport method is called once more and that invocation fails with an "InvalidDnDOperationException: No drop current" exception at the point where the file list is obtained from the Transferable. Googling a bit hinted that getting data from the Transferable isn't allowed until the drop is accepted by calling event.acceptDrop() in the proper listener. That, however, is something that's hidden from me deep inside the Swing code and I would rather keep it that way. Nevertheless, I took a peek and found that there's indeed code down there that first checks the TransferHandler's canImport and - if that calls gives the ok - calls the acceptDrop. Sounds reasonable: only accept it if it can be imported. But it apparently leads to a catch-22 situation: in our case, canImport can only validate the data if its accepted first, but to accept it, it must be validated. I have the feeling I'm missing something.
Do you have a suggestion?
Thanks,
Felix
Btw, the link in my last message was pointing to the blog of "Shannon Hickey is Technical Lead for the Swing team at Sun Microsystems". I though this was credit enough to link to the question, instead of copying it over here. Sorry if that isn't recommended and leads to INSTANT blocking of a Thread.