Example usage for com.vaadin.ui Upload addListener

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

Introduction

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

Prototype

@Override
    public Registration addListener(Component.Listener listener) 

Source Link

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.
 *///w w w  . ja v a  2  s  .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:dhbw.ka.mwi.businesshorizon2.ui.initialscreen.InitialScreenViewImpl.java

License:Open Source License

public void createImportButton() {
    importButton = new VerticalLayout();
    importButton.setWidth(150, com.vaadin.terminal.Sizeable.UNITS_PIXELS);
    importButton.setHeight(80, com.vaadin.terminal.Sizeable.UNITS_PIXELS);
    importButton.setStyleName("topBarButtonContainer");
    UploadReceiver receiver = new UploadReceiver(eventBus);
    Upload upload = new Upload(null, receiver);
    upload.setButtonCaption("");
    upload.setImmediate(true);//from www.  ja  v a 2s. com
    upload.addListener(receiver);
    upload.setStyleName("importButton");
    upload.setWidth(30, com.vaadin.terminal.Sizeable.UNITS_PIXELS);
    upload.setHeight(30, com.vaadin.terminal.Sizeable.UNITS_PIXELS);
    Label gap = new Label();
    gap.setHeight("5px");
    Label label = new Label("Projekte");
    label.setStyleName("topBarButtonLabel");
    label.setSizeUndefined();
    Label label2 = new Label("importieren");
    label2.setStyleName("topBarButtonLabel");
    label2.setSizeUndefined();
    VerticalLayout labelLayout = new VerticalLayout();
    labelLayout.setHeight(45, com.vaadin.terminal.Sizeable.UNITS_PIXELS);
    labelLayout.setWidth(100, UNITS_PERCENTAGE);
    importButton.addComponent(upload);
    labelLayout.addComponent(label);
    labelLayout.addComponent(label2);
    importButton.addComponent(gap);
    importButton.addComponent(labelLayout);
    importButton.setComponentAlignment(upload, Alignment.TOP_CENTER);
    labelLayout.setComponentAlignment(label, Alignment.MIDDLE_CENTER);
    labelLayout.setComponentAlignment(label2, Alignment.MIDDLE_CENTER);
}

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.
 *///from ww  w  .  ja v a  2s  . c o m
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.activiti.explorer.ui.profile.ProfilePanel.java

License:Apache License

protected Upload initChangePictureButton() {
    final Upload changePictureUpload = new Upload();
    changePictureUpload.setImmediate(true);
    changePictureUpload.setButtonCaption(i18nManager.getMessage(Messages.PROFILE_CHANGE_PICTURE));

    final InMemoryUploadReceiver receiver = initPictureReceiver(changePictureUpload);
    changePictureUpload.addListener(new FinishedListener() {
        private static final long serialVersionUID = 1L;

        public void uploadFinished(FinishedEvent event) {
            if (!receiver.isInterruped()) {
                picture = new Picture(receiver.getBytes(), receiver.getMimeType());
                identityService.setUserPicture(userId, picture);

                // reset picture
                imageLayout.removeAllComponents();
                initPicture();//  w  w  w.  j  a  v a  2s  .  c o  m
            } else {
                receiver.reset();
            }
        }
    });

    return changePictureUpload;
}

From source file:org.escidoc.browser.ui.maincontent.OnAddOrgUnitMetadata.java

License:Open Source License

