Java Code Examples for com.google.gwt.user.client.Event#addNativePreviewHandler()

The following examples show how to use com.google.gwt.user.client.Event#addNativePreviewHandler() . 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: EventPreviewAutoHiderRegistrar.java    From swellrt with Apache License 2.0 6 votes vote down vote up
@Override
public void registerAutoHider(final AutoHider autoHider) {
  autoHider.setRegistered(true);
  autoHiders.add(autoHider);

  if (eventPreviewRegistration == null) {
    eventPreviewRegistration = Event.addNativePreviewHandler(this);
  }

  if (onResizeRegistration == null) {
    onResizeRegistration = Window.addResizeHandler(this);
  }

  if (onHistoryRegistration == null) {
    onHistoryRegistration = History.addValueChangeHandler(this);
  }
}
 
Example 2
Source File: EventPreviewAutoHiderRegistrar.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
@Override
public void registerAutoHider(final AutoHider autoHider) {
  autoHider.setRegistered(true);
  autoHiders.add(autoHider);

  if (eventPreviewRegistration == null) {
    eventPreviewRegistration = Event.addNativePreviewHandler(this);
  }

  if (onResizeRegistration == null) {
    onResizeRegistration = Window.addResizeHandler(this);
  }

  if (onHistoryRegistration == null) {
    onHistoryRegistration = History.addValueChangeHandler(this);
  }
}
 
Example 3
Source File: WidgetComboBox.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void onFocus(FocusEvent event) {
  Object sender = event.getSource();
  getFocuses().add(sender);

  if (keyboardManagerRegistration == null) keyboardManagerRegistration = Event.addNativePreviewHandler(getKeyboardManager());

  SimplePanel value = getSelectedValue();
  if (sender == value) {
    value.addStyleName("selected-row");
    if (isChoiceButtonVisible()) getChoiceButton().setFocus(true);
  }
  else if (sender == null || sender == getListPanel()) { //on drop down list show
    Widget widget = getSelectedWidget();
    if (widget != null) getListPanel().ensureVisible(widget);
  }

  if (focuses.size() == 1) fireEvent(event);
}
 
Example 4
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 5
Source File: CubaFileUploadProgressWindow.java    From cuba with Apache License 2.0 5 votes vote down vote up
private void addTabBlockHandlers() {
    if (topBlockerRegistration == null) {
        topBlockerRegistration = Event
                .addNativePreviewHandler(topEventBlocker);
        bottomBlockerRegistration = Event
                .addNativePreviewHandler(bottomEventBlocker);
    }
}
 
Example 6
Source File: CubaTreeTableConnector.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void init() {
    super.init();

    getWidget()._delegate.cellClickListener = new TableCellClickListener() {
        @Override
        public void onClick(String columnKey, int rowKey, boolean isText) {
            getRpcProxy(CubaTableServerRpc.class).onClick(columnKey, String.valueOf(rowKey), isText);
        }
    };

    tooltipHandlerRegistration = Event.addNativePreviewHandler(new Event.NativePreviewHandler() {
        @Override
        public void onPreviewNativeEvent(Event.NativePreviewEvent event) {
            if (event.getTypeInt() != Event.ONMOUSEMOVE
                    || !Element.is(event.getNativeEvent().getEventTarget())) {
                return;
            }

            Element element = Element.as(event.getNativeEvent().getEventTarget());
            if ("div".equalsIgnoreCase(element.getTagName())) {
                String className = element.getClassName();
                if (className != null && (className.contains("v-table-caption-container")
                        || className.contains("v-table-footer-container"))) {
                    DomEvent.fireNativeEvent(event.getNativeEvent(), getWidget());
                }
            }
        }
    });
    getWidget()._delegate.totalAggregationInputHandler = (columnKey, value, isFocused) -> {
        getRpcProxy(CubaTableServerRpc.class).onAggregationTotalInputChange(columnKey, value, isFocused);
    };

    getWidget()._delegate.emptyStateLinkClickHandler = () -> getRpcProxy(CubaTableServerRpc.class).onEmptyStateLinkClick();
}
 
