Skip to content

Conversation

imagejan
Copy link
Member

@imagejan imagejan requested a review from stelfrich February 16, 2018 13:11
Copy link
Member

@stelfrich stelfrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Augmenting the script from imagej/imagej-legacy#178 with a file filter (#@File(style="extensions:tif/png") file") reveals that canImport() actually works. At least on Windows 10 and Ubuntu 16.04 you are not able to drop a file with a different extension, meaning that the filter is applied in practice. Hence, I tried to catch the java.awt.dnd.InvalidDnDOperationException and return true;: everything works as expected. The Java API says:

Upon a drop, canImport is called one final time before calling into importData.

This final call seems to throw the exception while all the calls before succeed. I also stumbled over this thread that somewhat supports my findings: https://coderanch.com/t/664525/java/Invalid-Drag-Drop-Exception

The changes to accept pasted Strings looks good to me!

@imagejan
Copy link
Member Author

Thanks a lot, @stelfrich, for investigating! That's very helpful. I'll make the suggested changes to catch the exception, and then update this PR.

@imagejan imagejan force-pushed the fix-file-drag-n-drop branch from bc18ecb to ec81c06 Compare February 21, 2018 09:38
On Windows, trying to get the TransferData during canImport() throws an InvalidDnDOperationException.
Since we know the exception is coming, let's catch and ignore it.

See: https://coderanch.com/t/664525/java/Invalid-Drag-Drop-Exception

Thanks Stefan Helfrich for investigating.
This restores the ability to paste text into the JTextField of SwingFileWidget. Before this change, the custom TransferHandler did not accept String values.
Now we try to get a File value first, and fall back to getting the String value of the current transfer operation.

I also tried to restore the full default Copy/Cut/Paste functionality by calling super.importData(support), but couldn't get it to work. So let's stay with some minimal Paste functionality at least.
@imagejan imagejan force-pushed the fix-file-drag-n-drop branch from ec81c06 to 26ab4d8 Compare February 21, 2018 09:47
@imagejan
Copy link
Member Author

I updated the branch to now catch the InvalidDnDOperationException during import. Thanks again, @stelfrich, for your help with this.

@stelfrich
Copy link
Member

Looks good and works as expected in my tests. I'd say this is ready to be merged, @ctrueden.

@ctrueden ctrueden merged commit d0802b1 into master Feb 21, 2018
@ctrueden ctrueden deleted the fix-file-drag-n-drop branch February 21, 2018 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants