Example usage for com.vaadin.ui Upload addStartedListener

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

Introduction

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

Prototype

public Registration addStartedListener(StartedListener listener) 

Source Link

Document

Adds the upload started event listener.

Usage

From source file:com.peergreen.webconsole.scope.deployment.internal.DeploymentScope.java

License:Open Source License

@PostConstruct
public void init() {
    deploymentViewManager = createDeploymentViewManager();

    OptionGroup option = new OptionGroup();
    HorizontalLayout toolBar = new HorizontalLayout();
    toolBar.setWidth("100%");
    toolBar.setSpacing(true);//from   w  w w. j  a  va 2 s .c  o  m
    toolBar.setMargin(true);

    VerticalLayout uploadLayout = new VerticalLayout();

    Upload uploader = new Upload("Upload a file here", null);
    uploader.setButtonCaption("Upload");
    final FileUploader fileUploader = new FileUploader(deploymentViewManager, notifierService, artifactBuilder,
            option);
    uploader.setReceiver(fileUploader);
    uploader.addSucceededListener(fileUploader);
    uploader.addStartedListener(fileUploader);
    uploadLayout.addComponent(uploader);

    HorizontalLayout target = new HorizontalLayout();
    option.addContainerProperty("id", String.class, null);
    option.setItemCaptionPropertyId("id");
    option.addItem(DeployableContainerType.DEPLOYABLE.attribute()).getItemProperty("id")
            .setValue("Add to deployables");
    option.addItem(DeployableContainerType.DEPLOYED.attribute()).getItemProperty("id").setValue("Deploy");
    option.addItem(DeployableContainerType.DEPLOYMENT_PLAN.attribute()).getItemProperty("id")
            .setValue("Create a deployment plan");
    option.addStyleName("horizontal");
    option.select(DeployableContainerType.DEPLOYABLE.attribute());

    target.addComponent(option);
    uploadLayout.addComponent(target);
    toolBar.addComponent(uploadLayout);

    Label infoLabel = new Label("Drop files here to create a deployment plan");
    infoLabel.setSizeUndefined();
    final VerticalLayout deploymentPlanMaker = new VerticalLayout(infoLabel);
    deploymentPlanMaker.setComponentAlignment(infoLabel, Alignment.MIDDLE_CENTER);
    Button draft = new Button("A draft is under construction");
    draft.addStyleName("link");
    draft.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            deploymentViewManager.showDeploymentPlanView();
        }
    });
    draft.setVisible(false);
    deploymentViewManager.setDeploymentPlanDraftViewer(draft);
    deploymentPlanMaker.addComponent(draft);
    deploymentPlanMaker.setComponentAlignment(draft, Alignment.TOP_CENTER);
    deploymentPlanMaker.setSizeFull();
    deploymentPlanMaker.addStyleName("drop-area");
    deploymentPlanMakerWrapper = new DragAndDropWrapper(deploymentPlanMaker);
    deploymentPlanMakerWrapper.setSizeFull();
    toolBar.addComponent(deploymentPlanMakerWrapper);
    addComponent(toolBar);

    addComponent(framesContainer);
    setExpandRatio(framesContainer, 1.5f);

    helpWindow = notifierService.createHelpOverlay("Deployment module",
            "<p>To deploy, or undeploy, artifacts, you can drag and drop elements from deployables panel "
                    + "to deployed panel and vice versa.</p>"
                    + "<p>You can also drag files from desktop and drop them where you want to add them.");
}

From source file:com.wcs.wcslib.vaadin.widget.multifileupload.component.SmartMultiUpload.java

License:Apache License

private void initSingleUpload() {
    upload = new CustomUpload();
    Upload singleUpload = (Upload) upload;
    singleUpload.setReceiver(new Upload.Receiver() {
        @Override//from w  ww.j  a v a  2s  .  c o m
        public OutputStream receiveUpload(String filename, String mimeType) {
            return handler.getOutputStream();
        }
    });
    singleUpload.setImmediate(true);

    SimpleFileUploadListener uploadEventListener = new SimpleFileUploadListener(handler);
    singleUpload.addStartedListener(uploadEventListener);
    singleUpload.addProgressListener(uploadEventListener);
    singleUpload.addFailedListener(uploadEventListener);
    singleUpload.addFinishedListener(uploadEventListener);
}

From source file:org.eclipse.hawkbit.ui.artifacts.upload.UploadLayout.java

License:Open Source License

private void buildLayout() {

    final Upload upload = new Upload();
    final UploadHandler uploadHandler = new UploadHandler(null, 0, this,
            multipartConfigElement.getMaxFileSize(), upload, null, null, softwareModuleManagement);
    upload.setButtonCaption(i18n.getMessage("upload.file"));
    upload.setImmediate(true);/* w w w . j  a va  2s . c o  m*/
    upload.setReceiver(uploadHandler);
    upload.addSucceededListener(uploadHandler);
    upload.addFailedListener(uploadHandler);
    upload.addFinishedListener(uploadHandler);
    upload.addProgressListener(uploadHandler);
    upload.addStartedListener(uploadHandler);
    upload.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON);
    upload.addStyleName("no-border");

    fileUploadLayout = new HorizontalLayout();
    fileUploadLayout.setSpacing(true);
    fileUploadLayout.addStyleName(SPUIStyleDefinitions.FOOTER_LAYOUT);
    fileUploadLayout.addComponent(upload);
    fileUploadLayout.setComponentAlignment(upload, Alignment.MIDDLE_LEFT);
    fileUploadLayout.addComponent(processBtn);
    fileUploadLayout.setComponentAlignment(processBtn, Alignment.MIDDLE_RIGHT);
    fileUploadLayout.addComponent(discardBtn);
    fileUploadLayout.setComponentAlignment(discardBtn, Alignment.MIDDLE_RIGHT);
    fileUploadLayout.addComponent(uploadStatusButton);
    fileUploadLayout.setComponentAlignment(uploadStatusButton, Alignment.MIDDLE_RIGHT);
    setMargin(false);

    /* create drag-drop wrapper for drop area */
    dropAreaWrapper = new DragAndDropWrapper(createDropAreaLayout());
    dropAreaWrapper.setDropHandler(new DropAreahandler());
    setSizeFull();
    setSpacing(true);
}

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  ww  .  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:org.ikasan.dashboard.ui.mappingconfiguration.window.MappingConfigurationImportWindow.java

License:BSD License

/**
 * Helper method to initialise this object.
 *///from   w  ww .  jav  a2s.  co 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);
            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 .j  a v 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// www. j  av 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;
}