Example usage for com.vaadin.ui Window Window

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

Introduction

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

Prototype

public Window(String caption) 

Source Link

Document

Creates a new, empty window with a given title.

Usage

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   ww  w .  jav  a2  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.maincontent.ParentsView.java

License:Open Source License

@SuppressWarnings("serial")
private Component buildParentsList() {
    // ViewConstants.PARENTS
    final Panel panel = new Panel();
    panel.setSizeFull();//from   www  . j ava 2 s.c  om
    panel.setStyleName(Runo.PANEL_LIGHT);

    VerticalLayout vl = new VerticalLayout();
    vl.setSizeFull();

    final CssLayout cssLayout = new CssLayout();
    cssLayout.setHeight("20px");
    buildPanelHeader(cssLayout, ViewConstants.PARENTS);
    ThemeResource ICON = new ThemeResource("images/assets/plus.png");

    Button btnAdd = new Button();
    btnAdd.setStyleName(BaseTheme.BUTTON_LINK);
    btnAdd.addStyleName("floatright paddingtop3");
    btnAdd.setWidth("20px");
    btnAdd.setIcon(ICON);
    btnAdd.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {

            final Window subwindow = new Window("Manage Organizational Unit Parents");
            subwindow.setModal(true);
            subwindow.setWidth("650px");
            VerticalLayout layout = (VerticalLayout) subwindow.getContent();
            layout.setMargin(true);
            layout.setSpacing(true);

            try {
                subwindow.addComponent(new OrgUnitParentEditView(orgUnitProxy, orgUnitProxy.getParentList(),
                        router, orgUnitController));
            } catch (EscidocClientException e) {
                orgUnitController.showError(e);
            }
            Button close = new Button("Close", new Button.ClickListener() {

                @Override
                public void buttonClick(@SuppressWarnings("unused") com.vaadin.ui.Button.ClickEvent event) {
                    (subwindow.getParent()).removeWindow(subwindow);
                }
            });
            layout.addComponent(close);
            layout.setComponentAlignment(close, Alignment.TOP_RIGHT);

            mainWindow.addWindow(subwindow);
        }
    });
    cssLayout.addComponent(btnAdd);
    vl.addComponent(cssLayout);
    List<ResourceModel> l = orgUnitProxy.getParentList();
    OUParentTableVH parentTable = new OUParentTableVH(orgUnitProxy, router, orgUnitController);
    parentTable.buildTable();
    vl.addComponent(parentTable);
    vl.setExpandRatio(parentTable, 9f);
    // TODO here comes table
    panel.setContent(vl);
    return panel;
}

From source file:org.escidoc.browser.ui.navigation.ActionHandlerImpl.java

License:Open Source License

private static Window buildSubWindow() {
    final Window subwindow = new Window(ViewConstants.DELETE_RESOURCE_WINDOW_NAME);
    subwindow.setModal(true);//ww w . ja  v  a  2s  .  c  o m
    final Label message = new Label(ViewConstants.QUESTION_DELETE_RESOURCE);
    subwindow.addComponent(message);
    return subwindow;
}

From source file:org.escidoc.browser.ui.navigation.ActionHandlerImpl.java

License:Open Source License

private void deleteItem(final ItemModel selectedItem, final Object sender) {
    final Window subwindow = new Window(DELETE_RESOURCE_WND_NAME);
    subwindow.setModal(true);/*  w  ww .j  av  a2s  .c o  m*/
    Label message = new Label(DELETE_RESOURCE);
    subwindow.addComponent(message);

    Button okConfirmed = new Button(ViewConstants.YES, new Button.ClickListener() {
        @Override
        public void buttonClick(@SuppressWarnings("unused") ClickEvent event) {
            (subwindow.getParent()).removeWindow(subwindow);
            try {
                repositories.item().finalDelete(selectedItem);
                router.getLayout().closeView(selectedItem, treeDataSource.getParent(selectedItem), sender);
                mainWindow.showNotification(
                        new Window.Notification(ViewConstants.DELETED, Notification.TYPE_TRAY_NOTIFICATION));
            } catch (EscidocClientException e) {
                mainWindow.showNotification(new Window.Notification(ViewConstants.ERROR, e.getMessage(),
                        Notification.TYPE_ERROR_MESSAGE));
            }
        }

    });

    Button cancel = new Button("Cancel", new Button.ClickListener() {
        @Override
        public void buttonClick(@SuppressWarnings("unused") ClickEvent event) {
            (subwindow.getParent()).removeWindow(subwindow);
        }
    });
    HorizontalLayout hl = new HorizontalLayout();
    hl.addComponent(okConfirmed);
    hl.addComponent(cancel);
    subwindow.addComponent(hl);
    mainWindow.addWindow(subwindow);
}

