summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Wagner <wbadam@users.noreply.github.com>2017-05-11 16:49:19 +0300
committerPekka Hyvönen <pekka@vaadin.com>2017-05-11 16:49:19 +0300
commitbda8acb85610f1532b9f11a8a9530c694051c2d9 (patch)
treec541bf0a3a12989e12c8a840bb001c671f77ab4a
parent8591ce8debbdd56c0f52b9fcca4346922282d5f7 (diff)
downloadvaadin-framework-bda8acb85610f1532b9f11a8a9530c694051c2d9.tar.gz
vaadin-framework-bda8acb85610f1532b9f11a8a9530c694051c2d9.zip
Poll server for changes at the end of each file upload (#9300)
* Poll server for changes at the end of each file upload
-rw-r--r--client/src/main/java/com/vaadin/client/extensions/FileDropTargetConnector.java2
-rw-r--r--server/src/main/java/com/vaadin/ui/FileDropTarget.java34
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/dnd/FileDropTargetRpc.java5
3 files changed, 28 insertions, 13 deletions
diff --git a/client/src/main/java/com/vaadin/client/extensions/FileDropTargetConnector.java b/client/src/main/java/com/vaadin/client/extensions/FileDropTargetConnector.java
index f496e90d7f..df236b6072 100644
--- a/client/src/main/java/com/vaadin/client/extensions/FileDropTargetConnector.java
+++ b/client/src/main/java/com/vaadin/client/extensions/FileDropTargetConnector.java
@@ -90,6 +90,8 @@ public class FileDropTargetConnector extends DropTargetExtensionConnector {
FileUploadXHR xhr = (FileUploadXHR) FileUploadXHR.create();
xhr.setOnReadyStateChange(xmlHttpRequest -> {
if (xmlHttpRequest.getReadyState() == XMLHttpRequest.DONE) {
+ // Poll server for changes
+ getRpcProxy(FileDropTargetRpc.class).poll();
uploading = false;
uploadNextFile();
xmlHttpRequest.clearOnReadyStateChange();
diff --git a/server/src/main/java/com/vaadin/ui/FileDropTarget.java b/server/src/main/java/com/vaadin/ui/FileDropTarget.java
index 654563dbd0..831d6723d9 100644
--- a/server/src/main/java/com/vaadin/ui/FileDropTarget.java
+++ b/server/src/main/java/com/vaadin/ui/FileDropTarget.java
@@ -30,6 +30,7 @@ import com.vaadin.shared.ApplicationConstants;
import com.vaadin.shared.ui.dnd.FileDropTargetClientRpc;
import com.vaadin.shared.ui.dnd.FileDropTargetRpc;
import com.vaadin.shared.ui.dnd.FileDropTargetState;
+import com.vaadin.shared.ui.dnd.FileParameters;
/**
* Extension to add drop target functionality to a widget for accepting and
@@ -68,24 +69,31 @@ public class FileDropTarget<T extends AbstractComponent> extends
protected void registerDropTargetRpc(T target) {
super.registerDropTargetRpc(target);
- registerRpc((FileDropTargetRpc) fileParams -> {
+ registerRpc(new FileDropTargetRpc() {
+ @Override
+ public void drop(Map<String, FileParameters> fileParams) {
+ List<Html5File> files = new ArrayList<>();
+ Map<String, String> urls = new HashMap<>();
- List<Html5File> files = new ArrayList<>();
- Map<String, String> urls = new HashMap<>();
+ fileParams.forEach((id, fileParameters) -> {
+ Html5File html5File = new Html5File(fileParameters.getName(),
+ fileParameters.getSize(), fileParameters.getMime());
+ String url = createUrl(html5File, id);
- fileParams.forEach((id, fileParameters) -> {
- Html5File html5File = new Html5File(fileParameters.getName(),
- fileParameters.getSize(), fileParameters.getMime());
- String url = createUrl(html5File, id);
+ files.add(html5File);
+ urls.put(id, url);
+ });
- files.add(html5File);
- urls.put(id, url);
- });
+ getRpcProxy(FileDropTargetClientRpc.class).sendUploadUrl(urls);
- getRpcProxy(FileDropTargetClientRpc.class).sendUploadUrl(urls);
+ FileDropEvent<T> event = new FileDropEvent<>(target, files);
+ fileDropHandler.drop(event);
+ }
- FileDropEvent<T> event = new FileDropEvent<>(target, files);
- fileDropHandler.drop(event);
+ @Override
+ public void poll() {
+ // Polling server for changes after upload finished
+ }
});
}
diff --git a/shared/src/main/java/com/vaadin/shared/ui/dnd/FileDropTargetRpc.java b/shared/src/main/java/com/vaadin/shared/ui/dnd/FileDropTargetRpc.java
index fd290a41f5..521f3ec7e6 100644
--- a/shared/src/main/java/com/vaadin/shared/ui/dnd/FileDropTargetRpc.java
+++ b/shared/src/main/java/com/vaadin/shared/ui/dnd/FileDropTargetRpc.java
@@ -34,4 +34,9 @@ public interface FileDropTargetRpc extends ServerRpc {
* Generated file IDs and file parameters of dropped files.
*/
public void drop(Map<String, FileParameters> fileParams);
+
+ /**
+ * Called to poll the server for changes when the upload is complete.
+ */
+ public void poll();
}