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.ikasan.dashboard.ui.administration.panel.UserDirectoriesPanel.java

License:BSD License

protected void init() {
    Label userDirectories = new Label("User Directories");
    userDirectories.setStyleName(ValoTheme.LABEL_HUGE);

    Label parapraphOne = new Label();
    parapraphOne.setCaptionAsHtml(true);
    parapraphOne.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " The table below shows the user directories currently configured for Ikasan.");
    parapraphOne.addStyleName(ValoTheme.LABEL_TINY);
    parapraphOne.addStyleName(ValoTheme.LABEL_LIGHT);

    Label parapraphTwo = new Label();
    parapraphTwo.setCaptionAsHtml(true);
    parapraphTwo.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " The order of the directory is the order in which it will be searched for users and groups."
            + " It is recommended that each user exists in a single directory.");
    parapraphTwo.addStyleName(ValoTheme.LABEL_TINY);
    parapraphTwo.addStyleName(ValoTheme.LABEL_LIGHT);

    this.mainLayout.setWidth("100%");
    this.mainLayout.setSpacing(true);

    this.mainLayout.addComponent(userDirectories);
    this.mainLayout.addComponent(parapraphOne);
    this.mainLayout.addComponent(parapraphTwo);

    Button newDirectoryButton = new Button("Add Directory");
    newDirectoryButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            final UserDirectoryManagementPanel authMethodPanel = new UserDirectoryManagementPanel(
                    new AuthenticationMethod(), securityService, authenticationProviderFactory, ldapService);

            Window window = new Window("Configure User Directory");
            window.setModal(true);
            window.setHeight("90%");
            window.setWidth("90%");

            window.setContent(authMethodPanel);

            UI.getCurrent().addWindow(window);

            window.addCloseListener(new Window.CloseListener() {
                @Override//from w w w  .  j av  a 2  s  . c  om
                public void windowClose(Window.CloseEvent e) {
                    populateAll();
                }
            });
        }
    });

    this.mainLayout.addComponent(newDirectoryButton);

    this.setWidth("100%");
    this.setHeight("100%");

    this.directoryTable = new Table();
    this.directoryTable.setWidth("100%");
    this.directoryTable.setHeight("600px");
    this.directoryTable.setCellStyleGenerator(new IkasanCellStyleGenerator());
    this.directoryTable.addContainerProperty("Directory Name", String.class, null);
    this.directoryTable.addContainerProperty("Type", String.class, null);
    this.directoryTable.addContainerProperty("Order", Layout.class, null);
    this.directoryTable.addContainerProperty("Operations", Layout.class, null);

    this.directoryTable.setColumnExpandRatio("Directory Name", 25);
    this.directoryTable.setColumnExpandRatio("Type", 25);

    this.directoryTable.setColumnAlignment("Order", Align.CENTER);
    this.directoryTable.setColumnExpandRatio("Order", 10);
    this.directoryTable.setColumnAlignment("Operations", Align.CENTER);
    this.directoryTable.setColumnWidth("Operations", 300);

    this.mainLayout.addComponent(this.directoryTable);

    this.mainLayout.setMargin(true);

    Panel wrapperPanel = new Panel();
    wrapperPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    wrapperPanel.setSizeFull();
    wrapperPanel.setContent(this.mainLayout);

    HorizontalLayout wrapperLayout = new HorizontalLayout();
    wrapperLayout.setSizeFull();
    wrapperLayout.setMargin(true);
    wrapperLayout.addComponent(wrapperPanel);

    this.setContent(wrapperLayout);
}

From source file:org.ikasan.dashboard.ui.administration.panel.UserDirectoriesPanel.java

License:BSD License