public void showAddWindow() {
    final Window subwindow = new Window(ViewConstants.ADD_ORGANIZATIONAL_UNIT_S_METADATA);
    subwindow.setWidth("600px");
    subwindow.setModal(true);//from   w ww  . j  a  va2 s. c o m

    // Make uploading start immediately when file is selected
    final Upload upload = new Upload("", receiver);
    upload.setImmediate(true);
    upload.setButtonCaption("Select file");

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

    final ProgressIndicator pi = new ProgressIndicator();
    progressLayout.addComponent(pi);
    progressLayout.setComponentAlignment(pi, Alignment.MIDDLE_LEFT);

    /**
     * =========== Add needed listener for the upload component: start, progress, finish, success, fail ===========
     */

    upload.addListener(new Upload.StartedListener() {
        @Override
        public void uploadStarted(final StartedEvent event) {

            upload.setVisible(false);
            progressLayout.setVisible(true);
            pi.setValue(Float.valueOf(0f));
            pi.setPollingInterval(500);
            status.setValue("Uploading file \"" + event.getFilename() + "\"");
        }
    });

    upload.addListener(new Upload.SucceededListener() {

        @Override
        public void uploadSucceeded(final SucceededEvent event) {
            // This method gets called when the upload finished successfully
            status.setValue("Uploading file \"" + event.getFilename() + "\" succeeded");
            final String fileContent = receiver.getFileContent();
            final boolean isWellFormed = XmlUtil.isWellFormed(fileContent);
            receiver.setWellFormed(isWellFormed);
            if (isWellFormed) {
                status.setValue(ViewConstants.XML_IS_WELL_FORMED);
                hl.setVisible(true);
                upload.setEnabled(false);
            } else {
                status.setValue(ViewConstants.XML_IS_NOT_WELL_FORMED);
                hl.setVisible(false);
            }
        }
    });

    upload.addListener(new Upload.FailedListener() {
        @Override
        public void uploadFailed(final FailedEvent event) {
            // This method gets called when the upload failed
            status.setValue("Uploading interrupted");
        }
    });

    upload.addListener(new Upload.FinishedListener() {
        @Override
        public void uploadFinished(final FinishedEvent event) {
            // This method gets called always when the upload finished,
            // either succeeding or failing
            progressLayout.setVisible(false);
            upload.setVisible(true);
            upload.setCaption("Select another file");
        }
    });

    mdName = new TextField("Metadata name");
    mdName.setValue("");
    mdName.setImmediate(true);
    mdName.setValidationVisible(false);

    hl = new HorizontalLayout();
    hl.setMargin(true);
    final Button btnAdd = new Button("Save", new Button.ClickListener() {

        private boolean containSpace(final String text) {
            final Pattern pattern = Pattern.compile("\\s");
            final Matcher matcher = pattern.matcher(text);
            return matcher.find();
        }

        @Override
        public void buttonClick(final ClickEvent event) {

            if (mdName.getValue().equals("")) {
                mdName.setComponentError(new UserError("You have to add a name for your MetaData"));
            } else if (containSpace(((String) mdName.getValue()))) {
                mdName.setComponentError(new UserError("The name of MetaData can not contain space"));
            } else {
                mdName.setComponentError(null);
                if (receiver.getFileContent().isEmpty()) {
                    upload.setComponentError(
                            new UserError("Please select a well formed XML file as metadata."));
                } else if (!receiver.isWellFormed()) {
                    upload.setComponentError(new UserError(ViewConstants.XML_IS_NOT_WELL_FORMED));
                } else {

                    final MetadataRecord metadataRecord = new MetadataRecord(mdName.getValue().toString());
                    try {
                        metadataRecord.setContent(getMetadataContent());
                        controller.addMetaData(metadataRecord);
                        controller.refreshView();
                        upload.setEnabled(true);
                        subwindow.getParent().removeWindow(subwindow);
                    } catch (final SAXException e) {
                        LOG.error(e.getMessage());
                        mdName.setComponentError(new UserError(
                                "Failed to add the new Metadata record" + e.getLocalizedMessage()));
                    } catch (final IOException e) {
                        LOG.error(e.getMessage());
                        mdName.setComponentError(new UserError(
                                "Failed to add the new Metadata record" + e.getLocalizedMessage()));
                    } catch (final ParserConfigurationException e) {
                        LOG.error(e.getMessage());
                        mdName.setComponentError(new UserError(
                                "Failed to add the new Metadata record" + e.getLocalizedMessage()));
                    }
                }
            }
        }

        private Element getMetadataContent() throws SAXException, IOException, ParserConfigurationException {
            final String fileContent = receiver.getFileContent();
            return XmlUtil.string2Dom(fileContent).getDocumentElement();
        }
    });

    final Button cnclAdd = new Button("Cancel", new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            (subwindow.getParent()).removeWindow(subwindow);
        }
    });

    hl.addComponent(btnAdd);
    hl.addComponent(cnclAdd);
    subwindow.addComponent(mdName);
    subwindow.addComponent(status);
    subwindow.addComponent(upload);
    subwindow.addComponent(progressLayout);
    subwindow.addComponent(hl);
    mainWindow.addWindow(subwindow);
}

From source file:org.escidoc.browser.ui.view.helpers.OnEditContextMetadata.java

License:Open Source License

@SuppressWarnings("serial")
private void addListeners(final Upload upload) {
    upload.addListener(new Upload.StartedListener() {
        @Override//from w  w  w. ja  va2s  . c o  m
        public void uploadStarted(final StartedEvent event) {
            upload.setVisible(false);
            progressLayout.setVisible(true);
            pi.setValue(Float.valueOf(0f));
            pi.setPollingInterval(500);
            message.setValue("Uploading file \"" + event.getFilename() + "\"");
        }
    });

    upload.addListener(new Upload.SucceededListener() {

        @Override
        public void uploadSucceeded(final SucceededEvent event) {
            message.setValue("Uploading file \"" + event.getFilename() + "\" succeeded");
            if (isWellFormed(receiver.getFileContent())) {
                message.setValue(ViewConstants.XML_IS_WELL_FORMED);
                buttonLayout.setVisible(true);
                upload.setEnabled(false);
            } else {
                message.setValue(ViewConstants.XML_IS_NOT_WELL_FORMED);
                receiver.clearBuffer();
            }
        }
    });

    upload.addListener(new Upload.FailedListener() {
        @Override
        public void uploadFailed(@SuppressWarnings("unused") final FailedEvent event) {
            message.setValue("Uploading interrupted");
        }
    });

    upload.addListener(new Upload.FinishedListener() {
        @Override
        public void uploadFinished(@SuppressWarnings("unused") final FinishedEvent event) {
            progressLayout.setVisible(false);
            upload.setVisible(true);
            upload.setCaption("Select another file");
        }
    });
}