Example 7
Source File: CubaScrollTableConnector.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void init() {
    super.init();

    getWidget()._delegate.cellClickListener = new TableCellClickListener() {
        @Override
        public void onClick(String columnKey, int rowKey, boolean isText) {
            getRpcProxy(CubaTableServerRpc.class).onClick(columnKey, String.valueOf(rowKey), isText);
        }
    };

    tooltipHandlerRegistration = Event.addNativePreviewHandler(new Event.NativePreviewHandler() {
        @Override
        public void onPreviewNativeEvent(Event.NativePreviewEvent event) {
            if (event.getTypeInt() != Event.ONMOUSEMOVE
                    || !Element.is(event.getNativeEvent().getEventTarget())) {
                return;
            }

            Element element = Element.as(event.getNativeEvent().getEventTarget());
            if ("div".equalsIgnoreCase(element.getTagName())) {
                String className = element.getClassName();
                if (className != null && (className.contains("v-table-caption-container")
                        || className.contains("v-table-footer-container"))) {
                    DomEvent.fireNativeEvent(event.getNativeEvent(), getWidget());
                }
            }
        }
    });
    getWidget()._delegate.totalAggregationInputHandler = (columnKey, value, isFocused) -> {
        getRpcProxy(CubaTableServerRpc.class).onAggregationTotalInputChange(columnKey, value, isFocused);
    };

    getWidget()._delegate.emptyStateLinkClickHandler = () -> getRpcProxy(CubaTableServerRpc.class).onEmptyStateLinkClick();
}
 
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 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 9
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 10
Source File: ListPopupPanel2.java    From consulo with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void show() {
  clickSpyRegistration = Event.addNativePreviewHandler(new ClickSpyHandler());
  setHidden(false);
  super.show();

  adjustSize();

  setHighlightRow(getComboBox().getModel().getSelectedIndex());
  getComboBox().getDelegateHandler().onFocus(new FocusEvent() {
  });
}
 
Example 11
Source File: PopupButtonConnector.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public void init() {
    super.init();
    nativePreviewHandler = Event.addNativePreviewHandler(this);
}
 
Example 12
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 13
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 14
Source File: VSliderPanel.java    From vaadin-sliderpanel with MIT License 4 votes vote down vote up
public VSliderPanel() {
    super();
    // main wrapper of the component
    this.wrapperNode = Document.get()
                               .createDivElement();
    this.wrapperNode.setClassName(VSliderPanel.CLASSNAME + "-wrapper");
    getElement().appendChild(this.wrapperNode);

    // container that holds the content
    this.contentNode = Document.get()
                               .createDivElement();
    this.contentNode.setClassName(VSliderPanel.CLASSNAME + "-content");
    this.contentNode.getStyle()
                    .setDisplay(Display.BLOCK);
    this.wrapperNode.appendChild(this.contentNode);

    // wrapper for collapsed content line, tab with caption and icon
    this.navigationElem = Document.get()
                                  .createDivElement();
    this.navigationElem.setClassName(VSliderPanel.CLASSNAME + "-navigator");

    this.tabElem = Document.get()
                           .createDivElement();
    this.tabElem.setClassName(VSliderPanel.CLASSNAME + "-tab");
    this.navigationElem.appendChild(this.tabElem);

    this.captionNode = Document.get()
                               .createDivElement();
    this.captionNode.setClassName(VSliderPanel.CLASSNAME + "-caption");
    this.tabElem.appendChild(this.captionNode);

    DivElement toggleLabel = Document.get()
                                     .createDivElement();
    toggleLabel.setClassName(VSliderPanel.CLASSNAME + "-icon");
    this.tabElem.appendChild(toggleLabel);

    DOM.sinkEvents(this.tabElem, Event.ONCLICK);
    this.wrapperNode.appendChild(this.navigationElem);

    Event.addNativePreviewHandler(this);
}