From source file:org.escidoc.browser.ui.navigation.ActionHandlerImpl.java

License:Open Source License

public void deleteContainer(final ContainerModel model, final Object sender) {
    final Window subwindow = new Window(DELETE_RESOURCE_WND_NAME);
    subwindow.setModal(true);/*w  w w .  j ava  2  s  .  c  o m*/
    final Label message = new Label(DELETE_RESOURCE);
    subwindow.addComponent(message);

    final Button okConfirmed = new Button(ViewConstants.YES, new Button.ClickListener() {
        @Override
        public void buttonClick(@SuppressWarnings("unused") final ClickEvent event) {
            (subwindow.getParent()).removeWindow(subwindow);
            deleteAllChildrenOfContainer(model, sender);
        }

    });
    final Button cancel = new Button("Cancel", new Button.ClickListener() {
        @Override
        public void buttonClick(@SuppressWarnings("unused") final ClickEvent event) {
            (subwindow.getParent()).removeWindow(subwindow);
        }
    });
    final HorizontalLayout hl = new HorizontalLayout();
    hl.addComponent(okConfirmed);
    hl.addComponent(cancel);
    subwindow.addComponent(hl);
    mainWindow.addWindow(subwindow);
}

From source file:org.escidoc.browser.ui.OrganizationSelectionView.java

License:Open Source License

public Window modalWindow() {
    final Window modalWindow = new Window("Select an Organization");
    modalWindow.setHeight("600px");
    modalWindow.setWidth("400px");
    VerticalLayout modalWindowLayout = (VerticalLayout) modalWindow.getContent();
    modalWindow.setModal(true);/*from www  .  j  a  v a2  s  . co  m*/

    modalWindow.setContent(modalWindowLayout);

    modalWindowLayout.setMargin(true);
    modalWindowLayout.setSpacing(true);

    // modalWindowLayout.setWidth("400px");
    // modalWindowLayout.setHeight("600px");
    modalWindowLayout.setSizeUndefined();

    orgUnitFilter = new TextField(ViewConstants.ORGANIZATIONAL_UNIT);

    orgUnitFilter.setWidth("300px");
    modalWindowLayout.addComponent(orgUnitFilter);

    orgUnitFilter.addListener(new TextChangeListener() {

        private SimpleStringFilter filter;

        @Override
        public void textChange(TextChangeEvent event) {
            // // TODO refactor this, the list should not return the data
            // source
            Filterable ds = (Filterable) tree.getDataSource();
            ds.removeAllContainerFilters();
            filter = new SimpleStringFilter(PropertyId.NAME, event.getText(), true, false);
            ds.addContainerFilter(filter);
        }
    });

    buildOrganizationTreeView();
    modalWindowLayout.addComponent(tree);

    Button saveButton = new Button(ViewConstants.SAVE, new Button.ClickListener() {

        @Override
        public void buttonClick(@SuppressWarnings("unused") ClickEvent event) {
            try {
                ResourceModel selected = tree.getSelected();
                List<ResourceModel> list = new ArrayList<ResourceModel>();
                list.add(selected);

                UserGroup updateGroup = repositories.group().updateGroup(resourceProxy.getId(),
                        (String) nameField.getValue(), list);
                mw.showNotification("Group, " + updateGroup.getXLinkTitle() + ", is updated",
                        Window.Notification.TYPE_TRAY_NOTIFICATION);

                dataSource.addBean(selected);
                mw.removeWindow(modalWindow);
            } catch (EscidocClientException e) {
                StringBuilder errorMessage = new StringBuilder();
                errorMessage.append("Can not update a group. Reason: ");
                errorMessage.append(e.getMessage());
                mw.showNotification(ViewConstants.ERROR, errorMessage.toString(),
                        Window.Notification.TYPE_ERROR_MESSAGE);
            }
        }
    });
    modalWindowLayout.addComponent(saveButton);
    return modalWindow;
}

From source file:org.escidoc.browser.ui.tools.BulkDeleteListener.java

License:Open Source License

