Example usage for com.vaadin.ui Window close

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

Introduction

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

Prototype

public void close() 

Source Link

Document

Method that handles window closing (from UI).

Usage

From source file:org.opennms.features.vaadin.dashboard.config.ui.HelpClickListener.java

License:Open Source License

@Override
public void buttonClick(Button.ClickEvent clickEvent) {
    final Window window = new Window("Help");

    window.setModal(true);/*from www . j  av  a  2 s .com*/
    window.setClosable(false);
    window.setResizable(false);

    window.setWidth("55%");
    window.setHeight("80%");

    m_component.getUI().addWindow(window);

    window.setContent(new VerticalLayout() {
        {
            setMargin(true);
            setSpacing(true);
            setSizeFull();

            HorizontalLayout horizontalLayout = new HorizontalLayout();
            horizontalLayout.setSizeFull();
            horizontalLayout.setSpacing(true);

            Tree tree = new Tree();
            tree.setNullSelectionAllowed(false);
            tree.setMultiSelect(false);
            tree.setImmediate(true);

            tree.addItem("Overview");
            tree.setChildrenAllowed("Overview", false);

            tree.addItem("Installed Dashlets");
            tree.setChildrenAllowed("Installed Dashlets", true);

            final List<DashletFactory> factories = m_dashletSelector.getDashletFactoryList();

            for (DashletFactory dashletFactory : factories) {
                tree.addItem(dashletFactory.getName());
                tree.setParent(dashletFactory.getName(), "Installed Dashlets");
                tree.setChildrenAllowed(dashletFactory.getName(), false);
            }
            horizontalLayout.addComponent(tree);

            for (final Object id : tree.rootItemIds()) {
                tree.expandItemsRecursively(id);
            }

            final Panel panel = new Panel();
            panel.setSizeFull();

            horizontalLayout.addComponent(panel);
            horizontalLayout.setExpandRatio(panel, 1.0f);

            addComponent(horizontalLayout);
            setExpandRatio(horizontalLayout, 1.0f);

            tree.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
                    String itemId = String.valueOf(valueChangeEvent.getProperty().getValue());

                    if ("Installed Dashlets".equals(itemId)) {
                        return;
                    }

                    if ("Overview".equals(itemId)) {
                        VerticalLayout verticalLayout = new VerticalLayout();
                        verticalLayout.setSpacing(true);
                        verticalLayout.setMargin(true);

                        verticalLayout.addComponent(new Label(getOverviewHelpHTML(), ContentMode.HTML));

                        panel.setContent(verticalLayout);
                    } else {
                        DashletFactory dashletFactory = m_dashletSelector.getDashletFactoryForName(itemId);

                        if (dashletFactory != null) {
                            if (dashletFactory.providesHelpComponent()) {
                                VerticalLayout verticalLayout = new VerticalLayout();
                                verticalLayout.setSpacing(true);
                                verticalLayout.setMargin(true);

                                Label helpTitle = new Label(
                                        "Help for Dashlet '" + dashletFactory.getName() + "'");
                                helpTitle.addStyleName("help-title");

                                verticalLayout.addComponent(helpTitle);
                                verticalLayout.addComponent(dashletFactory.getHelpComponent());

                                panel.setContent(verticalLayout);
                            }
                        }
                    }
                }
            });

            tree.select("Overview");

            addComponent(new HorizontalLayout() {
                {
                    setMargin(true);
                    setSpacing(true);
                    setWidth("100%");

                    Button closeButton = new Button("Close");

                    addComponent(closeButton);
                    setComponentAlignment(closeButton, Alignment.MIDDLE_RIGHT);
                    closeButton.addClickListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(Button.ClickEvent clickEvent) {
                            window.close();
                        }
                    });
                }
            });
        }
    });
}

From source file:org.opennms.features.vaadin.dashboard.config.ui.PreviewClickListener.java

License:Open Source License

