List of usage examples for com.vaadin.ui Upload.SucceededListener Upload.SucceededListener
Upload.SucceededListener
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);// www.jav a2 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); } }); }
From source file:org.bubblecloud.ilves.module.content.AssetFlowlet.java
License:Apache License
@Override public void initialize() { entityManager = getSite().getSiteContext().getObject(EntityManager.class); final GridLayout gridLayout = new GridLayout(1, 3); gridLayout.setSizeFull();//from w w w .j av a2 s.c o m gridLayout.setMargin(false); gridLayout.setSpacing(true); gridLayout.setRowExpandRatio(1, 1f); setViewContent(gridLayout); assetEditor = new ValidatingEditor( FieldSetDescriptorRegister.getFieldSetDescriptor(Asset.class).getFieldDescriptors()); assetEditor.setCaption("Asset"); assetEditor.addListener(this); gridLayout.addComponent(assetEditor, 0, 1); final Upload upload = new Upload(getSite().localize("field-file-upload"), new Upload.Receiver() { @Override public OutputStream receiveUpload(String filename, String mimeType) { try { temporaryFile = File.createTempFile(entity.getAssetId(), ".upload"); return new FileOutputStream(temporaryFile, false); } catch (IOException e) { throw new SiteException("Unable to create temporary file for upload.", e); } } }); upload.setButtonCaption(getSite().localize("button-start-upload")); upload.addSucceededListener(new Upload.SucceededListener() { @Override public void uploadSucceeded(Upload.SucceededEvent event) { if (event.getLength() == 0) { return; } if (temporaryFile.length() > Long .parseLong(PropertiesUtil.getProperty("site", "asset-maximum-size"))) { Notification.show(getSite().localize("message-file-too-large"), Notification.Type.ERROR_MESSAGE); return; } entity.setName(event.getFilename().substring(0, event.getFilename().lastIndexOf('.'))); entity.setExtension(event.getFilename().substring(event.getFilename().lastIndexOf('.') + 1)); entity.setType(event.getMIMEType()); entity.setSize((int) event.getLength()); assetEditor.setItem(new BeanItem<Asset>(entity), assetEditor.isNewItem()); save(); } }); gridLayout.addComponent(upload, 0, 0); final HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true); gridLayout.addComponent(buttonLayout, 0, 2); saveButton = getSite().getButton("save"); buttonLayout.addComponent(saveButton); saveButton.addClickListener(new ClickListener() { /** Serial version UID. */ private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { if (isValid()) { save(); } else { Notification.show(getSite().localize("message-invalid-form-asset"), Notification.Type.HUMANIZED_MESSAGE); } } }); discardButton = getSite().getButton("discard"); buttonLayout.addComponent(discardButton); discardButton.addClickListener(new ClickListener() { /** Serial version UID. */ private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { assetEditor.discard(); if (temporaryFile != null) { temporaryFile.deleteOnExit(); temporaryFile = null; } } }); editPrivilegesButton = getSite().getButton("edit-privileges"); buttonLayout.addComponent(editPrivilegesButton); editPrivilegesButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { final PrivilegesFlowlet privilegesFlowlet = getFlow().getFlowlet(PrivilegesFlowlet.class); privilegesFlowlet.edit(entity.getName(), entity.getAssetId(), "view", "edit"); getFlow().forward(PrivilegesFlowlet.class); } }); }