Search in sources :

Example 1 with KeyboardEvent

use of elemental.events.KeyboardEvent in project flow by vaadin.

the class SystemErrorHandler method handleUnrecoverableError.

/**
 * Shows an error notification for an error which is unrecoverable, using
 * the given parameters.
 *
 * @param caption
 *            the caption of the message
 * @param message
 *            the message body
 * @param details
 *            message details or {@code null} if there are no details
 * @param url
 *            a URL to redirect to when the user clicks the message or
 *            {@code null} to refresh on click
 * @param querySelector
 *            query selector to find the element under which the error will
 *            be added . If element is not found or the selector is
 *            {@code null}, body will be used
 */
public void handleUnrecoverableError(String caption, String message, String details, String url, String querySelector) {
    if (caption == null && message == null && details == null) {
        if (!isWebComponentMode()) {
            WidgetUtil.redirect(url);
        }
        return;
    }
    Element systemErrorContainer = handleError(caption, message, details, querySelector);
    if (!isWebComponentMode()) {
        systemErrorContainer.addEventListener("click", e -> WidgetUtil.redirect(url), false);
        Browser.getDocument().addEventListener(Event.KEYDOWN, e -> {
            int keyCode = ((KeyboardEvent) e).getKeyCode();
            if (keyCode == KeyCode.ESC) {
                e.preventDefault();
                WidgetUtil.redirect(url);
            }
        }, false);
    }
}
Also used : Element(elemental.dom.Element) KeyboardEvent(elemental.events.KeyboardEvent)

Example 2 with KeyboardEvent

use of elemental.events.KeyboardEvent in project che by eclipse.

the class ContentAssistWidget method handleEvent.

@Override
public void handleEvent(Event evt) {
    if (Event.KEYDOWN.equalsIgnoreCase(evt.getType())) {
        final KeyboardEvent keyEvent = (KeyboardEvent) evt;
        switch(keyEvent.getKeyCode()) {
            case KeyCodes.KEY_ESCAPE:
                Scheduler.get().scheduleDeferred(() -> hide());
                break;
            case KeyCodes.KEY_DOWN:
                selectNext();
                evt.preventDefault();
                break;
            case KeyCodes.KEY_UP:
                selectPrevious();
                evt.preventDefault();
                break;
            case KeyCodes.KEY_PAGEUP:
                selectPreviousPage();
                evt.preventDefault();
                break;
            case KeyCodes.KEY_PAGEDOWN:
                selectNextPage();
                evt.preventDefault();
                break;
            case KeyCodes.KEY_HOME:
                selectFirst();
                break;
            case KeyCodes.KEY_END:
                selectLast();
                break;
            case KeyCodes.KEY_ENTER:
                evt.preventDefault();
                evt.stopImmediatePropagation();
                validateItem(true);
                break;
            case KeyCodes.KEY_TAB:
                evt.preventDefault();
                evt.stopImmediatePropagation();
                validateItem(false);
                break;
        }
    } else if (Event.SCROLL.equalsIgnoreCase(evt.getType())) {
        updateIfNecessary();
    } else if (Event.FOCUS.equalsIgnoreCase(evt.getType())) {
        focused = true;
    }
}
Also used : KeyboardEvent(elemental.events.KeyboardEvent)

Example 3 with KeyboardEvent

use of elemental.events.KeyboardEvent in project che by eclipse.

the class PopupKeyDownListener method handleEvent.

@Override
public void handleEvent(final Event evt) {
    if (evt instanceof KeyboardEvent) {
        final KeyboardEvent keyEvent = (KeyboardEvent) evt;
        switch(keyEvent.getKeyCode()) {
            case KeyCodes.KEY_ESCAPE:
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                    @Override
                    public void execute() {
                        popupWidget.hide();
                    }
                });
                break;
            case KeyCodes.KEY_DOWN:
                focusNext();
                break;
            case KeyCodes.KEY_UP:
                focusPrevious();
                break;
            case KeyCodes.KEY_HOME:
                focusFirst();
                break;
            case KeyCodes.KEY_END:
                focusLast();
                break;
            case KeyCodes.KEY_ENTER:
                evt.preventDefault();
                evt.stopImmediatePropagation();
                validateItem();
                break;
            default:
        }
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) KeyboardEvent(elemental.events.KeyboardEvent)

Aggregations

KeyboardEvent (elemental.events.KeyboardEvent)3 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 Element (elemental.dom.Element)1