Refactor File DnD (and assume that "java.io.IOException: Owner failed to convert data" is normal during the DnD process and can be ignored)

This commit is contained in:
Reinhard Pointner 2019-02-17 19:12:27 +07:00
parent 9fb947bbfd
commit acd1f0fa64
1 changed files with 16 additions and 16 deletions

View File

@ -89,22 +89,6 @@ public class FileTransferable implements Transferable {
return isFileListFlavor(flavor);
}
public static <T> T getTransferData(Transferable tr, DataFlavor flavor, Class<T> type) throws IOException, UnsupportedFlavorException, InvalidDnDOperationException {
Object transferData;
try {
transferData = tr.getTransferData(flavor);
} catch (IOException e) {
// java.io.IOException: Owner failed to convert data
throw new InvalidDnDOperationException(e.getMessage());
}
if (transferData != null && type.isInstance(transferData)) {
return type.cast(transferData);
}
return null;
}
public static List<File> getFilesFromTransferable(Transferable tr) throws IOException, UnsupportedFlavorException {
// On Linux, if a file is dragged from a smb share to into a java application (e.g. Ubuntu Files to FileBot)
// the application/x-java-file-list transfer data will be an empty list
@ -165,4 +149,20 @@ public class FileTransferable implements Transferable {
throw new UnsupportedFlavorException(DataFlavor.javaFileListFlavor);
}
private static <T> T getTransferData(Transferable tr, DataFlavor flavor, Class<T> type) throws IOException, UnsupportedFlavorException, InvalidDnDOperationException {
Object transferData;
try {
transferData = tr.getTransferData(flavor);
} catch (IOException e) {
// java.io.IOException: Owner failed to convert data
throw new InvalidDnDOperationException(e.getMessage());
}
if (transferData != null && type.isInstance(transferData)) {
return type.cast(transferData);
}
return null;
}
}