@Override
public void buttonClick(Button.ClickEvent clickEvent) {
    final Window window = new Window("Preview");

    window.setModal(true);// ww  w.  j a  v  a 2s  .  c  o  m
    window.setClosable(false);
    window.setResizable(false);

    window.setWidth("80%");
    window.setHeight("90%");

    m_component.getUI().addWindow(window);

    final WallboardBody wallboardBody = new WallboardBody();

    window.setContent(new VerticalLayout() {
        {
            setMargin(true);
            setSpacing(true);
            setSizeFull();

            addComponent(wallboardBody);
            setExpandRatio(wallboardBody, 1.0f);
            addComponent(new HorizontalLayout() {
                {
                    setMargin(true);
                    setSpacing(true);
                    setWidth("100%");

                    Button closeButton = new Button("Close");

                    addComponent(closeButton);
                    setComponentAlignment(closeButton, Alignment.MIDDLE_RIGHT);
                    closeButton.addClickListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(Button.ClickEvent clickEvent) {
                            window.close();
                        }
                    });
                }
            });
        }
    });
    wallboardBody.setDashletSpecs(m_wallboard.getDashletSpecs());
}

From source file:org.opennms.features.vaadin.dashboard.config.ui.WallboardConfigView.java

License:Open Source License

/**
 * This method is used to add a new {@link TabSheet.Tab} component. It creates a new window querying the user for the name of the new {@link Wallboard}.
 *//*from  w ww.j  ava  2  s  .  c o m*/
protected void addNewTabComponent() {
    final Window window = new Window("New Ops Board");

    window.setModal(true);
    window.setClosable(false);
    window.setResizable(false);
    window.addCloseListener(new Window.CloseListener() {
        @Override
        public void windowClose(Window.CloseEvent e) {
            m_dashboardOverview.refreshTable();
        }
    });
    getUI().addWindow(window);

    window.setContent(new VerticalLayout() {
        TextField name = new TextField("Ops Board Name");

        {
            addComponent(new FormLayout() {
                {
                    setSizeUndefined();
                    setMargin(true);

                    String newName = "Untitled";
                    int i = 1;
                    if (WallboardProvider.getInstance().containsWallboard(newName)) {
                        do {
                            i++;
                            newName = "Untitled #" + i;
                        } while (WallboardProvider.getInstance().containsWallboard(newName));
                    }
                    name.setValue(newName);
                    addComponent(name);
                    name.focus();
                    name.selectAll();

                    name.addValidator(new AbstractStringValidator("Title must be unique") {
                        @Override
                        protected boolean isValidValue(String s) {
                            return (!WallboardProvider.getInstance().containsWallboard(s) && !"".equals(s));
                        }
                    });
                }
            });

            addComponent(new HorizontalLayout() {
                {
                    setMargin(true);
                    setSpacing(true);
                    setWidth("100%");

                    Button cancel = new Button("Cancel");
                    cancel.setDescription("Cancel editing");
                    cancel.addClickListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(Button.ClickEvent event) {
                            // NMS-7560: Toggle the tab in order to allow us to click it again
                            m_tabSheet.togglePlusTab();
                            window.close();
                        }
                    });

                    cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);
                    addComponent(cancel);
                    setExpandRatio(cancel, 1);
                    setComponentAlignment(cancel, Alignment.TOP_RIGHT);

                    Button ok = new Button("Save");
                    ok.setDescription("Save configuration");
                    ok.addClickListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(Button.ClickEvent event) {
                            if (name.isValid()) {
                                Wallboard wallboard = new Wallboard();
                                wallboard.setTitle(name.getValue());

                                WallboardProvider.getInstance().addWallboard(wallboard);
                                WallboardProvider.getInstance().save();

                                WallboardEditor wallboardEditor = new WallboardEditor(m_dashletSelector,
                                        wallboard);
                                TabSheet.Tab tab = m_tabSheet.addTab(wallboardEditor, wallboard.getTitle());

                                wallboardEditor.setTab(tab);

                                m_wallboardEditorMap.put(wallboard, tab);

                                tab.setClosable(true);

                                m_tabSheet.setSelectedTab(tab);

                                window.close();
                            }
                        }
                    });

                    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);

                    addComponent(ok);
                }
            });
        }
    });
}