protected void populateDirectoryTable(final AuthenticationMethod authenticationMethod) {
    Button test = new Button("Test");
    test.setStyleName(BaseTheme.BUTTON_LINK);
    test.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            try {
                authenticationProviderFactory.testAuthenticationConnection(authenticationMethod);
            } catch (RuntimeException e) {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);//w w w . j  a va 2s .  c om

                Notification.show("Error occurred while testing connection!", sw.toString(),
                        Notification.Type.ERROR_MESSAGE);

                return;
            } catch (Exception e) {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);

                Notification.show("Error occurred while testing connection!", sw.toString(),
                        Notification.Type.ERROR_MESSAGE);

                return;
            }

            Notification.show("Connection Successful!");
        }
    });

    final Button enableDisableButton = new Button();

    if (authenticationMethod.isEnabled()) {
        enableDisableButton.setCaption("Disable");
    } else {
        enableDisableButton.setCaption("Enable");
    }
    enableDisableButton.setStyleName(BaseTheme.BUTTON_LINK);
    enableDisableButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            try {
                if (authenticationMethod.isEnabled()) {
                    authenticationMethod.setEnabled(false);
                } else {
                    authenticationMethod.setEnabled(true);
                }

                securityService.saveOrUpdateAuthenticationMethod(authenticationMethod);

                populateAll();
            } catch (RuntimeException e) {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);

                Notification.show("Error trying to enable/disable the authentication method!", sw.toString(),
                        Notification.Type.ERROR_MESSAGE);

                return;
            }

            if (authenticationMethod.isEnabled()) {
                enableDisableButton.setCaption("Disable");
                Notification.show("Enabled!");
            } else {
                enableDisableButton.setCaption("Enable");
                Notification.show("Disabled!");
            }
        }
    });

    Button delete = new Button("Delete");
    delete.setStyleName(BaseTheme.BUTTON_LINK);
    delete.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            try {
                securityService.deleteAuthenticationMethod(authenticationMethod);

                List<AuthenticationMethod> authenticationMethods = securityService.getAuthenticationMethods();

                directoryTable.removeAllItems();

                long order = 1;

                for (final AuthenticationMethod authenticationMethod : authenticationMethods) {
                    authenticationMethod.setOrder(order++);
                    securityService.saveOrUpdateAuthenticationMethod(authenticationMethod);
                }

                populateAll();
            } catch (RuntimeException e) {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);

                Notification.show("Error trying to delete the authentication method!", sw.toString(),
                        Notification.Type.ERROR_MESSAGE);

                return;
            }

            Notification.show("Deleted!");
        }
    });

    Button edit = new Button("Edit");
    edit.setStyleName(BaseTheme.BUTTON_LINK);
    edit.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            UserDirectoryManagementPanel authMethodPanel = new UserDirectoryManagementPanel(
                    authenticationMethod, securityService, authenticationProviderFactory, ldapService);

            Window window = new Window("Configure User Directory");
            window.setModal(true);
            window.setHeight("90%");
            window.setWidth("90%");

            window.setContent(authMethodPanel);

            UI.getCurrent().addWindow(window);
        }
    });

    Button synchronise = new Button("Synchronise");
    synchronise.setStyleName(BaseTheme.BUTTON_LINK);

    synchronise.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            try {
                ldapService.synchronize(authenticationMethod);

                authenticationMethod.setLastSynchronised(new Date());
                securityService.saveOrUpdateAuthenticationMethod(authenticationMethod);

                populateAll();
            } catch (UnexpectedRollbackException e) {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);

                logger.error("Most specific cause: " + e.getMostSpecificCause());
                e.getMostSpecificCause().printStackTrace();
                logger.error("Most specific cause: " + e.getRootCause());
                e.getRootCause().printStackTrace();

                Notification.show("Error occurred while synchronizing!", sw.toString(),
                        Notification.Type.ERROR_MESSAGE);

                return;
            } catch (RuntimeException e) {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);

                Notification.show("Error occurred while synchronizing!", sw.toString(),
                        Notification.Type.ERROR_MESSAGE);

                return;
            } catch (Exception e) {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);

                Notification.show("Error occurred while synchronizing!", sw.toString(),
                        Notification.Type.ERROR_MESSAGE);

                return;
            }

            Notification.show("Synchronized!");
        }
    });

    GridLayout operationsLayout = new GridLayout(9, 2);
    operationsLayout.setWidth("250px");
    operationsLayout.addComponent(enableDisableButton, 0, 0);
    operationsLayout.addComponent(new Label(" "), 1, 0);
    operationsLayout.addComponent(edit, 2, 0);
    operationsLayout.addComponent(new Label(" "), 3, 0);
    operationsLayout.addComponent(delete, 4, 0);
    operationsLayout.addComponent(new Label(" "), 5, 0);
    operationsLayout.addComponent(test, 6, 0);
    operationsLayout.addComponent(new Label(" "), 7, 0);
    operationsLayout.addComponent(synchronise, 8, 0);

    TextArea synchronisedTextArea = new TextArea();
    synchronisedTextArea.setRows(3);
    synchronisedTextArea.setWordwrap(true);

    if (authenticationMethod.getLastSynchronised() != null) {
        synchronisedTextArea.setValue(
                "This directory was last synchronised at " + authenticationMethod.getLastSynchronised());
    } else {
        synchronisedTextArea.setValue("This directory has not been synchronised");
    }

    synchronisedTextArea.setSizeFull();
    synchronisedTextArea.setReadOnly(true);

    operationsLayout.addComponent(synchronisedTextArea, 0, 1, 8, 1);

    HorizontalLayout orderLayout = new HorizontalLayout();
    orderLayout.setWidth("50%");

    if (authenticationMethod.getOrder() != 1) {
        Button upArrow = new Button(VaadinIcons.ARROW_UP);
        upArrow.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
        upArrow.addStyleName(ValoTheme.BUTTON_BORDERLESS);
        upArrow.addClickListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                if (authenticationMethod.getOrder() != 1) {
                    AuthenticationMethod upAuthMethod = securityService
                            .getAuthenticationMethodByOrder(authenticationMethod.getOrder() - 1);

                    upAuthMethod.setOrder(authenticationMethod.getOrder());
                    authenticationMethod.setOrder(authenticationMethod.getOrder() - 1);

                    securityService.saveOrUpdateAuthenticationMethod(upAuthMethod);
                    securityService.saveOrUpdateAuthenticationMethod(authenticationMethod);

                    populateAll();
                }
            }
        });

        orderLayout.addComponent(upArrow);
    }

    long numberOfAuthMethods = securityService.getNumberOfAuthenticationMethods();

    if (authenticationMethod.getOrder() != numberOfAuthMethods) {
        Button downArrow = new Button(VaadinIcons.ARROW_DOWN);
        downArrow.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
        downArrow.addStyleName(ValoTheme.BUTTON_BORDERLESS);
        downArrow.addClickListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                long numberOfAuthMethods = securityService.getNumberOfAuthenticationMethods();

                if (authenticationMethod.getOrder() != numberOfAuthMethods) {
                    AuthenticationMethod downAuthMethod = securityService
                            .getAuthenticationMethodByOrder(authenticationMethod.getOrder() + 1);

                    downAuthMethod.setOrder(authenticationMethod.getOrder());
                    authenticationMethod.setOrder(authenticationMethod.getOrder() + 1);

                    securityService.saveOrUpdateAuthenticationMethod(downAuthMethod);
                    securityService.saveOrUpdateAuthenticationMethod(authenticationMethod);

                    populateAll();
                }
            }
        });

        orderLayout.addComponent(downArrow);
    }

    this.directoryTable.addItem(new Object[] { authenticationMethod.getName(), "Microsoft Active Directory",
            orderLayout, operationsLayout }, authenticationMethod);
}

