com.google.gwt.user.client.Event.NativePreviewEvent Java Examples

The following examples show how to use com.google.gwt.user.client.Event.NativePreviewEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPreviewNativeEvent(NativePreviewEvent event) {
	// Check all events outside the combobox to see if they scroll the
	// page. We cannot use e.g. Window.addScrollListener() because the
	// scrolled element can be at any level on the page.

	// Normally this is only called when the popup is showing, but make
	// sure we don't accidentally process all events when not showing.
	if (!this.scrollPending && isShowing()
			&& !DOM.isOrHasChild(SuggestionPopup.this.getElement(), Element.as(event.getNativeEvent()
				.getEventTarget()))) {
		if (getDesiredLeftPosition() != this.leftPosition || getDesiredTopPosition() != this.topPosition) {
			updatePopupPositionOnScroll();
		}
	}

	super.onPreviewNativeEvent(event);
}
 
Example #2
Source File: VSliderPanel.java    From vaadin-sliderpanel with MIT License 6 votes vote down vote up
@Override
public void onPreviewNativeEvent(NativePreviewEvent event) {
    if (autoCollapseSlider && event != null && !event.isCanceled() && expand) {
        Event nativeEvent = Event.as(event.getNativeEvent());

        switch (nativeEvent.getTypeInt()) {
            case Event.ONMOUSEDOWN:
            case Event.ONTOUCHSTART:
            case Event.ONDBLCLICK:

                if (eventTargetsPopup(nativeEvent)) {
                    return;
                }
                if (eventTargetsInnerElementsPopover(nativeEvent)) {
                    return;
                }
                setExpand(false, true);
        }
    }
}
 
Example #3
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPreviewNativeEvent(NativePreviewEvent event) {
	// Check all events outside the combobox to see if they scroll the
	// page. We cannot use e.g. Window.addScrollListener() because the
	// scrolled element can be at any level on the page.

	// Normally this is only called when the popup is showing, but make
	// sure we don't accidentally process all events when not showing.
	if (!this.scrollPending && isShowing()
			&& !DOM.isOrHasChild(SuggestionPopup.this.getElement(), Element.as(event.getNativeEvent()
				.getEventTarget()))) {
		if (getDesiredLeftPosition() != this.leftPosition || getDesiredTopPosition() != this.topPosition) {
			updatePopupPositionOnScroll();
		}
	}

	super.onPreviewNativeEvent(event);
}
 
Example #4
Source File: UniTimeDialogBox.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPreviewNativeEvent(NativePreviewEvent event) {
	super.onPreviewNativeEvent(event);
	if (isEscapeToHide() && event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
		AriaStatus.getInstance().setText(ARIA.dialogClosed(getText()));
		hide();
	} if (isEnterToSubmit() && event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
		event.getNativeEvent().stopPropagation();
		event.getNativeEvent().preventDefault();
    	iSubmitHandler.execute();
	}
}
 
Example #5
Source File: ContextMenuConnector.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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();
                }
            }
        }
    });
}
 
Example #6
Source File: CompositeFocusHelper.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
			}
		});
	}
}
 
Example #7
Source File: CompositeFocusHelper.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void previewNativeEvent(NativePreviewEvent event) {
	if (event.isCanceled() || event.isConsumed()) {
		event.cancel();
		return;
	}

	boolean eventTargetsContainerOrPartner = this.eventTargetsContainerOrPartner(event);

	int type = event.getTypeInt();
	switch (type) {
		case Event.ONMOUSEDOWN:
		case Event.ONTOUCHSTART:
			if (!eventTargetsContainerOrPartner) {
				this.blur();
				return;
			}
			break;
		case Event.ONFOCUS:
			// Not used because focus events are not previewed yet
			if (!eventTargetsContainerOrPartner) {
				this.blur();
			} else {
				this.focus();
			}
			break;
		default:
			break;
	}
}
 
Example #8
Source File: CompositeFocusHelper.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean eventTargetsContainerOrPartner(NativePreviewEvent event) {
	Event nativeEvent = Event.as(event.getNativeEvent());
	EventTarget target = nativeEvent.getEventTarget();
	if (Element.is(target)) {
		return this.isOrHasChildOfContainerOrPartner(Element.as(target));
	}
	return false;
}
 
