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

The following examples show how to use com.google.gwt.user.client.Event.NativePreviewHandler. 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: 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 #2
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 #3
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 #4
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 #5
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);
}