From source file:org.investovator.ui.main.AdminGameConfigLayout.java

License:Open Source License

private void startDailySummaryAddGameWizard() {
    // Create a sub-window and set the content
    Window subWindow = new Window("Create New Game");
    VerticalLayout subContent = new VerticalLayout();
    subContent.setMargin(true);//from   ww w .  j a va  2  s.  co  m
    subWindow.setContent(subContent);

    // Put some components in it
    subContent.addComponent(new NewDataPlaybackGameWizard(subWindow));

    // set window characteristics
    subWindow.center();
    subWindow.setClosable(false);
    subWindow.setDraggable(false);
    subWindow.setResizable(false);
    subWindow.setModal(true);

    subWindow.addCloseListener(new Window.CloseListener() {
        @Override
        public void windowClose(Window.CloseEvent closeEvent) {
            //getUI().getNavigator().navigateTo(UIConstants.MAINVIEW);
            getUI().getPage().reload();
        }
    });

    // Add it to the root component
    UI.getCurrent().addWindow(subWindow);
}

From source file:org.investovator.ui.main.components.AdminGameCreateView.java

License:Open Source License

private void startDailySummaryAddGameWizard() {
    // Create a sub-window and set the content
    Window subWindow = new Window("Create New Game");
    VerticalLayout subContent = new VerticalLayout();
    subContent.setMargin(true);/*from   www  .j  a va 2  s.  c o m*/
    subWindow.setContent(subContent);

    // Put some components in it
    subContent.addComponent(new NewDataPlaybackGameWizard(subWindow));

    // set window characteristics
    subWindow.center();
    subWindow.setClosable(false);
    subWindow.setDraggable(false);
    subWindow.setResizable(false);
    subWindow.setModal(true);

    subWindow.addCloseListener(new Window.CloseListener() {
        @Override
        public void windowClose(Window.CloseEvent closeEvent) {
            getUI().getNavigator().navigateTo(UIConstants.MAINVIEW);
            //                getUI().getPage().reload();
        }
    });

    // Add it to the root component
    UI.getCurrent().addWindow(subWindow);
}

From source file:org.jdal.vaadin.ui.FormUtils.java

License:Apache License

/**
 * Show a YES/NO confirm dialog/* ww  w. j  av a 2s.  c o  m*/
 * @param window Window to attach the dialog
 * @param msg the msg
 */
