Example usage for com.vaadin.ui Window addCloseShortcut

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

Introduction

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

Prototype

public void addCloseShortcut(int keyCode, int... modifiers) 

Source Link

Document

Adds a close shortcut - pressing this key while holding down all (if any) modifiers specified while this Window is in focus will close the Window.

Usage

From source file:dhbw.clippinggorilla.userinterface.windows.ActivateWindow.java

public static Window get() {
    Window window = new Window();
    window.setModal(true);/*from   ww  w . j a va  2  s.  co  m*/
    window.setResizable(false);
    window.setDraggable(false);
    window.setCaption(Language.get(Word.ACTIVATION_CODE));
    window.addCloseShortcut(ShortcutAction.KeyCode.ENTER, null);

    VerticalLayout windowLayout = new VerticalLayout();
    windowLayout.setMargin(false);
    windowLayout.setSizeUndefined();

    FormLayout forms = new FormLayout();
    forms.setMargin(true);
    forms.setSizeUndefined();

    Button save = new Button(Language.get(Word.ACTIVATE));

    TextField activationCode = new TextField(Language.get(Word.ACTIVATION_CODE));
    activationCode.setMaxLength(6);
    activationCode.focus();
    activationCode.addValueChangeListener(e -> {
        if (activationCode.getValue().length() > 5) {
            save.setEnabled(true);
            activationCode.setComponentError(null);
        } else {
            save.setEnabled(false);
            activationCode.setComponentError(new UserError(Language.get(Word.ACTIVATION_CODE_SIX_CHARS),
                    AbstractErrorMessage.ContentMode.HTML, ErrorMessage.ErrorLevel.INFORMATION));
            VaadinUtils.infoNotification(Language.get(Word.ACTIVATION_CODE_SIX_CHARS));
        }
    });
    forms.addComponent(activationCode);

    Button resendMail = new Button(Language.get(Word.RESEND_ACTIVATION_CODE));
    resendMail.addStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED);
    resendMail.addClickListener(ce -> {
        try {
            UserUtils.resendActivationMail(UserUtils.getCurrent());
            VaadinUtils.infoNotification(Language.get(Word.RESEND_ACTIVATION_CODE_SUCCESSFUL));
        } catch (EmailException ex) {
            VaadinUtils.errorNotification(Language.get(Word.RESEND_ACTIVATION_CODE_FAILED));
        }
    });
    forms.addComponent(resendMail);

    GridLayout footer = new GridLayout(3, 1);
    footer.setSpacing(true);
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
    footer.setWidth(100.0f, Sizeable.Unit.PERCENTAGE);

    Label placeholder = new Label();

    Button cancel = new Button(Language.get(Word.CANCEL));
    cancel.setIcon(VaadinIcons.CLOSE);
    cancel.addClickListener(ce -> {
        window.close();
    });
    cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);

    save.setEnabled(false);
    save.setIcon(VaadinIcons.CHECK);
    save.addStyleName(ValoTheme.BUTTON_PRIMARY);
    save.addClickListener(ce -> {
        try {
            String code = activationCode.getValue();
            User user = UserUtils.getCurrent();
            if (UserUtils.activateUser(user, code)) {
                VaadinUtils.infoNotification(Language.get(Word.ACTIVATION_SUCCESSFUL));
                window.close();
            } else {
                activationCode.setValue("");
                VaadinUtils.errorNotification(Language.get(Word.ACTIVATION_FAILED));
            }
        } catch (NumberFormatException e) {
        }
    });
    save.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);

    footer.setSizeUndefined();
    footer.setWidth("100%");
    footer.addComponents(placeholder, cancel, save);
    footer.setColumnExpandRatio(0, 1);//ExpandRatio(placeholder, 1);
    footer.setComponentAlignment(cancel, Alignment.MIDDLE_CENTER);
    footer.setComponentAlignment(save, Alignment.MIDDLE_CENTER);

    windowLayout.addComponent(forms);
    windowLayout.addComponent(footer);

    window.setContent(windowLayout);
    return window;
}

From source file:dhbw.clippinggorilla.userinterface.windows.PDFWindow.java

public static Window get(Path pdfFile) {
    Window window = new Window();
    window.setModal(true);/* w  ww . j  a v  a2s  .c  o  m*/
    window.setResizable(false);
    window.setWidth("90%");
    window.setHeight("90%");
    window.addCloseShortcut(ShortcutAction.KeyCode.ENTER, null);
    BrowserFrame e = new BrowserFrame(pdfFile.getFileName().toString(), new FileResource(pdfFile.toFile()));
    e.setSizeFull();
    window.setContent(e);
    return window;
}