Example usage for com.vaadin.ui Window setModal

List of usage examples for com.vaadin.ui Window setModal

Introduction

In this page you can find the example usage for com.vaadin.ui Window setModal.

Prototype

public void setModal(boolean modal) 

Source Link

Document

Sets window modality.

Usage

From source file:org.eclipse.hawkbit.ui.distributions.smtable.SwModuleDetails.java

License:Open Source License

private void showArtifactDetailsWindow(final SoftwareModule softwareModule) {
    final Window artifactDtlsWindow = new Window();
    artifactDtlsWindow.setCaption(HawkbitCommonUtil.getArtifactoryDetailsLabelId(
            softwareModule.getName() + "." + softwareModule.getVersion(), getI18n()));
    artifactDtlsWindow.setCaptionAsHtml(true);
    artifactDtlsWindow.setClosable(true);
    artifactDtlsWindow.setResizable(true);
    artifactDtlsWindow.setImmediate(true);
    artifactDtlsWindow.setWindowMode(WindowMode.NORMAL);
    artifactDtlsWindow.setModal(true);
    artifactDtlsWindow.addStyleName(SPUIStyleDefinitions.CONFIRMATION_WINDOW_CAPTION);

    artifactDetailsLayout.setFullWindowMode(false);
    artifactDetailsLayout.populateArtifactDetails(softwareModule);
    artifactDetailsLayout.getArtifactDetailsTable().setWidth(700, Unit.PIXELS);
    artifactDetailsLayout.getArtifactDetailsTable().setHeight(500, Unit.PIXELS);
    artifactDtlsWindow.setContent(artifactDetailsLayout.getArtifactDetailsTable());

    artifactDtlsWindow.addWindowModeChangeListener(event -> {
        if (event.getWindowMode() == WindowMode.MAXIMIZED) {
            artifactDtlsWindow.setSizeFull();
            artifactDetailsLayout.setFullWindowMode(true);
            artifactDetailsLayout.createMaxArtifactDetailsTable();
            artifactDetailsLayout.getMaxArtifactDetailsTable().setWidth(100, Unit.PERCENTAGE);
            artifactDetailsLayout.getMaxArtifactDetailsTable().setHeight(100, Unit.PERCENTAGE);
            artifactDtlsWindow.setContent(artifactDetailsLayout.getMaxArtifactDetailsTable());
        } else {/*from w  w  w  .  ja v  a  2s . c om*/
            artifactDtlsWindow.setSizeUndefined();
            artifactDtlsWindow.setContent(artifactDetailsLayout.getArtifactDetailsTable());
        }
    });
    UI.getCurrent().addWindow(artifactDtlsWindow);
}

From source file:org.eclipse.hawkbit.ui.management.dstag.DistributionTagHeader.java

License:Open Source License

@Override
protected void settingsIconClicked(final ClickEvent event) {
    final Window addUpdateWindow = createORUpdateDistributionTagLayout.getWindow();
    UI.getCurrent().addWindow(addUpdateWindow);
    addUpdateWindow.setModal(true);
    addUpdateWindow.setVisible(Boolean.TRUE);
}

From source file:org.eclipse.skalli.view.ext.impl.internal.infobox.ReviewComponent.java

License:Open Source License

