Example usage for com.vaadin.ui Window getParent

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

Introduction

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

Prototype

@Override
    public HasComponents getParent() 

Source Link

Usage

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);/*from  w ww .j  a  va2  s  .co  m*/
    receiver = new MetadataFileReceiver();
    // Make uploading start immediately when file is selected
    upload = new Upload("", receiver);
    upload.setImmediate(true);
    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);/*from   ww w  . j  a v a2  s  .  c  o  m*/

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

    subwindow.addComponent(msgWindow);
    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);// www.  j  a va 2 s  . co m
    status = new Label(ViewConstants.EDIT_METADATA_UPLOAD_MESSAGE);

    // Make uploading start immediately when file is selected
    receiver = new MetadataFileReceiver();
    receiver.clearBuffer();

    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);//from   ww  w. j  ava  2s .c o m

    final StringBuilder builder = new StringBuilder();
    builder.append(NAME);
    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);/* w w  w. ja va  2 s  .  co  m*/

    receiver = new MetadataFileReceiver();

    // Make uploading start immediately when file is selected
    upload = new Upload("", receiver);
    upload.setImmediate(true);
    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);/*from   w w  w  . j av a2s  .c  o m*/
    subwindow.setWidth("650px");
    VerticalLayout layout = (VerticalLayout) subwindow.getContent();
    layout.setMargin(true);
    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);

}

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

License:Open Source License

/**
 * Editing since it has a parameter// w w w  .  ja  v  a 2  s .co  m
 * 
 * @param adminDescriptor
 */
public void adminDescriptorForm(AdminDescriptor adminDescriptor) {

    // Editing
    final Window subwindow = new Window("A modal subwindow");
    subwindow.setModal(true);
    subwindow.setWidth("650px");

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

    final TextField txtName = new TextField("Name");
    txtName.setValue(adminDescriptor.getName());
    txtName.setImmediate(true);
    txtName.setValidationVisible(true);
    final TextArea txtContent = new TextArea("Content");
    txtContent.setColumns(30);
    txtContent.setRows(40);
    try {
        txtContent.setValue(adminDescriptor.getContentAsString());
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    txtContent.setColumns(30);

    Button addAdmDescButton = new Button("Add Description");
    addAdmDescButton.addListener(new ClickListener() {
        @Override
        public void buttonClick(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 {
                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);

}

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

License:Open Source License

private Button buildSaveButton(final Window modalWindow) {
    final Button saveBtn = new Button(ViewConstants.SAVE, new Button.ClickListener() {

        private MetadataRecord metadata;

        @Override//from w  ww.j  a v  a2s . co m
        public void buttonClick(@SuppressWarnings("unused") final ClickEvent event) {
            try {
                metadata = controller.getMetadata(md.name);
                metadata.setContent(metadataContent);
                controller.updateMetadata(metadata);
                controller.refreshView();
                message.setValue("");
                upload.setEnabled(true);
            } catch (final EscidocClientException e) {
                LOG.error(e.getMessage());
                mainWindow.showNotification(e.getMessage());
            }
            modalWindow.getParent().removeWindow(modalWindow);
        }
    });
    return saveBtn;
}

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

License:Open Source License

private static Button buildCancelButton(final Window modalWindow) {
    final Button cancelBtn = new Button(ViewConstants.CANCEL, new Button.ClickListener() {

        @Override//w w  w  .j a v  a2s  .c o m
        public void buttonClick(@SuppressWarnings("unused") final ClickEvent event) {
            modalWindow.getParent().removeWindow(modalWindow);
        }
    });
    return cancelBtn;
}

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

License:Open Source License

@Override
public void buttonClick(final ClickEvent event) {
    final Window subwindow = new Window("Relations");
    subwindow.setWidth("600px");
    subwindow.setModal(true);/*from w ww .j  a  va  2  s  .  c o m*/

    String id = "";
    if (event.getButton().getCaption().equals("Container Content Relations")) {
        id = containerProxy.getId();
    } else if (event.getButton().getCaption().equals("Item Content Relations")) {
        id = itemProxy.getId();
    } else {
        throw new RuntimeException("Bug: unexpected event button: " + event.getButton());
    }

    try {
        content = getRelations(itemOrContainerRepository, id, subwindow);
    } catch (final EscidocClientException e) {
        content = new HorizontalLayout();
        content.addComponent(new Label("No information available"));
    }

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