aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUpload.java
diff options
context:
space:
mode:
Diffstat (limited to 'uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUpload.java')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUpload.java45
1 files changed, 42 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";