@SuppressWarnings("serial")
private Window createReviewWindow(final ProjectRating rating) {
    final Window subwindow = new Window("Rate and Review");
    subwindow.setModal(true);
    subwindow.setWidth("420px"); //$NON-NLS-1$
    subwindow.setHeight("320px"); //$NON-NLS-1$

    VerticalLayout vl = (VerticalLayout) subwindow.getContent();
    vl.setSpacing(true);/*from  w w w  .  jav  a2  s.com*/
    vl.setSizeFull();

    HorizontalLayout hl = new HorizontalLayout();
    hl.setSizeUndefined();

    Embedded icon = new Embedded(null, getIcon(rating));
    Label iconLabel = new Label("<b>" + HSPACE + getReviewComment(rating) + "</b>", Label.CONTENT_XHTML); //$NON-NLS-1$ //$NON-NLS-2$
    String captionTextField = getReviewCommentQuestion(rating);
    hl.addComponent(icon);
    hl.addComponent(iconLabel);
    hl.setComponentAlignment(iconLabel, Alignment.MIDDLE_LEFT);
    vl.addComponent(hl);

    final TextField editor = new TextField(captionTextField);
    editor.setRows(3);
    editor.setColumns(30);
    editor.setImmediate(true);
    vl.addComponent(editor);

    final User user = util.getLoggedInUser();
    final ArrayList<String> userSelects = new ArrayList<String>(2);
    userSelects.add("I want to vote as " + user.getDisplayName());
    if (extension.getAllowAnonymous()) {
        userSelects.add("I want to vote as Anonymous!");
    }
    final OptionGroup userSelect = new OptionGroup(null, userSelects);
    userSelect.setNullSelectionAllowed(false);
    userSelect.select(userSelects.get(0));
    vl.addComponent(userSelect);

    CssLayout css = new CssLayout() {
        @Override
        protected String getCss(Component c) {
            return "margin-left:5px;margin-right:5px;margin-top:10px"; //$NON-NLS-1$
        }
    };

    Button okButton = new Button("OK");
    okButton.setIcon(ICON_BUTTON_OK);
    okButton.setDescription("Commit changes");
    okButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            String comment = (String) editor.getValue();
            if (StringUtils.isBlank(comment)) {
                comment = "No Comment";
            }
            ((Window) subwindow.getParent()).removeWindow(subwindow);
            String userName = "Anonymous";
            if (userSelects.get(0).equals(userSelect.getValue())) {
                userName = user.getDisplayName();
            }
            ReviewEntry review = new ReviewEntry(rating, comment, userName, System.currentTimeMillis());
            extension.addReview(review);
            util.persist(project);
            reviews = extension.getReviews();
            size = reviews.size();
            currentPage = 0;
            lastPage = size / currentPageLength;
            paintReviewList();
        }
    });
    css.addComponent(okButton);

    Button cancelButton = new Button("Cancel");
    cancelButton.setIcon(ICON_BUTTON_CANCEL);
    cancelButton.setDescription("Discard changes");
    cancelButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            ((Window) subwindow.getParent()).removeWindow(subwindow);
        }
    });
    css.addComponent(cancelButton);

    vl.addComponent(css);
    vl.setComponentAlignment(css, Alignment.MIDDLE_CENTER);

    return subwindow;
}

From source file:org.escidoc.browser.ui.listeners.AddMetaDataFileItemBehaviour.java

License:Open Source License

public void showAddWindow() {
    final Window subwindow = new Window(ViewConstants.ADD_ITEM_S_METADATA);
    subwindow.setWidth("600px");
    subwindow.setModal(true);
    receiver = new MetadataFileReceiver();
    // Make uploading start immediately when file is selected
    upload = new Upload("", receiver);
    upload.setImmediate(true);/* w  w w  .jav a  2  s  .  com*/
    upload.setButtonCaption("Select file");

    progressLayout.setSpacing(true);
    progressLayout.setVisible(false);
    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);
            }
        }
    });

    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() {
        Item item;

        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 {
                        item = repositories.item().findItemById(resourceProxy.getId());
                        metadataRecord.setContent(getMetadataContent());
                        repositories.item().addMetaData(metadataRecord, item);
                        upload.setEnabled(true);
                        subwindow.getParent().removeWindow(subwindow);
                    } catch (final EscidocClientException e) {
                        LOG.error(e.getLocalizedMessage());
                        mdName.setComponentError(new UserError(
                                "Failed to add the new Metadata record" + e.getLocalizedMessage()));
                    } catch (final SAXException e) {
                        LOG.error(e.getLocalizedMessage());
                        mdName.setComponentError(new UserError(
                                "Failed to add the new Metadata record" + e.getLocalizedMessage()));
                    } catch (final IOException e) {
                        LOG.error(e.getLocalizedMessage());
                        mdName.setComponentError(new UserError(
                                "Failed to add the new Metadata record" + e.getLocalizedMessage()));
                    } catch (final ParserConfigurationException e) {
                        LOG.error(e.getLocalizedMessage());
                        mdName.setComponentError(new UserError(
                                "Failed to add the new Metadata record" + e.getLocalizedMessage()));
                    }
                }
            }
        }

    });

    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.listeners.AddMetaDataFileItemComponentBehaviour.java

License:Open Source License

