Example usage for com.vaadin.ui Upload addSucceededListener

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

Introduction

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

Prototype

public Registration addSucceededListener(SucceededListener listener) 

Source Link

Document

Adds the upload success event listener.

Usage

From source file:org.ikasan.dashboard.ui.mappingconfiguration.window.MappingConfigurationValuesImportWindow.java

License:BSD License

/**
 * Helper method to initialise this object.
 *///from   ww w  .  ja  va 2 s .c  o  m
protected void init() {
    this.setModal(true);
    super.setHeight(40.0f, Unit.PERCENTAGE);
    super.setWidth(40.0f, Unit.PERCENTAGE);
    super.center();
    super.setStyleName("ikasan");

    progressLayout.setSpacing(true);
    progressLayout.setVisible(false);
    progressLayout.addComponent(uploadLabel);

    final Upload upload = new Upload("", receiver);
    upload.addSucceededListener(receiver);

    upload.addFinishedListener(new Upload.FinishedListener() {
        public void uploadFinished(FinishedEvent event) {
            upload.setVisible(false);
            parseUploadFile();
        }
    });

    final Button importButton = new Button("Import");
    importButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            upload.interruptUpload();
        }
    });

    upload.addStartedListener(new Upload.StartedListener() {
        public void uploadStarted(StartedEvent event) {
            // This method gets called immediately after upload is started
            upload.setVisible(false);
        }
    });

    upload.addProgressListener(new Upload.ProgressListener() {
        public void updateProgress(long readBytes, long contentLength) {
            // This method gets called several times during the update

        }

    });

    importButton.setStyleName(ValoTheme.BUTTON_SMALL);
    importButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            try {
                saveImportedMappingConfigurationValues();

                IkasanAuthentication authentication = (IkasanAuthentication) VaadinService.getCurrentRequest()
                        .getWrappedSession().getAttribute(DashboardSessionValueConstants.USER);

                systemEventService.logSystemEvent(MappingConfigurationConstants.MAPPING_CONFIGURATION_SERVICE,
                        "Imported mapping configuration values for mapping configuration: [Client="
                                + mappingConfiguration.getConfigurationServiceClient().getName()
                                + "] [Source Context=" + mappingConfiguration.getSourceContext().getName()
                                + "] [Target Context=" + mappingConfiguration.getTargetContext().getName()
                                + "] [Type=" + mappingConfiguration.getConfigurationType().getName() + "]",
                        authentication.getName());

                logger.info("User: " + authentication.getName()
                        + " successfully imported the following Mapping Configuration: "
                        + mappingConfiguration);
            } catch (Exception e) {
                Notification.show(
                        "An error occurred trying to import a mapping configuration: " + e.getMessage(),
                        Notification.Type.ERROR_MESSAGE);
            }
            mappingConfigurationConfigurationValuesTable.populateTable(mappingConfiguration);
            close();
        }
    });

    progressLayout.addComponent(importButton);

    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.addComponent(new Label("Select file to upload mapping configurations."));
    layout.addComponent(upload);

    layout.addComponent(progressLayout);

    Button cancelButton = new Button("Cancel");
    cancelButton.setStyleName(ValoTheme.BUTTON_SMALL);

    cancelButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            close();
        }
    });

    HorizontalLayout hlayout = new HorizontalLayout();
    hlayout.addComponent(cancelButton);

    layout.addComponent(hlayout);

    super.setContent(layout);
}

From source file:org.jumpmind.vaadin.ui.common.ReadOnlyTextAreaDialog.java

License:Open Source License

private void buildUploadButton(String title, final String value) {
    final Button uploadButton = new Button("Upload");
    final Button viewTextButton = new Button("View Text");

    LobUploader lobUploader = new LobUploader();
    final Upload upload = new Upload("Upload new " + table.getColumnWithName(title).getMappedType(),
            lobUploader);//from   w  ww  .ja va  2s . c o m
    upload.addSucceededListener(lobUploader);

    uploadButton.addClickListener(new ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            wrapper.replaceComponent(textField, upload);
            wrapper.setComponentAlignment(upload, Alignment.MIDDLE_CENTER);
            buttonLayout.replaceComponent(uploadButton, viewTextButton);
        }
    });

    viewTextButton.addClickListener(new ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            wrapper.replaceComponent(upload, textField);
            wrapper.setComponentAlignment(textField, Alignment.TOP_LEFT);
            buttonLayout.replaceComponent(viewTextButton, uploadButton);
        }
    });

    if (value != null) {
        buttonLayout.addComponent(uploadButton);
        buttonLayout.setComponentAlignment(uploadButton, Alignment.BOTTOM_CENTER);
    } else {
        wrapper.replaceComponent(textField, upload);
        wrapper.setComponentAlignment(upload, Alignment.MIDDLE_CENTER);
    }
}