public static void showConfirmDialog(UI ui, final Command command, String msg) {

    final Window dlg = new Window("Please Confirm");
    VerticalLayout vl = new VerticalLayout();
    vl.setSizeFull();
    vl.setSpacing(true);
    vl.setMargin(true);
    Label label = new Label(msg, Label.CONTENT_XHTML);
    vl.addComponent(label);
    HorizontalLayout hl = new HorizontalLayout();
    hl.setSpacing(true);

    Button ok = new Button(StaticMessageSource.getMessage("yes"));
    ok.addClickListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {
            command.execute(null);
            closeWindow(dlg);

        }
    });
    Button cancel = new Button(StaticMessageSource.getMessage("no"));
    cancel.addClickListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {
            closeWindow(dlg);
        }
    });

    hl.setSpacing(true);
    hl.addComponent(ok);
    hl.addComponent(cancel);
    hl.setSizeFull();
    vl.addComponent(hl);
    vl.setComponentAlignment(hl, Alignment.TOP_CENTER);

    dlg.setContent(vl);
    dlg.setModal(true);
    vl.setSizeUndefined();

    ui.addWindow(dlg);
}

From source file:org.metawidget.example.vaadin.addressbook.AddressBook.java

License:BSD License

void showModalWindow(Window window) {

    window.setModal(true);
    mContent.getWindow().addWindow(window);
}

From source file:org.metawidget.example.vaadin.addressbook.AddressBookUI.java

License:BSD License

void showModalWindow(Window window) {

    window.setModal(true);
    addWindow(window);
}

From source file:org.opencms.ui.actions.CmsUserInfoDialogAction.java

License:Open Source License

/**
 * @see org.opencms.ui.actions.I_CmsWorkplaceAction#executeAction(org.opencms.ui.I_CmsDialogContext)
 *//*from   www .  j  a  v  a2 s . c o m*/
public void executeAction(final I_CmsDialogContext context) {

    CmsUserInfo dialog = new CmsUserInfo(new I_UploadListener() {

        public void onUploadFinished(List<String> uploadedFiles) {

            handleUpload(uploadedFiles, context);
        }
    }, context);
    Multimap<String, String> params = A_CmsUI.get().getParameters();
    int top = 55;
    int left = 0;
    if (params.containsKey("left")) {
        String buttonLeft = params.get("left").iterator().next();
        left = Integer.parseInt(buttonLeft) - 290;
    }
    final Window window = new Window();
    window.setModal(false);
    window.setClosable(true);
    window.setResizable(false);
    window.setContent(dialog);
    context.setWindow(window);
    window.addStyleName(OpenCmsTheme.DROPDOWN);
    UI.getCurrent().addWindow(window);
    window.setPosition(left, top);
}

From source file:org.opencms.ui.CmsVaadinUtils.java

License:Open Source License

/**
 * Shows an alert box to the user with the given information, which will perform the given action after the user clicks on OK.<p>
 *
 * @param title the title// w  w w  .  ja va2 s  .  com
 * @param message the message
 *
 * @param callback the callback to execute after clicking OK
 */
public static void showAlert(String title, String message, final Runnable callback) {

    final Window window = new Window();
    window.setModal(true);
    Panel panel = new Panel();
    panel.setCaption(title);
    panel.setWidth("500px");
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    panel.setContent(layout);
    layout.addComponent(new Label(message));
    Button okButton = new Button();
    okButton.addClickListener(new ClickListener() {

        /** The serial version id. */
        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            window.close();
            if (callback != null) {
                callback.run();
            }
        }
    });
    layout.addComponent(okButton);
    layout.setComponentAlignment(okButton, Alignment.BOTTOM_RIGHT);
    okButton.setCaption(org.opencms.workplace.Messages.get().getBundle(A_CmsUI.get().getLocale())
            .key(org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_OK_0));
    window.setContent(panel);
    window.setClosable(false);
    window.setResizable(false);
    A_CmsUI.get().addWindow(window);

}

From source file:org.opencms.ui.components.CmsBasicDialog.java

License:Open Source License

/**
 * Initializes the dialog window.<p>
 *
 * @param width the dialog width//from w w w .j av  a  2  s . c  o  m
 *
 * @return the window to be used by dialogs
 */
public static Window prepareWindow(DialogWidth width) {

    Window window = new Window();
    window.setModal(true);
    window.setClosable(true);
    int pageWidth = Page.getCurrent().getBrowserWindowWidth();
    if (((width == DialogWidth.wide) && (pageWidth < 810))
            || ((width == DialogWidth.narrow) && (pageWidth < 610))) {
        // in case the available page width does not allow the desired width, use max
        width = DialogWidth.max;
    }
    if (width == DialogWidth.max) {
        // in case max width would result in a width very close to wide or narrow, use their static width instead of relative width
        if ((pageWidth >= 610) && (pageWidth < 670)) {
            width = DialogWidth.narrow;
        } else if ((pageWidth >= 810) && (pageWidth < 890)) {
            width = DialogWidth.wide;
        }
    }
    switch (width) {
    case content:
        // do nothing
        break;
    case wide:
        window.setWidth("800px");
        break;
    case max:
        window.setWidth("90%");
        break;
    case narrow:
    default:
        window.setWidth("600px");
        break;
    }
    window.center();
    return window;
}