From source file:org.s23m.cell.editor.semanticdomain.ui.components.MultitabPanel.java

License:Mozilla Public License

private void addImageUploadControls(final DetailsData detailsData) {
    final Embedded img = new Embedded("Icon", EditorIcon.VERTEX.getIconImage());
    final FileReceiver receiver = new FileReceiver();
    final Upload upload = new Upload("", receiver);

    upload.addListener(new Upload.FinishedListener() {

        public void uploadFinished(final FinishedEvent event) {
            final String imgContent = receiver.getBase64ContentString();
            final byte[] imgData = SerializerHolder.getS23MInstanceSerializer(SerializationType.XML)
                    .decodeBase64StringToByteArray(imgContent);
            DataOutputStream os = null;
            try {
                final String id = detailsData.getInstance().identity().identifier().toString();
                final String resourcePath = File.createTempFile(id, "").getAbsolutePath();
                os = new DataOutputStream(new FileOutputStream(resourcePath));
                os.write(imgData);// w  ww  . j  a v a 2s .  c  o  m
                img.setSource(new FileResource(new File(resourcePath), application));
            } catch (final IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    if (os != null) {
                        os.close();
                    }
                } catch (final IOException e) {
                }
            }
            receiver.clearCache();
        }

    });
    detailsForm.getLayout().addComponent(img);
    detailsForm.getLayout().addComponent(upload);
}

From source file:org.s23m.cell.editor.semanticdomain.ui.components.upload.IconUploadComponent.java

License:Mozilla Public License

/**
 * Constructor/*from   w  ww.j av  a2 s  . c  o  m*/
 *
 * @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);
}

From source file:org.universAAL.ucc.controller.desktop.ToolController.java

