Example usage for com.vaadin.ui Panel addShortcutListener

List of usage examples for com.vaadin.ui Panel addShortcutListener

Introduction

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

Prototype

public Registration addShortcutListener(ShortcutListener shortcut) 

Source Link

Usage

From source file:com.m1kah.ui.TodoComponent.java

License:Open Source License

private void initInputRow() {
    toggleAllButton = new CheckBox();
    toggleAllButton.setId("toggle-all");

    inputField = new TextField();
    inputField.setInputPrompt("What needs to be done?");

    Panel panel = new Panel(inputField);
    panel.addShortcutListener(new ShortcutListener("", ShortcutAction.KeyCode.ENTER, null) {
        @Override//from w w  w .  j  a  v a 2 s  .com
        public void handleAction(Object o, Object o1) {
            addNewTodo();
        }
    });

    HorizontalLayout inputFieldLayout = new HorizontalLayout(toggleAllButton, panel);
    inputFieldLayout.setComponentAlignment(toggleAllButton, Alignment.MIDDLE_LEFT);
    inputFieldLayout.setId("new-todo");
    addComponent(inputFieldLayout);
}

From source file:info.magnolia.ui.framework.overlay.OverlayPresenter.java

License:Open Source License

@Override
public void openAlert(MessageStyleType type, String title, View body, String okButton,
        final AlertCallback callback) {

    final BaseDialog dialog = new LightDialog();
    dialog.addStyleName(type.getCssClass());
    dialog.addStyleName("alert");

    dialog.setCaption(title);//from   www.j  a  v  a 2  s  . c o m
    CompositeIcon icon = (CompositeIcon) Classes.getClassFactory().newInstance(type.getIconClass());
    icon.setStyleName("dialog-icon");
    dialog.setHeaderToolbar(icon);
    dialog.showCloseButton();

    dialog.setContent(body.asVaadinComponent());

    Panel shortcutPanel = new Panel();
    shortcutPanel.setStyleName("shortcut-panel");
    shortcutPanel.setHeight(100, Unit.PERCENTAGE);
    shortcutPanel.setWidth(100, Unit.PERCENTAGE);
    shortcutPanel.setContent(dialog);

    final OverlayCloser overlayCloser = openOverlay(new ViewAdapter(shortcutPanel), ModalityLevel.LIGHT);
    final ShortcutListener escapeShortcut = new ShortcutListener("Escape shortcut",
            ShortcutAction.KeyCode.ESCAPE, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            callback.onOk();
            dialog.closeSelf();
        }
    };
    shortcutPanel.addShortcutListener(escapeShortcut);
    addOkHandler(dialog, okButton, overlayCloser, callback);
    dialog.addDialogCloseHandler(createCloseHandler(overlayCloser));
}

From source file:info.magnolia.ui.framework.overlay.OverlayPresenter.java

License:Open Source License

@Override
public void openConfirmation(MessageStyleType type, String title, View body, String confirmButton,
        String cancelButton, boolean cancelIsDefault, final ConfirmationCallback callback) {
    final ConfirmationDialog dialog = new ConfirmationDialog(body.asVaadinComponent(), confirmButton,
            cancelButton, cancelIsDefault);
    dialog.addStyleName(type.getCssClass());
    dialog.addStyleName("confirmation");

    dialog.setCaption(title);/*from   w  ww. j  a  v  a  2s . com*/
    CompositeIcon icon = (CompositeIcon) Classes.getClassFactory().newInstance(type.getIconClass());
    icon.setStyleName("dialog-icon");
    dialog.setHeaderToolbar(icon);
    dialog.showCloseButton();

    dialog.setContent(body.asVaadinComponent());

    Panel shortcutPanel = new Panel();
    shortcutPanel.setStyleName("shortcut-panel");
    shortcutPanel.setHeight(100, Unit.PERCENTAGE);
    shortcutPanel.setWidth(100, Unit.PERCENTAGE);
    shortcutPanel.setContent(dialog);

    final OverlayCloser overlayCloser = openOverlay(new ViewAdapter(shortcutPanel), ModalityLevel.LIGHT);

    final ShortcutListener escapeShortcut = new ShortcutListener("Escape shortcut",
            ShortcutAction.KeyCode.ESCAPE, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            callback.onCancel();
            dialog.closeSelf();
        }
    };
    shortcutPanel.addShortcutListener(escapeShortcut);
    dialog.addConfirmationHandler(new ConfirmationDialog.ConfirmationEvent.Handler() {
        @Override
        public void onConfirmation(ConfirmationEvent event) {
            if (event.isConfirmed()) {
                callback.onSuccess();
            } else {
                callback.onCancel();
            }
            overlayCloser.close();
        }
    });
    dialog.addDialogCloseHandler(createCloseHandler(overlayCloser));
}

From source file:info.magnolia.ui.framework.overlay.OverlayPresenter.java

License:Open Source License

/**
 * Opens a notification of given {@link MessageStyleType type}, with given body; it can close automatically after a timeout.
 *///w  w w  . j a  va  2 s.  c o m
@Override
public void openNotification(final MessageStyleType type, boolean doesTimeout, View viewToShow) {
    final Notification notification = new Notification(type);
    notification.setContent(viewToShow.asVaadinComponent());

    Panel shortcutPanel = new Panel();
    shortcutPanel.setStyleName("shortcut-panel");
    shortcutPanel.setWidth(null);
    shortcutPanel.setContent(notification.asVaadinComponent());
    final OverlayCloser closer = openOverlay(new ViewAdapter(shortcutPanel), ModalityLevel.NON_MODAL);

    final ShortcutListener escapeShortcut = new ShortcutListener("Escape shortcut",
            ShortcutAction.KeyCode.ESCAPE, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            closer.close();
        }
    };
    shortcutPanel.addShortcutListener(escapeShortcut);

    notification.addCloseButtonListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            closer.close();
        }
    });

    notification.addNotificationBodyClickListener(new LayoutEvents.LayoutClickListener() {
        @Override
        public void layoutClick(LayoutEvents.LayoutClickEvent layoutClickEvent) {
            closer.setCloseTimeout(-1);
        }
    });

    if (doesTimeout) {
        closer.setCloseTimeout(TIMEOUT_SECONDS_DEFAULT);
    }

}