public void showAddWindow() {
    final Window subwindow = new Window(ViewConstants.ADD_ITEM_S_METADATA);
    subwindow.setWidth("600px");
    subwindow.setModal(true);
    receiver = new MetadataFileReceiver();
    // Make uploading start immediately when file is selected
    upload = new Upload("", receiver);
    upload.setImmediate(true);/* w ww  . j  a v  a 2  s .c  o  m*/
    upload.setButtonCaption("Select file");

    progressLayout.setSpacing(true);
    progressLayout.setVisible(false);
    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);
            }
        }
    });

    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());

                        MetadataRecords mdRecs = component.getMetadataRecords();
                        if (mdRecs == null) {
                            mdRecs = new MetadataRecords();
                        }
                        mdRecs.add(metadataRecord);
                        component.setMetadataRecords(mdRecs);

                        controller.updateComponent(component, itemProxy.getId());
                        itemComponentMDView.addNewItem(metadataRecord);
                        upload.setEnabled(true);
                        subwindow.getParent().removeWindow(subwindow);
                    }

                    catch (final SAXException e) {
                        LOG.error(e.getLocalizedMessage());
                        mdName.setComponentError(new UserError(
                                "Failed to add the new Metadata record" + e.getLocalizedMessage()));
                    } catch (final IOException e) {
                        LOG.error(e.getLocalizedMessage());
                        mdName.setComponentError(new UserError(
                                "Failed to add the new Metadata record" + e.getLocalizedMessage()));
                    } catch (final ParserConfigurationException e) {
                        LOG.error(e.getLocalizedMessage());
                        mdName.setComponentError(new UserError(
                                "Failed to add the new Metadata record" + e.getLocalizedMessage()));
                    } catch (EscidocClientException e) {
                        LOG.error(e.getLocalizedMessage());
                        mdName.setComponentError(new UserError(
                                "Failed to add the new Metadata record" + e.getLocalizedMessage()));
                    }
                }
            }
        }

    });

    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.listeners.ContextAdminDescriptorsClickListener.java

License:Open Source License

@Override
public void buttonClick(ClickEvent event) {
    Window subwindow = new Window(wndname);
    subwindow.setWidth("600px");
    subwindow.setModal(true);

    Label msgWindow = new Label(content, Label.CONTENT_RAW);

    subwindow.addComponent(msgWindow);/*from   w w w .j a v  a2s.  c  o  m*/
    if (subwindow.getParent() != null) {
        mainWindow.showNotification("Window is already open");
    } else {
        mainWindow.addWindow(subwindow);
    }
}

From source file:org.escidoc.browser.ui.listeners.EditMetaDataFileItemComponentBehaviour.java

License:Open Source License

public void showWindow() {
    final Window subwindow = new Window(ViewConstants.EDIT_METADATA);
    subwindow.setWidth("600px");
    subwindow.setModal(true);
    status = new Label(ViewConstants.EDIT_METADATA_UPLOAD_MESSAGE);

    // Make uploading start immediately when file is selected
    receiver = new MetadataFileReceiver();
    receiver.clearBuffer();/*from   w w  w .j  av a  2  s . co m*/

    upload = new Upload("", receiver);
    upload.setImmediate(true);
    upload.setButtonCaption("Select file");
    upload.setEnabled(true);
    progressLayout.setSpacing(true);
    progressLayout.setVisible(false);
    progressLayout.addComponent(progressIndicator);
    progressLayout.setComponentAlignment(progressIndicator, 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);
            progressIndicator.setValue(Float.valueOf(0.5f));
            progressIndicator.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");
            if (isValidXml(receiver.getFileContent())) {
                status.setValue(ViewConstants.XML_IS_WELL_FORMED);
                horizontalLayout.setVisible(true);
                upload.setEnabled(false);
            } else {
                status.setValue(ViewConstants.XML_IS_NOT_WELL_FORMED);
                receiver.clearBuffer();
            }
        }
    });

    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) {

            progressLayout.setVisible(false);
            upload.setVisible(true);
            upload.setCaption("Select another file");
        }
    });

    final Button btnAdd = new Button("Save", new Button.ClickListener() {
        Item item;

        @Override
        public void buttonClick(final ClickEvent event) {

            metadataRecord.setContent(metadataContent);
            controller.updateMetaDataComponent(metadataRecord, itemProxy, component);
            upload.setEnabled(true);

            subwindow.getParent().removeWindow(subwindow);
        }
    });

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

    subwindow.addComponent(status);
    subwindow.addComponent(upload);
    subwindow.addComponent(progressLayout);
    subwindow.addComponent(horizontalLayout);
    mainWindow.addWindow(subwindow);
}

From source file:org.escidoc.browser.ui.listeners.MetadataRecBehavour.java

License:Open Source License

@Override
public void buttonClick(final ClickEvent event) {
    final Window subwindow = new Window(ViewConstants.METADATA);
    subwindow.setWidth("600px");
    subwindow.setModal(true);

    final StringBuilder builder = new StringBuilder();
    builder.append(NAME);//from  ww  w. ja  va2s.  co  m
    builder.append(metadataRecord.getName());
    builder.append("<br />");
    builder.append(LINK);
    builder.append(metadataRecord.getXLinkTitle());
    final String mtRecinfo = builder.toString();

    final Label msgWindow = new Label(mtRecinfo, Label.CONTENT_RAW);
    final Label msgMetaDataXml = new Label(getContentAsString(metadataRecord.getContent()),
            Label.CONTENT_PREFORMATTED);

    subwindow.addComponent(msgWindow);
    subwindow.addComponent(msgMetaDataXml);
    if (subwindow.getParent() != null) {
        mainWindow.showNotification("Window is already open");
    } else {
        mainWindow.addWindow(subwindow);
    }
}

