public void setKeyPressed(JavaScriptObject aValue) { if (keyPressed != aValue) { if (keyDownReg != null) { keyDownReg.removeHandler(); keyDownReg = null; } keyPressed = aValue; if (keyPressed != null && component instanceof HasKeyDownHandlers) { keyDownReg = ((HasKeyDownHandlers) component).addKeyDownHandler(new KeyDownHandler() { @Override public void onKeyDown(KeyDownEvent event) { if (keyPressed != null) { event.stopPropagation(); executeEvent(keyPressed, EventsPublisher.publish(event)); } } }); } } }
private void fixHandlers(final FilterBox box, Widget w) { if (w instanceof HasBlurHandlers) ((HasBlurHandlers)w).addBlurHandler(box.iBlurHandler); if (w instanceof HasFocusHandlers) ((HasFocusHandlers)w).addFocusHandler(box.iFocusHandler); if (w instanceof HasKeyDownHandlers) ((HasKeyDownHandlers)w).addKeyDownHandler(new KeyDownHandler() { @Override public void onKeyDown(KeyDownEvent event) { if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) if (box.isFilterPopupShowing()) box.hideFilterPopup(); } }); }
/** * Sets the KeyDown event handler in many widgets * @param handler the handler * @param widgets the widgets */ public static void addKeyDownHandler(final KeyDownHandler handler,final HasKeyDownHandlers... widgets) { if (handler != null && widgets != null && widgets.length > 0) { for (HasKeyDownHandlers w : widgets) { if (w != null) w.addKeyDownHandler(handler); } } }