aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/dnd
diff options
context:
space:
mode:
Diffstat (limited to 'uitest/src/main/java/com/vaadin/tests/dnd')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUpload.java45
-rw-r--r--uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUploadWithManualPush.java12
-rw-r--r--uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUploadWithPush.java8
3 files changed, 62 insertions, 3 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUpload.java b/uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUpload.java
index 53264a760d..6189cf5eaf 100644
--- a/uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUpload.java
+++ b/uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUpload.java
@@ -4,15 +4,18 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
import com.vaadin.server.StreamVariable;
import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.ui.dnd.FileParameters;
import com.vaadin.shared.ui.grid.DropMode;
import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.Button;
import com.vaadin.ui.Grid;
-import com.vaadin.ui.Layout;
import com.vaadin.ui.Notification;
+import com.vaadin.ui.ProgressBar;
+import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.components.grid.GridDropTarget;
import com.vaadin.ui.dnd.FileDropTarget;
@@ -21,6 +24,16 @@ public class Html5FileDragAndDropUpload extends AbstractTestUIWithLog {
private static final int FILE_SIZE_LIMIT = 1024 * 1024 * 5; // 5 MB
+ private final boolean pushManually;
+
+ public Html5FileDragAndDropUpload() {
+ this(false);
+ }
+
+ public Html5FileDragAndDropUpload(boolean pushManually) {
+ this.pushManually = pushManually;
+ }
+
@Override
protected void setup(VaadinRequest request) {
@@ -31,6 +44,9 @@ public class Html5FileDragAndDropUpload extends AbstractTestUIWithLog {
grid.addColumn(FileParameters::getMime).setCaption("Mime type");
List<FileParameters> gridItems = new ArrayList<>();
+ AtomicBoolean cancelled = new AtomicBoolean(false);
+
+ ProgressBar progressBar = new ProgressBar(0.0f);
new FileDropTarget<Grid<FileParameters>>(grid,
event -> event.getFiles().forEach(html5File -> {
@@ -39,6 +55,7 @@ public class Html5FileDragAndDropUpload extends AbstractTestUIWithLog {
+ " is too large (max 5 MB)");
return;
}
+ UI.getCurrent().setPollInterval(200);
html5File.setStreamVariable(new StreamVariable() {
@Override
@@ -58,19 +75,27 @@ public class Html5FileDragAndDropUpload extends AbstractTestUIWithLog {
@Override
public void onProgress(StreamingProgressEvent event) {
+ float progress = (float) event.getBytesReceived()
+ / event.getContentLength();
+ progressBar.setValue(progress);
log("Progress, bytesReceived="
+ event.getBytesReceived());
+ pushIfManual();
}
@Override
public void streamingStarted(
StreamingStartEvent event) {
+ cancelled.set(false);
+ progressBar.setValue(0.0f);
log("Stream started, fileName="
+ event.getFileName());
+ pushIfManual();
}
@Override
public void streamingFinished(StreamingEndEvent event) {
+ progressBar.setValue(1.0f);
gridItems
.add(new FileParameters(event.getFileName(),
event.getContentLength(),
@@ -79,17 +104,22 @@ public class Html5FileDragAndDropUpload extends AbstractTestUIWithLog {
log("Stream finished, fileName="
+ event.getFileName());
+ pushIfManual();
+ UI.getCurrent().setPollInterval(-1);
}
@Override
public void streamingFailed(StreamingErrorEvent event) {
+ progressBar.setValue(0.0f);
log("Stream failed, fileName="
+ event.getFileName());
+ pushIfManual();
+ UI.getCurrent().setPollInterval(-1);
}
@Override
public boolean isInterrupted() {
- return false;
+ return cancelled.get();
}
});
}));
@@ -101,11 +131,20 @@ public class Html5FileDragAndDropUpload extends AbstractTestUIWithLog {
Notification.show(event.getDataTransferText());
});
- Layout layout = new VerticalLayout(grid);
+ Button cancelButton = new Button("Cancel",
+ click -> cancelled.set(true));
+ VerticalLayout layout = new VerticalLayout(grid, cancelButton,
+ progressBar);
addComponent(layout);
}
+ private void pushIfManual() {
+ if (pushManually) {
+ push();
+ }
+ }
+
@Override
protected String getTestDescription() {
return "Drop files onto the Grid to upload them or text";
diff --git a/uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUploadWithManualPush.java b/uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUploadWithManualPush.java
new file mode 100644
index 0000000000..22b63aacb2
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUploadWithManualPush.java
@@ -0,0 +1,12 @@
+package com.vaadin.tests.dnd;
+
+import com.vaadin.annotations.Push;
+import com.vaadin.shared.communication.PushMode;
+
+@Push(PushMode.MANUAL)
+public class Html5FileDragAndDropUploadWithManualPush
+ extends Html5FileDragAndDropUpload {
+ public Html5FileDragAndDropUploadWithManualPush() {
+ super(true);
+ }
+}
diff --git a/uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUploadWithPush.java b/uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUploadWithPush.java
new file mode 100644
index 0000000000..9425a05c5b
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUploadWithPush.java
@@ -0,0 +1,8 @@
+package com.vaadin.tests.dnd;
+
+import com.vaadin.annotations.Push;
+
+@Push
+public class Html5FileDragAndDropUploadWithPush
+ extends Html5FileDragAndDropUpload {
+}