@PostConstruct private void setup() { globalHandlerRegistration = com.google.gwt.user.client.Event.addNativePreviewHandler(new NativePreviewHandler() { @Override public void onPreviewNativeEvent(NativePreviewEvent event) { if (event.getTypeInt() == com.google.gwt.user.client.Event.ONKEYPRESS && event.getNativeEvent().getCharCode() == 'm' && event.getNativeEvent().getCtrlKey()) { if (maximizedPanel != null) { maximizedPanel.unmaximize(); maximizedPanel = null; } else if (activePart != null) { WorkbenchPanelPresenter activePanelPresenter = mapPanelDefinitionToPresenter.get(activePart.getParentPanel()); activePanelPresenter.maximize(); maximizedPanel = activePanelPresenter; } } } }); }
public ResizePanel(AvroUiStyle style) { super(); DOM.sinkEvents(this.getElement(), Event.ONMOUSEDOWN | Event.ONMOUSEMOVE | Event.ONMOUSEUP | Event.ONMOUSEOVER); addStyleName(style.resizePanel()); resizeElement = DOM.createDiv(); resizeElement.addClassName(style.resizeHandle()); this.getElement().appendChild(resizeElement); Event.addNativePreviewHandler(new NativePreviewHandler() { public void onPreviewNativeEvent(NativePreviewEvent event) { if (resize) { int clientX = event.getNativeEvent().getClientX(); int clientY = event.getNativeEvent().getClientY(); int originalX = getElement().getAbsoluteLeft(); int originalY = getElement().getAbsoluteTop(); if (clientX < originalX || clientY < originalY) { event.cancel(); } } } }); }
private void startRectangle() { cleanup(); container = mapPresenter.getContainerManager().addScreenContainer(); zoomToRectangleGroup = new ZoomToRectGroup(mapPresenter.getViewPort()); escapeHandler = Event.addNativePreviewHandler(new NativePreviewHandler() { public void onPreviewNativeEvent(NativePreviewEvent event) { if (event.getTypeInt() == Event.ONKEYDOWN || event.getTypeInt() == Event.ONKEYPRESS) { if (KeyCodes.KEY_ESCAPE == event.getNativeEvent().getKeyCode()) { cleanup(); } } } }); container.add(zoomToRectangleGroup); }
/** * The constructor should first call super() to initialize the component and * then handle any initialization relevant to Vaadin. */ public CustomOverlayWidget() { setWidget(new HTML()); // Seems that we need this one overlay = new PopupPanel(); overlay.addStyleName(CLASSNAME); overlay.setAutoHideEnabled(false); overlay.setAnimationEnabled(false); overlay.setModal(false); Event.addNativePreviewHandler(new NativePreviewHandler() { public void onPreviewNativeEvent(NativePreviewEvent event) { int typeInt = event.getTypeInt(); // We're only listening for these if (typeInt == Event.ONSCROLL) { CustomOverlayWidget.this.updateOverlayPosition(); } } }); }
/** * ExtendedPopupPanel */ public ExtendedPopupPanel(boolean autoHide, boolean modal) { super(autoHide, modal); // Ensures when mouseup / onclick / ondblclick event is disabled drag flag and not consumed by popup Event.addNativePreviewHandler(new NativePreviewHandler() { @Override public void onPreviewNativeEvent(NativePreviewEvent event) { int type = event.getTypeInt(); if (type == Event.ONMOUSEUP || type == Event.ONCLICK || type == Event.ONDBLCLICK) { Main.get().activeFolderTree.disableDragged(); } } }); }
@Override // Exception squid:S1604 - GWT 2.7 does not support Java 8 @SuppressWarnings("squid:S1604") public void accept(final VDragEvent drag, final UIDL configuration, final VAcceptCallback callback) { if (isDragStarting(drag)) { final NativePreviewHandler nativeEventHandler = new NativePreviewHandler() { @Override public void onPreviewNativeEvent(NativePreviewEvent event) { if (isEscKey(event) || isMouseUp(event)) { try { hideDropTargetHints(configuration); } finally { nativeEventHandlerRegistration.removeHandler(); } } } }; nativeEventHandlerRegistration = Event.addNativePreviewHandler(nativeEventHandler); setMultiRowDragDecoration(drag); } int childCount = configuration.getChildCount(); accepted = false; for (int childIndex = 0; childIndex < childCount; childIndex++) { VAcceptCriterion crit = getCriteria(configuration, childIndex); crit.accept(drag, configuration.getChildUIDL(childIndex), this); if (Boolean.TRUE.equals(accepted)) { callback.accepted(drag); return; } } // if no VAcceptCriterion accepts and the mouse is release, an error // message is shown if (Event.ONMOUSEUP == Event.getTypeInt(drag.getCurrentGwtEvent().getType())) { showErrorNotification(drag); } }
@Override protected void init() { super.init(); dummyRootMenuBar = GWT.create(MyVMenuBar.class); CustomMenuItem item = GWT.create(CustomMenuItem.class); dummyRootMenuBar.getItems().add(item); contextMenuWidget = new MyVMenuBar(true, dummyRootMenuBar); item.setSubMenu(contextMenuWidget); // application connection that is used for all our overlays MyVOverlay.setApplicationConnection(this.getConnection()); registerRpc(ContextMenuClientRpc.class, new ContextMenuClientRpc() { @Override public void showContextMenu(int x, int y) { showMenu(x, y); } }); Event.addNativePreviewHandler(new NativePreviewHandler() { @Override public void onPreviewNativeEvent(NativePreviewEvent event) { if (event.getTypeInt() == Event.ONKEYDOWN && contextMenuWidget.isPopupShowing()) { boolean handled = contextMenuWidget.handleNavigation( event.getNativeEvent().getKeyCode(), event.getNativeEvent().getCtrlKey(), event.getNativeEvent().getShiftKey()); if (handled) { event.cancel(); } } } }); }
@Override public void addPreviewListener(NativePreviewHandler p_listener) { if( !m_previewListenerCollection.contains( p_listener ) ) { m_previewListenerCollection.add( p_listener ); } }
private void updateHandlers() { if (nativePreviewHandlerRegistration != null) { nativePreviewHandlerRegistration.removeHandler(); nativePreviewHandlerRegistration = null; } if (showing) { nativePreviewHandlerRegistration = Event.addNativePreviewHandler(new NativePreviewHandler() { public void onPreviewNativeEvent(NativePreviewEvent event) { previewNativeEvent(event); } }); } }
private void updateHandler() { if (this.previewHandler != null) { this.previewHandler.removeHandler(); this.previewHandler = null; } if (this.focused) { this.previewHandler = Event.addNativePreviewHandler(new NativePreviewHandler() { @Override public void onPreviewNativeEvent(NativePreviewEvent event) { CompositeFocusHelper.this.previewNativeEvent(event); } }); } }
/** * Through a {@link NativePreviewHandler} and its {@link NativePreviewEvent} * all mouse events are caught here before they are processed. * If the event is of type {@link Event#ONMOUSEUP} and the click was outside * the button or this drop-down panel, the panel is closed. * * @return handler registration */ private HandlerRegistration previewMouseUpHandler() { return Event.addNativePreviewHandler(new NativePreviewHandler() { public void onPreviewNativeEvent(NativePreviewEvent preview) { int typeInt = preview.getTypeInt(); if (typeInt == Event.ONMOUSEUP) { Event event = Event.as(preview.getNativeEvent()); // Can not retrieve the clicked widget from the Event, so here goes... int clientX = event.getClientX(); int clientY = event.getClientY(); // Was the button clicked? int left = button.getPageLeft(); int right = button.getPageRight(); int top = button.getPageTop(); int bottom = button.getPageBottom(); boolean mouseIsOutside = true; if (clientX > left && clientX < right && clientY > top && clientY < bottom) { mouseIsOutside = false; } if (mouseIsOutside) { // Was this panel clicked? right = getPageRight(); top = getPageTop(); bottom = getPageBottom(); if (clientX > left && clientX < right && clientY > top && clientY < bottom) { mouseIsOutside = false; } } if (mouseIsOutside) { hide(); } } } }); }
@Override public void removePreviewListener(NativePreviewHandler p_listener) { m_previewListenerCollection.remove( p_listener ); }
void addPreviewListener(NativePreviewHandler p_listener);
void removePreviewListener(NativePreviewHandler p_listener);