diff options
author | Adam Wagner <wbadam@users.noreply.github.com> | 2017-05-11 22:49:19 +0300 |
---|---|---|
committer | Pekka Hyvönen <pekka@vaadin.com> | 2017-05-11 22:49:19 +0300 |
commit | 494b90a81cdd7dfc2fb337676e51ffa4bdd6ea43 (patch) | |
tree | e3196df0dad644a3b6930575205b26cb36ff91cf /uitest | |
parent | bda8acb85610f1532b9f11a8a9530c694051c2d9 (diff) | |
download | vaadin-framework-494b90a81cdd7dfc2fb337676e51ffa4bdd6ea43.tar.gz vaadin-framework-494b90a81cdd7dfc2fb337676e51ffa4bdd6ea43.zip |
Create upload URLs only when stream variable is attached by drop handler (#9301)
* Create upload URLs only when stream variable is attached by drop handler
* Add file size limit to test ui and remove label drop target
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUpload.java | 87 |
1 files changed, 19 insertions, 68 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 211d50d047..c01e0293c1 100644 --- a/uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUpload.java +++ b/uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUpload.java @@ -29,75 +29,17 @@ import com.vaadin.ui.Grid; import com.vaadin.ui.Html5File; import com.vaadin.ui.Label; import com.vaadin.ui.Layout; +import com.vaadin.ui.Notification; import com.vaadin.ui.VerticalLayout; public class Html5FileDragAndDropUpload extends AbstractTestUIWithLog { + private static final int FILE_SIZE_LIMIT = 1024 * 1024 * 5; // 5 MB + @Override protected void setup(VaadinRequest request) { - Label dropArea = new Label("Drop files here"); - - FileDropTarget<Label> dropTarget = new FileDropTarget<>(dropArea, - event -> { - List<Html5File> files = event.getFiles(); - if (files != null) { - files.forEach(file -> { - file.setStreamVariable(new StreamVariable() { - @Override - public OutputStream getOutputStream() { - return new OutputStream() { - @Override - public void write(int b) throws - IOException { - // NOP - } - }; - } - - @Override - public boolean listenProgress() { - return true; - } - - @Override - public void onProgress( - StreamingProgressEvent event) { - log("Progress, bytesReceived=" + event - .getBytesReceived()); - } - - @Override - public void streamingStarted( - StreamingStartEvent event) { - log("Stream started, fileName=" + event - .getFileName()); - } - - @Override - public void streamingFinished( - StreamingEndEvent event) { - log("Stream finished, fileName=" + event - .getFileName()); - } - - @Override - public void streamingFailed( - StreamingErrorEvent event) { - log("Stream failed, fileName=" + event - .getFileName()); - } - - @Override - public boolean isInterrupted() { - return false; - } - }); - }); - } - }); - - Grid<FileParameters> grid = new Grid<>(); + Grid<FileParameters> grid = new Grid<>("Drop files on the Grid"); grid.addColumn(FileParameters::getName).setCaption("File name"); grid.addColumn(FileParameters::getSize).setCaption("File size"); grid.addColumn(FileParameters::getMime).setCaption("Mime type"); @@ -106,6 +48,12 @@ public class Html5FileDragAndDropUpload extends AbstractTestUIWithLog { new FileDropTarget<Grid<FileParameters>>(grid, event -> { event.getFiles().forEach(html5File -> { + if (html5File.getFileSize() > FILE_SIZE_LIMIT) { + Notification.show(html5File.getFileName() + + " is too large (max 5 MB)"); + return; + } + html5File.setStreamVariable(new StreamVariable() { @Override public OutputStream getOutputStream() { @@ -119,17 +67,18 @@ public class Html5FileDragAndDropUpload extends AbstractTestUIWithLog { @Override public boolean listenProgress() { - return false; + return true; } @Override public void onProgress(StreamingProgressEvent event) { - // NOP + log("Progress, bytesReceived=" + event + .getBytesReceived()); } @Override public void streamingStarted(StreamingStartEvent event) { - // NOP + log("Stream started, fileName=" + event.getFileName()); } @Override @@ -137,11 +86,13 @@ public class Html5FileDragAndDropUpload extends AbstractTestUIWithLog { gridItems.add(new FileParameters(event.getFileName(), event.getContentLength(), event.getMimeType())); grid.setItems(gridItems); + + log("Stream finished, fileName=" + event.getFileName()); } @Override public void streamingFailed(StreamingErrorEvent event) { - + log("Stream failed, fileName=" + event.getFileName()); } @Override @@ -152,13 +103,13 @@ public class Html5FileDragAndDropUpload extends AbstractTestUIWithLog { }); }); - Layout layout = new VerticalLayout(dropArea, grid); + Layout layout = new VerticalLayout(grid); addComponent(layout); } @Override protected String getTestDescription() { - return "Drop and upload files onto file drop target"; + return "Drop files onto the Grid to upload them"; } } |