Example #9
Source File: SimpleDropdown.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean eventTargetsDropDown(NativePreviewEvent event) {
	Event nativeEvent = Event.as(event.getNativeEvent());
	EventTarget target = nativeEvent.getEventTarget();
	if (Element.is(target)) {
		return this.getElement().isOrHasChild(Element.as(target));
	}
	return false;
}
 
Example #10
Source File: StudentSchedule.java    From unitime with Apache License 2.0 5 votes vote down vote up
public void checkAccessKeys(NativePreviewEvent event) {
	if (event.getTypeInt() == Event.ONKEYUP && (event.getNativeEvent().getAltKey() || event.getNativeEvent().getCtrlKey())) {
		for (Map.Entry<Character, Integer> entry: iTabAccessKeys.entrySet())
			if (event.getNativeEvent().getKeyCode() == Character.toLowerCase(entry.getKey()) || event.getNativeEvent().getKeyCode()  == Character.toUpperCase(entry.getKey())) {
				iTabs.selectTab(entry.getValue());
			}
	}
}
 
Example #11
Source File: ExtendedPopupPanel.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
			}
		}
	});
}
 
Example #12
Source File: MockComponent.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPreviewNativeEvent(NativePreviewEvent event) {
  super.onPreviewNativeEvent(event);
  switch (event.getTypeInt()) {
    case Event.ONKEYDOWN:
      if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
        hide();
      } else if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
        hide();
        MockComponent.this.delete();
      }
      break;
  }
}
 
Example #13
Source File: ViewClientCriterion.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks if the origin of the given event is a pressed ESC key.
 *
 * @param event
 *            the event to analyze
 * @return <code>true</code> if the origin of the event is a pressed ESC
 *         key, otherwise <code>false</code>.
 */
private static boolean isEscKey(final NativePreviewEvent event) {
    final int typeInt = event.getTypeInt();
    if (typeInt == Event.ONKEYDOWN) {
        final int keyCode = event.getNativeEvent().getKeyCode();
        if (KeyCodes.KEY_ESCAPE == keyCode) {
            return true;
        }
    }
    return false;
}
 
Example #14
Source File: EventPreviewAutoHiderRegistrar.java    From swellrt with Apache License 2.0 4 votes vote down vote up
@Override
public void onPreviewNativeEvent(NativePreviewEvent previewEvent) {
  if (autoHiders.isEmpty()) {
    return;
  }

  // TODO(danilatos,user,user): Push signal down a layer - clean this up.
  Event event = Event.as(previewEvent.getNativeEvent());
  int lowLevelType = event.getTypeInt();

  // TODO(danilatos): Insert this logic deeply rather than
  // sprinkling it in event handlers. Also the return value
  // of onEventPreview is the reverse of signal handlers.
  SignalEvent signal = SignalEventImpl.create(event, false);
  if (signal == null) {
    return;
  }

  // Key events (excluding escape) and mousewheel events use hideTopmostAutoHiderForKeyEvent
  if (lowLevelType == Event.ONMOUSEWHEEL || signal.isKeyEvent()) {
    if (hideTopmostAutoHiderForKeyEvent(false)) {
      // TODO(user): We don't call previewEvent.cancel() here, since for the floating-buttons
      // menu we want, for example, space-bar to still shift focus to the next blip.
      // The to-do is to audit the previewEvent.cancel call below and see why it's there (and if
      // it's not needed, eliminate it).
      return;
    }
  }

  // Pressing escape at any time causes us to close and discard the event.
  if (signal.getKeySignalType() == KeySignalType.NOEFFECT &&
      event.getKeyCode() == KeyCodes.KEY_ESCAPE) {
    if (hideTopmostAutoHiderForKeyEvent(true)) {
      previewEvent.cancel();
      return;
    }
  }

  // Click events and mouse-wheel events that fall through use hideAllAfter.
  if (lowLevelType == Event.ONMOUSEDOWN || lowLevelType == Event.ONMOUSEWHEEL) {
    hideAllAfter(signal.getTarget());
  }

  // Otherwise we don't do anything and the event continues as usual.
}
 