public void buttonClick(ClickEvent event) {
    if (event.getButton() == toolWin.getuStoreButton()) {
        Embedded em = new Embedded("", new ExternalResource(createLink()));
        em.setType(Embedded.TYPE_BROWSER);
        em.setWidth("100%");
        em.setHeight("850px");
        Window w = new Window("uStore");
        w.setWidth("1250px");
        w.setHeight("800px");
        VerticalLayout v = new VerticalLayout();
        w.center();/*from   w w  w .  ja  v  a 2  s  . c  o  m*/
        v.addComponent(em);
        w.setContent(v);
        app.getMainWindow().removeWindow(toolWin);
        app.getMainWindow().addWindow(w);
    }
    if (event.getButton() == toolWin.getOpenAAL()) {
        //         Embedded em = new Embedded("", new ExternalResource(
        //               "http://wiki.openaal.org"));
        //         em.setType(Embedded.TYPE_BROWSER);
        //         em.setWidth("100%");
        //         em.setHeight("800px");
        //         Window w = new Window("openAAL");
        //         w.setWidth("1250px");
        //         w.setHeight("800px");
        //         VerticalLayout v = new VerticalLayout();
        //         w.center();
        //         v.addComponent(em);
        //         w.setContent(v);
        BrowseServicesWindow pw = new BrowseServicesWindow(app);
        PurchasedServicesController pc = new PurchasedServicesController(pw, app);
        app.getMainWindow().removeWindow(toolWin);
        app.getMainWindow().addWindow(pw);
    }
    if (event.getButton() == toolWin.getInstallButton()) {
        // Later uncomment again only for testing commented out!
        Upload up = new Upload("", new AALServiceReceiver());
        up.setButtonCaption(res.getString("install.button"));
        up.addListener((Upload.FinishedListener) this);
        up.addListener((Upload.FailedListener) this);
        installWindow = new Window(res.getString("install.win.caption"));
        installWindow.setResizable(false);
        installWindow.center();
        installWindow.setWidth("400px");
        VerticalLayout v = new VerticalLayout();
        v.setSizeFull();
        v.setSpacing(true);
        v.setMargin(true);
        v.addComponent(up);
        installWindow.setContent(v);

        app.getMainWindow().removeWindow(toolWin);
        app.getMainWindow().addWindow(installWindow);
    }
    if (event.getButton() == toolWin.getLogoutButton()) {
        DesktopController.setCurrentPassword("");
        DesktopController.setCurrentUser("");
        //         if(!DesktopController.web.getSocket().isClosed()) {
        //            try {
        //               DesktopController.web.getSocket().close();
        //            } catch (IOException e) {
        //               e.printStackTrace();
        //            }
        //         }
        app.close();
    }

    if (event.getButton() == toolWin.getUninstallButton()) {
        app.getMainWindow().removeWindow(toolWin);
        List<RegisteredService> ids = new ArrayList<RegisteredService>();
        Document doc = Model.getSrvDocument();
        NodeList nodeList = doc.getElementsByTagName("service");
        for (int i = 0; i < nodeList.getLength(); i++) {
            RegisteredService srv = new RegisteredService();
            Element element = (Element) nodeList.item(i);
            System.err.println(element.getAttribute("serviceId"));
            srv.setServiceId(element.getAttribute("serviceId"));
            NodeList srvChilds = element.getChildNodes();
            for (int j = 0; j < srvChilds.getLength(); j++) {
                Node n = srvChilds.item(j);
                if (n.getNodeName().equals("application")) {
                    Element e = (Element) n;
                    srv.getAppId().add(e.getAttribute("appId"));
                }
                if (n.getNodeName().equals("bundle")) {
                    Element b = (Element) n;
                    srv.getBundleId().add(b.getAttribute("id"));
                    srv.setBundleVersion(b.getAttribute("version"));
                }
                if (n.getNodeName().equals("menuEntry")) {
                    Element e = (Element) n;
                    srv.setMenuName(e.getAttribute("entryName"));
                    srv.setIconURL(e.getAttribute("iconURL"));
                    srv.setProvider(e.getAttribute("vendor"));
                    srv.setServiceClass(e.getAttribute("serviceClass"));
                    srv.setUserID(e.getAttribute("userID"));
                }
            }
            ids.add(srv);
        }
        DeinstallWindow dw = new DeinstallWindow(ids);
        app.getMainWindow().addWindow(dw);
        DeinstallController dc = new DeinstallController(dw, app);
        //         frontend.uninstallService(Activator.getSessionKey(), "28002");
        //         frontend.getInstalledUnitsForService(Activator.getSessionKey(), "28002");
    }

    if (event.getButton() == toolWin.getPersonButton()) {
        AddNewPersonWindow apw = null;
        try {
            apw = new AddNewPersonWindow(null, null, app);
        } catch (JAXBException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        app.getMainWindow().removeWindow(toolWin);
        app.getMainWindow().addWindow(apw);
    }
    if (event.getButton() == toolWin.getConfigButton()) {
        AddNewHardwareWindow anhw = null;
        try {
            anhw = new AddNewHardwareWindow(null, null, app);
        } catch (JAXBException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        app.getMainWindow().removeWindow(toolWin);
        app.getMainWindow().addWindow(anhw);
    }
    if (event.getButton() == toolWin.getEditHW()) {
        RoomsWindow hardWare = null;
        try {
            hardWare = new RoomsWindow(app);
        } catch (JAXBException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        app.getMainWindow().removeWindow(toolWin);
        app.getMainWindow().addWindow(hardWare);

    }

    if (event.getButton() == toolWin.getEditPerson()) {
        HumansWindow hw = null;
        try {
            hw = new HumansWindow(app);
        } catch (JAXBException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        app.getMainWindow().removeWindow(toolWin);
        app.getMainWindow().addWindow(hw);
    }
    if (event.getButton() == toolWin.getEditUC()) {
        WhichBundleShouldBeConfiguredWindow uc = new WhichBundleShouldBeConfiguredWindow("Use Cases");
        app.getMainWindow().removeWindow(toolWin);
        app.getMainWindow().addWindow(uc);

    }

}

From source file:ru.codeinside.adm.ui.BusinessCalendar.java

License:Mozilla Public License

public BusinessCalendar() {
    Upload upload = new Upload();
    upload.setImmediate(false);//w  w w.  j a v a  2s . co m
    upload.setButtonCaption("  ");
    upload.setReceiver(this);
    upload.addListener(this);

    datesTable = new BusinessDatesTable();
    removeButton = createButton("");

    VerticalLayout vr = new VerticalLayout();
    vr.setSizeFull();
    vr.setSpacing(true);
    vr.setMargin(true);

    HorizontalLayout horLayout = new HorizontalLayout();
    horLayout.setSizeFull();
    horLayout.setSpacing(true);
    horLayout.setMargin(true);
    horLayout.addComponent(upload);
    horLayout.addComponent(removeButton);
    vr.addComponent(horLayout);
    vr.addComponent(datesTable);

    addComponent(vr);
    vr.setExpandRatio(horLayout, .1f);
    vr.setExpandRatio(datesTable, .9f);
    datesTable.addListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            removeButton.setVisible(event.getProperty().getValue() != null);
        }
    });
    setSizeFull();
}