From source file:org.semanticsoft.vaaclipse.p2.install.ui.impl.ContainerP2Views.java

License:Open Source License

@Override
public void initUI() {
    // TODO Auto-generated method stub

    mainLayout.removeAllComponents();// ww  w.j  a  v a 2s  .c o m
    mainLayout.addComponent((Component) listUI.get(0).getUIComponent());

    selectedBasicUI = listUI.get(0);
    final CssLayout cssLayout = new CssLayout();

    cssLayout.addComponent(buttonPrevies);
    cssLayout.addComponent(buttonNext);
    buttonNext.setEnabled(true);
    buttonInstall.setEnabled(false);
    buttonPrevies.setEnabled(false);

    cssLayout.addComponent(buttonInstall);

    buttonInstall.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            // TODO Auto-generated method stub

            boolean validate = listUI.get(maxViews - 1).validate();

            if (validate) {
                installService.installNewSoftware(listUI.get(maxViews - 1).getRepositories());

                HasComponents parent = buttonNext.getParent();
                while (!(parent instanceof Window)) {

                    parent = parent.getParent();
                }

                Window w = (Window) parent;
                w.close();
                Notification.show("Software installed");
            }

        }
    });

    Button.ClickListener listenerButton = new Button.ClickListener() {

        int index = 0;
        IBasicUI iBasicUIWas = null;
        IBasicUI iBasicUI = null;

        @Override
        public void buttonClick(ClickEvent event) {
            // TODO Auto-generated method stub

            if (event.getButton() == buttonNext) {

                boolean validate = listUI.get(index).validate();

                if (index < maxViews - 1 && validate) {
                    mainLayout.removeAllComponents();
                    index++;
                    iBasicUIWas = iBasicUI;
                    if (iBasicUI == null) {
                        iBasicUIWas = listUI.get(0);
                    }
                    iBasicUI = listUI.get(index);

                    iBasicUI.addRepositories(iBasicUIWas.getRepositories());
                    mainLayout.addComponent((Component) iBasicUI.getUIComponent());
                    handleButtons();
                }
            } else if (event.getButton() == buttonPrevies) {

                if (index > -1) {

                    if (index > 0)
                        mainLayout.removeAllComponents();
                    index--;
                    if (iBasicUI == null) {
                        iBasicUIWas = listUI.get(0);
                    }
                    iBasicUIWas = iBasicUI;
                    iBasicUI = listUI.get(index);

                    iBasicUI.addRepositories(iBasicUIWas.getRepositories());
                    mainLayout.addComponent((Component) iBasicUI.getUIComponent());
                    handleButtons();
                }
            }

            mainLayout.addComponent(cssLayout);
        }

        private void handleButtons() {
            if (index == 0) {
                buttonPrevies.setEnabled(false);
                buttonInstall.setEnabled(false);
            } else if (index == maxViews - 1) {
                buttonNext.setEnabled(false);
                buttonInstall.setEnabled(true);

            }

            if (index > 0) {
                buttonPrevies.setEnabled(true);

            }
            if (index < maxViews - 1) {
                buttonNext.setEnabled(true);

            }
        }
    };
    buttonNext.addClickListener(listenerButton);
    buttonPrevies.addClickListener(listenerButton);
    mainLayout.addComponent(cssLayout);
}

From source file:org.tltv.gantt.demo.DemoUI.java

License:Apache License

@SuppressWarnings("unchecked")
private void commit(final Window win, final FieldGroup group, final NativeSelect parentStepSelect) {
    try {//from   w  w  w .ja  v a  2 s.  c  o  m
        group.commit();
        AbstractStep step = ((BeanItem<AbstractStep>) group.getItemDataSource()).getBean();
        gantt.markStepDirty(step);
        if (parentStepSelect.isEnabled() && parentStepSelect.getValue() != null) {
            SubStep subStep = addSubStep(parentStepSelect, step);
            step = subStep;
        }
        if (step instanceof Step && !gantt.getSteps().contains(step)) {
            gantt.addStep((Step) step);
        }
        if (ganttListener != null && step instanceof Step) {
            ganttListener.stepModified((Step) step);
        }
        win.close();
    } catch (CommitException e) {
        Notification.show("Commit failed", e.getMessage(), Type.ERROR_MESSAGE);
        e.printStackTrace();
    }
}