From source file:org.lunifera.vaaclipse.ui.preferences.addon.internal.impexp.ImportPreferences.java

License:Open Source License

@Override
public Component getComponent(OptionDialog optionDialog) {

    CssLayout layout = new CssLayout();
    layout.addStyleName("import");

    Upload upload = new Upload("Select file with preferences for upload", this);
    upload.setWidth("100%");
    upload.setButtonCaption("Upload");
    upload.addSucceededListener(this);
    layout.addComponent(upload);/*ww w  .j  a v  a 2  s.c  o  m*/

    layout.addComponent(new Label("Select preferences to import"));
    createPreferencesTable(layout, new ArrayList<PreferencesPage>());

    createStatusLabel(layout, "Choose file with preferences");

    return layout;
}

From source file:org.vaadin.tori.component.AuthoringComponent.java

License:Apache License

private Upload buildAttachUpload() {
    final Receiver receiver = new Receiver() {

        @Override/*from  w  w  w. j a  va2  s.  c  o m*/
        public OutputStream receiveUpload(final String filename, final String mimeType) {
            attachmentData = new ByteArrayOutputStream();
            attachmentFileName = filename;
            return attachmentData;
        }
    };

    final Upload attach = new Upload(null, receiver);
    attach.setButtonCaption("Add Attachment...");
    attach.setImmediate(true);
    attach.addSucceededListener(new Upload.SucceededListener() {

        @Override
        public void uploadSucceeded(final SucceededEvent event) {
            attachments.put(attachmentFileName, attachmentData.toByteArray());
            attachmentFileName = null;
            attachmentData = null;
            updateAttachmentList();
        }
    });

    attach.addStartedListener(new Upload.StartedListener() {
        @Override
        public void uploadStarted(final StartedEvent event) {
            if (maxFileSize > 0 && event.getContentLength() > maxFileSize) {
                attach.interruptUpload();
                Notification.show("File size too large");
                return;
            }
        }
    });
    return attach;
}

From source file:ui.button.AddCertificateButton.java

License:Apache License

public AddCertificateButton(final Integer userId, final String language, final Achievement a) {
    super(Translator.getTranslation("Add Certificate", language), FontAwesome.CERTIFICATE);
    setDescription(Translator.getTranslation("Add Certificate", language));
    addClickListener(new Button.ClickListener() {
        @Override//from  w w  w.j a  v  a  2 s . c  o m
        public void buttonClick(Button.ClickEvent event) {
            UploadReceiver receiver = new CertificateUploadReceiver(userId, language, a);
            Upload upload = new Upload(Translator.getTranslation("Add Certificate", language), receiver);
            upload.addSucceededListener((Upload.SucceededListener) receiver);

            String wcaption = Translator.getTranslation("Upload", language);
            final Window window = new Window(wcaption, upload);
            window.center();
            //window.setModal(true);
            window.setStyleName("window");
            receiver.setWindow(window);
            window.addCloseListener(new Window.CloseListener() {

                @Override
                public void windowClose(Window.CloseEvent e) {
                    window.close();
                }
            });
            getUI().addWindow(window);
        }
    });
}

From source file:ui.button.AddPhotoButton.java

License:Apache License

public AddPhotoButton(final Integer userId, final String language) {
    super(Translator.getTranslation("Add professional photo", language), FontAwesome.CAMERA_RETRO);
    setDescription(Translator.getTranslation("Add professional photo", language));
    addClickListener(new Button.ClickListener() {

        @Override/*from   w  ww.  jav a2 s .co m*/
        public void buttonClick(Button.ClickEvent event) {
            UploadReceiver receiver = new PhotoUploadReceiver(userId, language);
            Upload upload = new Upload(Translator.getTranslation("Choose your best photo", language), receiver);
            upload.addSucceededListener((Upload.SucceededListener) receiver);

            String wcaption = Translator.getTranslation("Upload a photo", language);
            final Window window = new Window(wcaption, upload);
            window.center();
            //window.setModal(true);
            window.setStyleName("window");
            receiver.setWindow(window);
            window.addCloseListener(new Window.CloseListener() {

                @Override
                public void windowClose(Window.CloseEvent e) {
                    window.close();
                }
            });
            getUI().addWindow(window);
        }
    });
}

From source file:views.BatchUpload.java

License:Open Source License

public BatchUpload() {
    setMargin(true);//  w  w  w . j  av a2  s. c  o  m
    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);
}