List of usage examples for com.vaadin.ui Upload.ProgressListener Upload.ProgressListener
Upload.ProgressListener
From source file:edu.nps.moves.mmowgli.modules.actionplans.UploadHandler.java
License:Open Source License
@SuppressWarnings("serial") public UploadHandler(Upload upld, UploadStatus panel, String savePath) { this.upload = upld; this.savePath = savePath; this.window = panel; new File(savePath).mkdirs(); upload.addStartedListener(new Upload.StartedListener() { public void uploadStarted(StartedEvent event) { // this method gets called immediately after upload is started window.pi.setValue(0f);/* w ww . j a va2 s . co m*/ window.pi.setVisible(true); window.textualProgress.setVisible(true); // updates to client window.state.setValue("Uploading"); window.fileName.setValue(event.getFilename()); window.cancelProcessing.setVisible(true); } }); upload.addProgressListener(new Upload.ProgressListener() { public void updateProgress(long readBytes, long contentLength) { // this method gets called several times during the update if (readBytes > MAXUPLOADSIZE) { window.textualProgress.setValue("Upload failed: " + MAXUPLOADSTRING + " limit"); upload.interruptUpload(); window.pi.setVisible(false); } else { window.pi.setValue(new Float(readBytes / (float) contentLength)); window.textualProgress.setValue("Processed " + readBytes + " bytes of " + contentLength); window.result.setValue(counter + " (counting...)"); } } }); upload.addSucceededListener(new Upload.SucceededListener() { public void uploadSucceeded(SucceededEvent event) { window.result.setValue(counter + " (total)"); } }); upload.addFailedListener(new Upload.FailedListener() { public void uploadFailed(FailedEvent event) { window.result.setValue(counter + " (upload interrupted at " + Math.round(100 * (Float) window.pi.getValue()) + "%)"); finalFullFilePath = null; // indicate error } }); upload.addFinishedListener(new Upload.FinishedListener() { public void uploadFinished(FinishedEvent event) { window.state.setValue("Finished"); // window.pi.setVisible(false); // window.textualProgress.setVisible(false); window.cancelProcessing.setVisible(false); } }); }