From: Mathieu Baudier Date: Thu, 24 Oct 2019 08:22:49 +0000 (+0200) Subject: File drop callbacks throw IOException. X-Git-Tag: argeo-commons-2.1.81~2 X-Git-Url: https://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=commitdiff_plain;h=b837ab75edc9c3ce9bf0ce63ea44b0f41d6e1049 File drop callbacks throw IOException. --- diff --git a/org.argeo.cms.ui/src/org/argeo/cms/ui/fs/FileDrop.java b/org.argeo.cms.ui/src/org/argeo/cms/ui/fs/FileDrop.java index be36a4629..d50b8d84d 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/ui/fs/FileDrop.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/ui/fs/FileDrop.java @@ -1,5 +1,6 @@ package org.argeo.cms.ui.fs; +import java.io.IOException; import java.io.InputStream; import org.apache.commons.logging.Log; @@ -17,10 +18,10 @@ public class FileDrop { public void createDropTarget(Control control) { FileDropAdapter fileDropAdapter = new FileDropAdapter() { @Override - protected void processUpload(InputStream in, String fileName, String contentType) { + protected void processUpload(InputStream in, String fileName, String contentType) throws IOException { if (log.isDebugEnabled()) log.debug("Process upload of " + fileName + " (" + contentType + ")"); - processUpload(in, fileName, contentType); + processFileUpload(in, fileName, contentType); } }; DropTarget dropTarget = new DropTarget(control, DND.DROP_MOVE | DND.DROP_COPY); @@ -31,7 +32,7 @@ public class FileDrop { } /** Executed in UI thread */ - protected void processUpload(InputStream in, String fileName, String contentType) { + protected void processFileUpload(InputStream in, String fileName, String contentType) throws IOException { } } diff --git a/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/FileDropAdapter.java b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/FileDropAdapter.java index 87d0e00c9..f9ca81682 100644 --- a/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/FileDropAdapter.java +++ b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/FileDropAdapter.java @@ -17,6 +17,7 @@ import org.eclipse.swt.dnd.DropTargetEvent; import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.widgets.Control; +/** Configures a {@link Control} to receive files drop from the client OS. */ public class FileDropAdapter { public void prepareDropTarget(Control control, DropTarget dropTarget) { @@ -46,8 +47,13 @@ public class FileDropAdapter { @Override public void receive(InputStream stream, FileDetails details) throws IOException { - control.getDisplay() - .syncExec(() -> processUpload(stream, details.getFileName(), details.getContentType())); + control.getDisplay().syncExec(() -> { + try { + processUpload(stream, details.getFileName(), details.getContentType()); + } catch (IOException e) { + throw new IllegalStateException("Cannot process upload of " + details.getFileName(), e); + } + }); } }; FileUploadHandler handler = new FileUploadHandler(receiver); @@ -60,7 +66,7 @@ public class FileDropAdapter { } /** Executed in UI thread */ - protected void processUpload(InputStream in, String fileName, String contentType) { + protected void processUpload(InputStream in, String fileName, String contentType) throws IOException { }