Example #15
Source File: ViewClientCriterion.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
@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(final NativePreviewEvent event) {
                if (isEscKey(event) || isMouseUp(event)) {
                    try {
                        hideDropTargetHints(configuration);
                    } finally {
                        nativeEventHandlerRegistration.removeHandler();
                    }
                }
            }
        };

        nativeEventHandlerRegistration = Event.addNativePreviewHandler(nativeEventHandler);
        setMultiRowDragDecoration(drag);
    }

    final int childCount = configuration.getChildCount();
    accepted = false;
    for (int childIndex = 0; childIndex < childCount; childIndex++) {
        final 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);
    }

    errorMessage = configuration.getStringAttribute(ERROR_MESSAGE);
}
 
Example #16
Source File: AboutPopup.java    From document-management-system with GNU General Public License v2.0 4 votes vote down vote up
public void onPreviewNativeEvent(NativePreviewEvent event) {
	if (event.getTypeInt() == Event.ONKEYPRESS) {
		futurama.evaluateKey((char) event.getNativeEvent().getKeyCode());
	}
}
 
Example #17
Source File: VLayoutDragDropMouseHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
/**
 * Initiates the drag only on the first move event
 *
 * @param originalEvent
 *            the original Mouse Down event. Only events on elements are
 *            passed in here (Element.as() is safe without check here)
 */
protected void initiateDragOnMove(final NativeEvent originalEvent) {
    EventTarget eventTarget = originalEvent.getEventTarget();

    boolean stopEventPropagation = false;

    Element targetElement = Element.as(eventTarget);
    Widget target = WidgetUtil.findWidget(targetElement, null);
    Widget targetParent = target.getParent();

    // Stop event propagation and prevent default behaviour if
    // - target is *not* a VTabsheet.TabCaption or
    // - drag mode is caption mode and widget is caption
    boolean isTabCaption = WidgetUtil.findWidget(target.getElement(), TabCaption.class) != null;
    boolean isCaption = VDragDropUtil.isCaptionOrCaptionless(targetParent);

    if (dragMode == LayoutDragMode.CLONE && isTabCaption == false) {

        stopEventPropagation = true;

        // overwrite stopEventPropagation flag again if
        // - root implements VHasDragFilter but
        // - target is not part of its drag filter and
        // - target is not a GWT Label based widget
        if (root instanceof VHasDragFilter) {
            if (((VHasDragFilter) root).getDragFilter()
                    .isDraggable(target) == false &&
	(target instanceof LabelBase) == false) {
                    stopEventPropagation = false;
            }
        }

        if (root instanceof VHasGrabFilter) {
            VGrabFilter grabFilter = ((VHasGrabFilter) root).getGrabFilter();
            if (grabFilter != null && !grabFilter.canBeGrabbed(root, target)) {
                return;
            }
        }
    }

    if (dragMode == LayoutDragMode.CAPTION && isCaption) {
        stopEventPropagation = true;
    }

    if (isElementNotDraggable(targetElement)) {
        stopEventPropagation = false;
    }

    if (stopEventPropagation) {
        originalEvent.stopPropagation();
        originalEvent.preventDefault();

        // Manually focus as preventDefault() will also cancel focus
        targetElement.focus();
    }

    mouseDownHandlerReg = Event
            .addNativePreviewHandler(new NativePreviewHandler() {

                @Override
                public void onPreviewNativeEvent(NativePreviewEvent event) {
                    int type = event.getTypeInt();
                    if (type == Event.ONMOUSEUP
                            || type == Event.ONTOUCHCANCEL
                            || type == Event.ONTOUCHEND) {
                        mouseDownHandlerReg.removeHandler();
                        mouseDownHandlerReg = null;

                    } else if (type == Event.ONMOUSEMOVE
                            || type == Event.ONTOUCHMOVE) {
                        mouseDownHandlerReg.removeHandler();
                        mouseDownHandlerReg = null;
                        initiateDrag(originalEvent);
                    }
                }
            });
}
 