From source file:org.tltv.gantt.demo.DemoUI.java

License:Apache License

private void cancel(final Window win, final FieldGroup group) {
    group.discard();
    win.close();
}

From source file:org.tltv.gantt.demo.DemoUI.java

License:Apache License

@SuppressWarnings("unchecked")
private void delete(final Window win, final FieldGroup group) {
    AbstractStep step = ((BeanItem<AbstractStep>) group.getItemDataSource()).getBean();
    if (step instanceof SubStep) {
        SubStep substep = (SubStep) step;
        substep.getOwner().removeSubStep(substep);
    } else {// w ww.java 2s.co  m
        gantt.removeStep((Step) step);
        if (ganttListener != null) {
            ganttListener.stepDeleted((Step) step);
        }
    }
    win.close();
}

From source file:pl.exsio.frameset.vaadin.ui.support.component.data.common.DataComponent.java

License:Open Source License

private Button createFormCancelButton(final Window formWindow) {
    Button cancel = new Button(t(config.getFormCancelButtonLabel()), FontAwesome.TIMES);
    cancel.addClickListener(new Button.ClickListener() {
        @Override//w ww.  ja v a 2 s  .  co  m
        public void buttonClick(Button.ClickEvent event) {
            formWindow.close();
        }
    });
    cancel.setStyleName("frameset-dc-form-button-cancel");
    return cancel;
}

From source file:pl.exsio.frameset.vaadin.ui.support.component.data.common.DataComponent.java

License:Open Source License

private void handleFormUpdate(final I item, final C container, final F form, final Window formWindow) {
    try {/*from w  w  w.  j  ava 2  s  .co m*/
        this.publishBeforeUpdateEvent(form, item, container);
        this.updateItem(item, container, form);
        this.publishAfterUpdateEvent(form, item, container);
        Notification.show(t(config.getEditionSuccessMessage()), Notification.Type.HUMANIZED_MESSAGE);
        formWindow.close();
    } catch (DataManipulationException ex) {
        Notification.show(t(ex.getMessage()), Notification.Type.ERROR_MESSAGE);
    } catch (Exception ex) {
        if (!(ex instanceof FormCommitException) && !(ex instanceof LifecycleEventException)) {
            Notification.show(t("core.data_component.error.update"), Notification.Type.ERROR_MESSAGE);
        }
        throw new DataManipulationException("There was an error during data update", ex);
    }
}

From source file:pl.exsio.frameset.vaadin.ui.support.component.data.common.DataComponent.java

License:Open Source License

private void handleFormAddition(final I item, final C container, final F form, final Window formWindow) {
    try {// ww w . j  a v  a  2s. c o m
        this.publishBeforeAdditionEvent(form, item, container);
        Object itemId = this.addItem(item, container, form);
        this.publishAfterAdditionEvent(form, item, container);
        Notification.show(t(config.getAdditionSuccessMessage()), Notification.Type.HUMANIZED_MESSAGE);
        formWindow.close();
        if (this.openEditionAfterAddition) {
            this.openForm((I) container.getItem(itemId), t(this.getEditionWindowTitle(item)), container,
                    MODE_EDITION);
        }
    } catch (DataManipulationException ex) {
        Notification.show(t(ex.getMessage()), Notification.Type.ERROR_MESSAGE);
    } catch (Exception ex) {
        if (!(ex instanceof FormCommitException) && !(ex instanceof LifecycleEventException)) {
            Notification.show(t("core.data_component.error.add"), Notification.Type.ERROR_MESSAGE);
        }
        throw new DataManipulationException("There was an error during data creation", ex);
    }
}