Example usage for com.vaadin.ui Upload setReceiver

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

Introduction

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

Prototype

public void setReceiver(Receiver receiver) 

Source Link

Document

Sets the receiver.

Usage

From source file:com.klwork.explorer.ui.custom.InMemoryUploadReceiver.java

License:Apache License

/**
 * @param upload The component that will serve this receiver
 * @param maxFileSize The maximum size of files that will be accepted (in bytes). -1 in case of no limit.
 *//*from w w  w . ja  va 2s.c  om*/
public InMemoryUploadReceiver(Upload upload, long maxFileSize) {
    this.upload = upload;
    this.maxFileSize = maxFileSize;
    this.notificationManager = ViewToolManager.getNotificationManager();

    upload.setReceiver(this);
    upload.addListener((StartedListener) this);
    upload.addListener((ProgressListener) this);
}

From source file:com.klwork.explorer.ui.user.ProfilePanel.java

License:Apache License

protected InMemoryUploadReceiver initPictureReceiver(Upload upload) {
    InMemoryUploadReceiver receiver = new InMemoryUploadReceiver(upload, 102400L); // 100 kb limit
    upload.setReceiver(receiver);
    receiver.setAcceptedMimeTypes(Constants.DEFAULT_IMAGE_MIMETYPES);
    return receiver;
}

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 ww  . j ava 2s.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 ww w. ja  v  a 2s. co 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:de.unioninvestment.eai.portal.portlet.crud.mvp.views.DefaultRowEditingFormView.java

License:Apache License

private Upload buildUpload(final ContainerRow row, final ContainerBlob containerBlob,
        final FileMetadata metadata, final Link downloadLink) {
    final Upload upload = new Upload();
    if (metadata.getUploadCaption() != null) {
        upload.setButtonCaption(metadata.getUploadCaption());
    } else {/*from w ww.j av  a 2  s  . c  o  m*/
        upload.setButtonCaption("Upload");
    }
    upload.setImmediate(true);
    upload.setReceiver(new BlobUploadReceiver());

    upload.addFinishedListener(new Upload.FinishedListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void uploadFinished(FinishedEvent event) {
            BlobUploadReceiver receiver = (BlobUploadReceiver) upload.getReceiver();
            if (receiver.getBaos().size() <= 0 || receiver.getBaos().size() <= metadata.getMaxFileSize()) {
                containerBlob.setValue(receiver.getBaos().toByteArray());
                if (metadata.getFilenameColumn() != null) {
                    row.getValues().put(metadata.getFilenameColumn(), receiver.getFilename());

                }
                if (metadata.getMimetypeColumn() != null) {
                    row.getValues().put(metadata.getMimetypeColumn(), receiver.getMimetype());
                }
                updateDownloadLink(row, containerBlob, metadata, downloadLink);

            } else {
                Notification.show(
                        "Ein Datei darauf nicht grer als " + metadata.getMaxFileSize() + " Bytes sein.",
                        Notification.Type.ERROR_MESSAGE);
            }
        }
    });
    return upload;
}

From source file:facs.components.UploadBox.java

License:Open Source License

public UploadBox() {
    this.setCaption(CAPTION);
    // there has to be a device selected.
    devices = new NativeSelect("Devices");
    devices.setDescription("Select a device in order to upload information for that specific devices.");
    devices.setNullSelectionAllowed(false);
    deviceNameToId = new HashMap<String, Integer>();
    for (DeviceBean bean : DBManager.getDatabaseInstance().getDevices()) {
        deviceNameToId.put(bean.getName(), bean.getId());
        devices.addItem(bean.getName());
        // System.out.println("Bean.getName: " + bean.getName() + " Bean.getId: " + bean.getId());
    }//from ww  w .jav a2 s .c  o  m
    occupationGrid = new Grid();
    occupationGrid.setSizeFull();

    // Create the upload component and handle all its events
    final Upload upload = new Upload();
    upload.setReceiver(this);
    upload.addProgressListener(this);
    upload.addFailedListener(this);
    upload.addSucceededListener(this);
    upload.setVisible(false);

    // one can only upload csvs, if a device was selected.
    devices.addValueChangeListener(new ValueChangeListener() {

        /**
         * 
         */
        private static final long serialVersionUID = 7890499571475184208L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            upload.setVisible(event.getProperty().getValue() != null);
        }
    });

    // Put the upload and image display in a panel
    // Panel panel = new Panel(UPLOAD_CAPTION);
    // panel.setWidth("100%");
    VerticalLayout panelContent = new VerticalLayout();
    panelContent.setSpacing(true);
    // panel.setContent(panelContent);
    panelContent.addComponent(devices);
    panelContent.addComponent(upload);
    panelContent.addComponent(progress);
    panelContent.addComponent(occupationGrid);

    panelContent.setMargin(true);
    panelContent.setSpacing(true);

    progress.setVisible(false);

    setCompositionRoot(panelContent);
}

From source file:org.activiti.explorer.ui.custom.InMemoryUploadReceiver.java

License:Apache License

/**
 * @param upload The component that will serve this receiver
 * @param maxFileSize The maximum size of files that will be accepted (in bytes). -1 in case of no limit.
 *//* w w w  . j a v a 2  s .  com*/
public InMemoryUploadReceiver(Upload upload, long maxFileSize) {
    this.upload = upload;
    this.maxFileSize = maxFileSize;
    this.notificationManager = ExplorerApp.get().getNotificationManager();

    upload.setReceiver(this);
    upload.addListener((StartedListener) this);
    upload.addListener((ProgressListener) this);
}

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  v a 2  s  . c  om
    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   www .j  a  v a 2 s . co  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.s23m.cell.editor.semanticdomain.ui.components.upload.IconUploadComponent.java

License:Mozilla Public License

/**
 * Constructor//w  w  w . j  ava 2  s  .c  om
 *
 * @param set the {@link Set} in focus
 */
public IconUploadComponent(final Set set) {
    this.set = set;

    root = new Panel("My Upload Component");
    setCompositionRoot(root);

    // Create the Upload component.
    final Upload upload = new Upload();
    upload.setReceiver(this);

    // Use a custom button caption instead of plain "Upload".
    //upload.setButtonCaption("Upload Now");

    // Listen for events regarding the success of upload.
    upload.addListener((Upload.SucceededListener) this);
    upload.addListener((Upload.FailedListener) this);

    root.addComponent(upload);
    root.addComponent(new Label("Click 'Browse' to " + "select a file and then click 'Upload'."));

    // Create a panel for displaying the uploaded image.
    imagePanel = new Panel("Uploaded image");
    imagePanel.addComponent(new Label("No image uploaded yet"));
    root.addComponent(imagePanel);
}