Example usage for com.vaadin.ui Upload interruptUpload

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

Introduction

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

Prototype

public void interruptUpload() 

Source Link

Document

Interrupts the upload currently being received.

Usage

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

License:BSD License

/**
 * Helper method to initialise this object.
 *//*from  w  w w  .j  av a2 s.com*/
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);
            try {
                parseUploadFile();
            } catch (Exception e) {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);

                Notification.show("Caught exception trying to import a Mapping Configuration!\n", sw.toString(),
                        Notification.Type.ERROR_MESSAGE);
            }
        }
    });

    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 {
                saveImportedMappingConfiguration();
                mappingConfiguration = null;
                progressLayout.setVisible(false);
                upload.setVisible(true);

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

                systemEventService.logSystemEvent(MappingConfigurationConstants.MAPPING_CONFIGURATION_SERVICE,
                        "Imported mapping configuration: [Client="
                                + mappingConfiguration.getConfigurationServiceClient().getName()
                                + "] [Source Context=" + mappingConfiguration.getSourceContext().getName()
                                + "] [Target Context=" + mappingConfiguration.getTargetContext().getName()
                                + "] [Type=" + mappingConfiguration.getConfigurationType().getName() + "]",
                        authentication.getName());
            } catch (MappingConfigurationServiceException e) {
                if (e.getCause() instanceof DataIntegrityViolationException) {
                    Notification.show("Caught exception trying to save an imported Mapping Configuration!",
                            "This is due to the fact "
                                    + "that, combined, the client, type, source and target context values are unique for a Mapping Configuration. The values"
                                    + " that are being imported and not unique.",
                            Notification.Type.ERROR_MESSAGE);
                } else {
                    StringWriter sw = new StringWriter();
                    PrintWriter pw = new PrintWriter(sw);
                    e.printStackTrace(pw);

                    Notification.show("Caught exception trying to save an imported Mapping Configuration!\n",
                            sw.toString(), Notification.Type.ERROR_MESSAGE);
                }
            }

            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) {
            mappingConfiguration = null;
            progressLayout.setVisible(false);
            upload.setVisible(true);
            close();
        }
    });

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

    layout.addComponent(hlayout);

    super.setContent(layout);
}

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

License:BSD License

/**
 * Helper method to initialise this object.
 *//*from w w w . jav  a 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.vaadin.tori.component.AuthoringComponent.java

License:Apache License

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

        @Override/*from w  w  w  .j a  v  a 2 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;
}