Example #18
Source File: EventPreviewAutoHiderRegistrar.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
@Override
public void onPreviewNativeEvent(NativePreviewEvent previewEvent) {
  if (autoHiders.isEmpty()) {
    return;
  }

  // TODO(danilatos,user,user): Push signal down a layer - clean this up.
  Event event = Event.as(previewEvent.getNativeEvent());
  int lowLevelType = event.getTypeInt();

  // TODO(danilatos): Insert this logic deeply rather than
  // sprinkling it in event handlers. Also the return value
  // of onEventPreview is the reverse of signal handlers.
  SignalEvent signal = SignalEventImpl.create(event, false);
  if (signal == null) {
    return;
  }

  // Key events (excluding escape) and mousewheel events use hideTopmostAutoHiderForKeyEvent
  if (lowLevelType == Event.ONMOUSEWHEEL || signal.isKeyEvent()) {
    if (hideTopmostAutoHiderForKeyEvent(false)) {
      // TODO(user): We don't call previewEvent.cancel() here, since for the floating-buttons
      // menu we want, for example, space-bar to still shift focus to the next blip.
      // The to-do is to audit the previewEvent.cancel call below and see why it's there (and if
      // it's not needed, eliminate it).
      return;
    }
  }

  // Pressing escape at any time causes us to close and discard the event.
  if (signal.getKeySignalType() == KeySignalType.NOEFFECT &&
      event.getKeyCode() == KeyCodes.KEY_ESCAPE) {
    if (hideTopmostAutoHiderForKeyEvent(true)) {
      previewEvent.cancel();
      return;
    }
  }

  // Click events and mouse-wheel events that fall through use hideAllAfter.
  if (lowLevelType == Event.ONMOUSEDOWN || lowLevelType == Event.ONMOUSEWHEEL) {
    hideAllAfter(signal.getTarget());
  }

  // Otherwise we don't do anything and the event continues as usual.
}
 
Example #19
Source File: PopupButtonConnector.java    From cuba with Apache License 2.0 4 votes vote down vote up
public void onPreviewNativeEvent(NativePreviewEvent event) {
    if (isEnabled()) {
        Element target = Element
                .as(event.getNativeEvent().getEventTarget());
        switch (event.getTypeInt()) {
            case Event.ONCLICK:
                if (getWidget().isOrHasChildOfButton(target)) {
                    if (getState().popupVisible && getState().buttonClickTogglesPopupVisibility) {
                        getWidget().sync();
                        rpc.setPopupVisible(false);
                    }
                }
                break;
            case Event.ONMOUSEDOWN:
                if (!getWidget().isOrHasChildOfPopup(target)
                        && !getWidget().isOrHasChildOfConsole(target)
                        && !getWidget().isOrHasChildOfButton(target)
                        && getState().closePopupOnOutsideClick) {
                    if (getState().popupVisible) {
                        getWidget().sync();
                        rpc.setPopupVisible(false);
                    }
                }
                break;
            case Event.ONKEYPRESS:
                if (getWidget().isOrHasChildOfPopup(target)) {
                    // Catch children that use keyboard, so we can unfocus
                    // them
                    // when
                    // hiding
                    getWidget().addToActiveChildren(target);
                }
                break;
            case Event.ONKEYDOWN:
                if (getState().popupVisible) {
                    getWidget().onKeyDownOnVisiblePopup(event.getNativeEvent(), this);
                }
                break;
            default:
                break;
        }
    }
}
 
Example #20
Source File: ViewClientCriterion.java    From hawkbit with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Checks if the given event is of type <code>Event.ONMOUSEUP</code>.
 *
 * @param event
 *            the event to analyze
 * @return <code>true</code> if the given event is of type
 *         <code>Event.ONMOUSEUP</code>, otherwise <code>false</code>.
 */
private static boolean isMouseUp(final NativePreviewEvent event) {
    return Event.ONMOUSEUP == Event.getTypeInt(event.getNativeEvent().getType());
}