private static Window buildModalWindow() {
    final Window subWindow = new Window(ViewConstants.WARNING);
    subWindow.setWidth("600px");
    subWindow.setModal(true);//from ww  w  .j  a  v  a  2  s .  co m
    return subWindow;
}

From source file:org.escidoc.browser.ui.tools.PurgeButtonListener.java

License:Open Source License

private Window buildModalDialog() {
    final Window subWindow = new Window(ViewConstants.WARNING);
    subWindow.setWidth("600px");
    subWindow.setModal(true);/*from   w  w  w. j av a2 s . c o m*/

    subWindow.addComponent(new Label(ViewConstants.PURGE_WARNING_MESSAGE, Label.CONTENT_XHTML));
    final HorizontalLayout buttonLayout = new HorizontalLayout();
    subWindow.addComponent(buttonLayout);
    buttonLayout.setSpacing(true);
    buttonLayout.addComponent(new Button(ViewConstants.YES, new ClickListener() {

        @Override
        public void buttonClick(final ClickEvent event) {
            closeDialog(subWindow);
            tryPurge(getSelectedResourceIds(filterButtonListener.getSelectedResources()));
        }
    }));

    buttonLayout.addComponent(new Button(ViewConstants.NO, new ClickListener() {

        @Override
        public void buttonClick(final ClickEvent event) {
            closeDialog(subWindow);
        }

    }));
    return subWindow;
}

From source file:org.escidoc.browser.ui.UserGroupView.java

License:Open Source License

private void addOrgUnitTable(VerticalLayout layout) {
    selectorTable = new Table();
    selectorTable.setWidth("60%");
    selectorTable.setPageLength(7);/*w w  w.  j ava  2  s .co m*/
    selectorTable.setSelectable(true);
    selectorTable.setImmediate(true);
    selectorTable.setColumnReorderingAllowed(true);

    final BeanItemContainer<ResourceModel> dataSource;
    dataSource = populateContainerTable();

    selectorTable.setContainerDataSource(dataSource);
    selectorTable.setVisibleColumns(new String[] { PropertyId.NAME, (String) PropertyId.ID });
    selectorTable.addActionHandler(new Action.Handler() {

        @Override
        public Action[] getActions(@SuppressWarnings("unused") Object target,
                @SuppressWarnings("unused") Object sender) {
            return ACTIONS_LIST;
        }

        @Override
        public void handleAction(Action action, @SuppressWarnings("unused") Object sender, Object target) {
            if (action.equals(ACTION_ADD)) {
                // mainWindow.addWindow(new OrganizationSelectionView(repositories, resourceProxy, nameField,
                // mainWindow, dataSource).modalWindow());
                openViewAddRemoveOUs();
            } else {
                try {
                    repositories.group().removeOrganization(resourceProxy.getId(),
                            ((ResourceModel) target).getId());
                    selectorTable.removeItem(target);
                    mainWindow.showNotification(
                            "Organization with the id " + resourceProxy.getId() + " is removed from the group.",
                            Window.Notification.TYPE_TRAY_NOTIFICATION);
                } catch (EscidocClientException e) {
                    mainWindow.showNotification("Error removing organizationunit: ", e.getMessage(),
                            Window.Notification.TYPE_ERROR_MESSAGE);

                }
            }
        }

        private void openViewAddRemoveOUs() {
            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);

            try {
                subwindow.addComponent(new AddOrgUnitstoGroup(router, resourceProxy, controller));
            } catch (EscidocClientException e) {
                controller.showError(e);
            }
            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);

        }
    });
    layout.addComponent(selectorTable);

}

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

License:Open Source License

public void showWindow() {

    subwindow = new Window("Change Category Type");
    subwindow.setModal(true);//  w  w  w . j av a 2s.  com

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

    final TextField txtField = new TextField("Change Category Type");
    txtField.setValue(categoryType);
    subwindow.addComponent(txtField);

    Button close = new Button("Close", new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            (subwindow.getParent()).removeWindow(subwindow);
        }
    });
    Button save = new Button("Save", new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            String newCatType = txtField.getValue().toString();
            controller.updateComponentCategory(componentId, newCatType, itemId);
            (subwindow.getParent()).removeWindow(subwindow);
        }
    });
    HorizontalLayout hl = new HorizontalLayout();
    hl.addComponent(save);
    hl.addComponent(close);

    layout.addComponent(hl);
    subwindow.setWidth("350px");
    subwindow.addComponent(layout);
    router.getMainWindow().addWindow(subwindow);

}