From source file:org.escidoc.browser.ui.listeners.OnAddContainerMetadata.java

License:Open Source License

public void showAddWindow() {
    final Window subwindow = new Window(ViewConstants.ADD_CONTAINER_S_METADATA);
    subwindow.setWidth("600px");
    subwindow.setModal(true);

    receiver = new MetadataFileReceiver();

    // Make uploading start immediately when file is selected
    upload = new Upload("", receiver);
    upload.setImmediate(true);//w  w  w  .j a  v a 2 s. c o m
    upload.setButtonCaption("Select file");

    progressLayout.setSpacing(true);
    progressLayout.setVisible(false);
    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(@SuppressWarnings("unused") 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() {
        Container container;

        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 {
                        container = repositories.container().findContainerById(resourceProxy.getId());
                        metadataRecord.setContent(getMetadataContent());
                        repositories.container().addMetaData(metadataRecord, container);

                        upload.setEnabled(true);
                        subwindow.getParent().removeWindow(subwindow);
                    } catch (final EscidocClientException e) {
                        LOG.error(e.getLocalizedMessage());
                        mdName.setComponentError(new UserError(
                                "Failed to add the new Metadata record" + e.getLocalizedMessage()));
                    } catch (final SAXException e) {
                        LOG.error(e.getLocalizedMessage());
                        mdName.setComponentError(new UserError(
                                "Failed to add the new Metadata record" + e.getLocalizedMessage()));
                    } catch (final IOException e) {
                        LOG.error(e.getLocalizedMessage());
                        mdName.setComponentError(new UserError(
                                "Failed to add the new Metadata record" + e.getLocalizedMessage()));
                    } catch (final ParserConfigurationException e) {
                        LOG.error(e.getLocalizedMessage());
                        mdName.setComponentError(new UserError(
                                "Failed to add the new Metadata record" + e.getLocalizedMessage()));
                    }
                }
            }
        }

        private Element getMetadataContent() throws SAXException, IOException, ParserConfigurationException {
            return XmlUtil.string2Dom(receiver.getFileContent()).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.listeners.OnContextAdminDescriptor.java

License:Open Source License

@SuppressWarnings("serial")
public void adminDescriptorForm() {
    final Window subwindow = new Window("A modal subwindow");
    subwindow.setModal(true);
    subwindow.setWidth("650px");
    VerticalLayout layout = (VerticalLayout) subwindow.getContent();
    layout.setMargin(true);/*ww w.  j  a  v a  2  s  . c  om*/
    layout.setSpacing(true);

    final TextField txtName = new TextField("Name");
    txtName.setImmediate(true);
    txtName.setValidationVisible(true);
    final TextArea txtContent = new TextArea("Content");
    txtContent.setColumns(30);
    txtContent.setRows(40);

    Button addAdmDescButton = new Button("Add Description");
    addAdmDescButton.addListener(new ClickListener() {
        @Override
        public void buttonClick(@SuppressWarnings("unused") ClickEvent event) {

            if (txtName.getValue().toString() == null) {
                router.getMainWindow().showNotification(ViewConstants.PLEASE_ENTER_A_NAME,
                        Notification.TYPE_ERROR_MESSAGE);
            } else if (!XmlUtil.isWellFormed(txtContent.getValue().toString())) {
                router.getMainWindow().showNotification(ViewConstants.XML_IS_NOT_WELL_FORMED,
                        Notification.TYPE_ERROR_MESSAGE);
            } else {
                AdminDescriptor newAdmDesc = controller.addAdminDescriptor(txtName.getValue().toString(),
                        txtContent.getValue().toString());
                (subwindow.getParent()).removeWindow(subwindow);
                router.getMainWindow().showNotification("Addedd Successfully",
                        Notification.TYPE_HUMANIZED_MESSAGE);
            }
        }
    });

    subwindow.addComponent(txtName);
    subwindow.addComponent(txtContent);
    subwindow.addComponent(addAdmDescButton);

    Button close = new Button(ViewConstants.CLOSE, new Button.ClickListener() {
        @Override
        public void buttonClick(@SuppressWarnings("unused") ClickEvent event) {
            (subwindow.getParent()).removeWindow(subwindow);
        }
    });
    layout.addComponent(close);
    layout.setComponentAlignment(close, Alignment.TOP_RIGHT);

    router.getMainWindow().addWindow(subwindow);

}