Example usage for com.vaadin.ui Upload setCaption

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

Introduction

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

Prototype

@Override
    public void setCaption(String caption) 

Source Link

Usage

From source file:org.apache.ace.webui.vaadin.AddArtifactWindow.java

License:Apache License

/**
 * Creates a new {@link AddArtifactWindow} instance.
 * /*from  w w w  .  ja  v a 2  s  .  c  o m*/
 * @param sessionDir
 *            the session directory to temporary place artifacts in;
 * @param obrUrl
 *            the URL of the OBR to use.
 */
public AddArtifactWindow(File sessionDir, URL obrUrl, String repositoryXML) {
    super("Add artifact");

    m_sessionDir = sessionDir;
    m_obrUrl = obrUrl;
    m_repositoryXML = repositoryXML;

    setModal(true);
    setWidth("50em");
    setCloseShortcut(KeyCode.ESCAPE);

    m_artifactsTable = new Table("Artifacts in repository");
    m_artifactsTable.addContainerProperty(PROPERTY_SYMBOLIC_NAME, String.class, null);
    m_artifactsTable.addContainerProperty(PROPERTY_VERSION, String.class, null);
    m_artifactsTable.addContainerProperty(PROPERTY_PURGE, Button.class, null);
    m_artifactsTable.setSizeFull();
    m_artifactsTable.setSelectable(true);
    m_artifactsTable.setMultiSelect(true);
    m_artifactsTable.setImmediate(true);
    m_artifactsTable.setHeight("15em");

    final Table uploadedArtifacts = new Table("Uploaded artifacts");
    uploadedArtifacts.addContainerProperty(PROPERTY_SYMBOLIC_NAME, String.class, null);
    uploadedArtifacts.addContainerProperty(PROPERTY_VERSION, String.class, null);
    uploadedArtifacts.setSizeFull();
    uploadedArtifacts.setSelectable(false);
    uploadedArtifacts.setMultiSelect(false);
    uploadedArtifacts.setImmediate(true);
    uploadedArtifacts.setHeight("15em");

    final GenericUploadHandler uploadHandler = new GenericUploadHandler(m_sessionDir) {
        @Override
        public void updateProgress(long readBytes, long contentLength) {
            // TODO Auto-generated method stub
        }

        @Override
        protected void artifactsUploaded(List<UploadHandle> uploads) {
            for (UploadHandle handle : uploads) {
                try {
                    URL artifact = handle.getFile().toURI().toURL();

                    Item item = uploadedArtifacts.addItem(artifact);
                    item.getItemProperty(PROPERTY_SYMBOLIC_NAME).setValue(handle.getFilename());
                    item.getItemProperty(PROPERTY_VERSION).setValue("");

                    m_uploadedArtifacts.add(handle.getFile());
                } catch (MalformedURLException e) {
                    showErrorNotification("Upload artifact processing failed",
                            "<br />Reason: " + e.getMessage());
                    logError("Processing of " + handle.getFilename() + " failed.", e);
                }
            }
        }
    };

    final Upload uploadArtifact = new Upload();
    uploadArtifact.setCaption("Upload Artifact");
    uploadHandler.install(uploadArtifact);

    final DragAndDropWrapper finalUploadedArtifacts = new DragAndDropWrapper(uploadedArtifacts);
    finalUploadedArtifacts.setDropHandler(new ArtifactDropHandler(uploadHandler));

    addListener(new Window.CloseListener() {
        public void windowClose(CloseEvent e) {
            for (File artifact : m_uploadedArtifacts) {
                artifact.delete();
            }
        }
    });

    HorizontalLayout searchBar = new HorizontalLayout();
    searchBar.setMargin(false);
    searchBar.setSpacing(true);

    final TextField searchField = new TextField();
    searchField.setImmediate(true);
    searchField.setValue("");

    final IndexedContainer dataSource = (IndexedContainer) m_artifactsTable.getContainerDataSource();

    m_searchButton = new Button("Search", new ClickListener() {
        public void buttonClick(ClickEvent event) {
            String searchValue = (String) searchField.getValue();

            dataSource.removeAllContainerFilters();

            if (searchValue != null && searchValue.trim().length() > 0) {
                dataSource.addContainerFilter(PROPERTY_SYMBOLIC_NAME, searchValue, true /* ignoreCase */,
                        false /* onlyMatchPrefix */);
            }
        }
    });
    m_searchButton.setImmediate(true);

    searchBar.addComponent(searchField);
    searchBar.addComponent(m_searchButton);

    m_addButton = new Button("Add", new ClickListener() {
        public void buttonClick(ClickEvent event) {
            // Import all "local" (existing) bundles...
            importLocalBundles(m_artifactsTable);
            // Import all "remote" (non existing) bundles...
            importRemoteBundles(m_uploadedArtifacts);

            close();
        }
    });
    m_addButton.setImmediate(true);
    m_addButton.setStyleName(Reindeer.BUTTON_DEFAULT);
    m_addButton.setClickShortcut(KeyCode.ENTER);

    VerticalLayout layout = (VerticalLayout) getContent();
    layout.setMargin(true);
    layout.setSpacing(true);

    layout.addComponent(searchBar);
    layout.addComponent(m_artifactsTable);
    layout.addComponent(uploadArtifact);
    layout.addComponent(finalUploadedArtifacts);
    // The components added to the window are actually added to the window's
    // layout; you can use either. Alignments are set using the layout
    layout.addComponent(m_addButton);
    layout.setComponentAlignment(m_addButton, Alignment.MIDDLE_RIGHT);

    searchField.focus();
}

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 w w.ja v  a2  s .co 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 .  j ava 2s .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");
        }
    });
}