Example usage for com.vaadin.ui Upload addFailedListener

List of usage examples for com.vaadin.ui Upload addFailedListener

Introduction

In this page you can find the example usage for com.vaadin.ui Upload addFailedListener.

Prototype

public Registration addFailedListener(FailedListener listener) 

Source Link

Document

Adds the upload interrupted event listener.

Usage

From source file:org.hip.vif.web.util.UploadComponent.java

License:Open Source License

private Upload createUpload(final IBibliographyTask inTask) {
    final Upload outUpload = new Upload();
    outUpload.setWidthUndefined();/*from w  w  w .  j ava 2s.c o m*/
    outUpload.setReceiver(new Upload.Receiver() {
        @Override
        public OutputStream receiveUpload(final String inFilename, // NOPMD
                final String inMimeType) {
            return createStream(inFilename);
        }
    });

    final String lCaption = Activator.getMessages().getMessage("ui.upload.button.lbl"); //$NON-NLS-1$
    outUpload.setButtonCaption(lCaption);
    outUpload.setImmediate(true);
    outUpload.setStyleName("vif-upload"); //$NON-NLS-1$

    outUpload.addStartedListener(new Upload.StartedListener() {
        @Override
        public void uploadStarted(final StartedEvent inEvent) { // NOPMD
            fileInfo = new FileInfo(inEvent.getFilename(), inEvent.getMIMEType());
            tempUpload = null; // NOPMD
            uploadFinished = false;
            outUpload.setVisible(false);
            if (hasDownloads) {
                dialog.setVisible(true); // FF
            }
        }
    });
    outUpload.addFinishedListener(new Upload.FinishedListener() {
        @Override
        public void uploadFinished(final FinishedEvent inEvent) { // NOPMD
            uploadFinished = true;
            outUpload.setVisible(true);
        }
    });
    outUpload.addSucceededListener(new Upload.SucceededListener() {
        @Override
        public void uploadSucceeded(final SucceededEvent inEvent) { // NOPMD
            if (!hasDownloads) {
                handleUpload(inTask, false);
            }
        }
    });
    outUpload.addFailedListener(new Upload.FailedListener() {
        @Override
        public void uploadFailed(final FailedEvent inEvent) { // NOPMD
            handleDeleteTemp();
        }
    });

    return outUpload;
}

From source file:views.BatchUpload.java

License:Open Source License

public BatchUpload() {
    setMargin(true);/*ww  w. j  a v a2 s .  com*/
    setSpacing(true);

    // file upload component
    Upload upload = new Upload("Upload your file here", uploader);
    addComponent(this.upload);
    upload.setEnabled(false);

    // sample registration button
    register = new Button("Register People");
    register.setVisible(false);
    addComponent(register);

    upload.setButtonCaption("Upload");
    // Listen for events regarding the success of upload.
    upload.addFailedListener(uploader);
    upload.addSucceededListener(uploader);
    FinishedListener uploadFinListener = new FinishedListener() {
        /**
         * 
         */
        private static final long serialVersionUID = -8413963075202260180L;

        public void uploadFinished(FinishedEvent event) {
            String uploadError = uploader.getError();
            File file = uploader.getFile();
            if (file.getPath().endsWith("up_")) {
                String msg = "No file selected.";
                logger.warn(msg);
                Styles.notification("Failed to read file.", msg, NotificationType.ERROR);
                if (!file.delete())
                    logger.error("uploaded tmp file " + file.getAbsolutePath() + " could not be deleted!");
            } else {
                if (uploadError == null || uploadError.isEmpty()) {
                    String msg = "Upload successful!";
                    logger.info(msg);
                    //            try {
                    setRegEnabled(false);
                    SQLBatchParser parser = new SQLBatchParser();
                    if (parser.processTSV()) {
                        // TODO = prep.getObjects();
                        Styles.notification("Upload successful",
                                "New people information successfully uploaded and read.",
                                NotificationType.SUCCESS);
                    } else {
                        String error = parser.getError();
                        Styles.notification("Failed to read file.", error, NotificationType.ERROR);
                        if (!file.delete())
                            logger.error(
                                    "uploaded tmp file " + file.getAbsolutePath() + " could not be deleted!");
                    }
                    //            } catch (IOException e) {
                    //              e.printStackTrace();
                    //            }
                } else {
                    Styles.notification("Failed to upload file.", uploadError, NotificationType.ERROR);
                    if (!file.delete())
                        logger.error("uploaded tmp file " + file.getAbsolutePath() + " could not be deleted!");
                }
            }
        }
    };
    upload.addFinishedListener(uploadFinListener);
    // view.initUpload(upload);

    Button.ClickListener cl = new Button.ClickListener() {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        /**
         * 
         */

        @Override
        public void buttonClick(ClickEvent event) {
            String src = event.getButton().getCaption();
            if (src.equals("Register People")) {
                register.setEnabled(false);
            }
        }
    };
    register.addClickListener(cl);
}