com.google.gwt.dom.client.NativeEvent Java Examples

The following examples show how to use com.google.gwt.dom.client.NativeEvent. 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: VDDVerticalLayoutDropHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
protected Slot getSlot(Element e, NativeEvent event) {
    Slot slot = null;
    if (getLayout().getElement() == e) {
        // Most likely between components, use the closest one in that case
        slot = findSlotVertically(12, event);
    } else {
        slot = WidgetUtil.findWidget(e, Slot.class);
        if (slot == null) {
            return null;
        }
        VAbstractOrderedLayout layout = VDragDropUtil.getSlotLayout(slot);
        while (layout != getLayout() && getLayout().getElement()
                .isOrHasChild(e.getParentElement())) {
            e = e.getParentElement();
            slot = WidgetUtil.findWidget(e, Slot.class);
            if (slot == null) {
                return null;
            }
            layout = VDragDropUtil.getSlotLayout(slot);
        }
    }
    return slot;
}
 
Example #2
Source File: SvgArrowWidget.java    From gantt with Apache License 2.0 6 votes vote down vote up
protected void cancelMove(boolean forceReset, NativeEvent event) {
    GWT.log("Relasing captured point.");
    if (captureElement != null) {
        Event.releaseCapture(captureElement);
    }
    movePointElement.removeFromParent();
    getElement().getParentElement().removeClassName(SELECTION_STYLE_NAME);
    moveRegisteration.removeHandler();
    if (touchCancelRegisteration != null) {
        touchCancelRegisteration.removeHandler();
    }
    captureElement = null;

    if (forceReset
            || (handler != null && !handler.onArrowChanged(
                    selectPredecessorMode, event))) {
        // cancel
        resetArrow();
    }
    selectPredecessorMode = false;
    selectFollowerMode = false;
    currentPointerEventId = -1;
    pendingPointerDownEvent = null;
}
 
Example #3
Source File: VDDHorizontalLayoutDropHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
protected Slot getSlot(Element e, NativeEvent event) {
    Slot slot = null;
    if (getLayout().getElement() == e) {
        // Most likely between components, use the closes one in that case
        slot = findSlotHorizontally(12, event);
    } else {
        slot = WidgetUtil.findWidget(e, Slot.class);
        if (slot == null) {
            return null;
        }
        VAbstractOrderedLayout layout = VDragDropUtil.getSlotLayout(slot);
        while (layout != getLayout() && getLayout().getElement()
                .isOrHasChild(e.getParentElement())) {
            e = e.getParentElement();
            slot = WidgetUtil.findWidget(e, Slot.class);
            if (slot == null) {
                return null;
            }
            layout = VDragDropUtil.getSlotLayout(slot);
        }
    }

    return slot;
}
 
Example #4
Source File: HTML5Support.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void onDragOver(DragOverEvent event) {
    NativeEvent nativeEvent = event.getNativeEvent();
    if (validate(nativeEvent) && vaadinDragEvent != null) {
        nativeEvent.preventDefault();
        nativeEvent.stopPropagation();

        // event stopped, just notify global handler
        // Haulmont API
        if (globalDragOverHandler != null) {
            globalDragOverHandler.onDragOver(event);
        }

        vaadinDragEvent.setCurrentGwtEvent(nativeEvent);
        VDragAndDropManager.get().setCurrentDropHandler(dropHandler);
        dropHandler.dragOver(vaadinDragEvent);
    }
}
 
Example #5
Source File: CubaWindowWidget.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    if (contextMenuHandler != null && event.getTypeInt() == Event.ONCONTEXTMENU) {
        contextMenuHandler.onContextMenu(event);
        return;
    }

    if ((event.getTypeInt() == Event.ONCLICK
            || event.getTypeInt() == Event.ONMOUSEDOWN)
            && event.getButton() != NativeEvent.BUTTON_LEFT) {
        event.preventDefault();
        event.stopPropagation();
        return;
    }

    super.onBrowserEvent(event);
}
 
Example #6
Source File: CubaTableDragSourceExtensionConnector.java    From cuba with Apache License 2.0 6 votes vote down vote up
private List<String> getDraggedRows(NativeEvent dragStartEvent) {
    List<String> draggedRows = new ArrayList<>();

    if (TableRowElement.is(dragStartEvent.getEventTarget())) {
        TableRowElement row = dragStartEvent.getEventTarget().cast();

        TableWidget tableWidget = getTableWidget();
        if (tableWidget == null) {
            draggedRows.add(String.valueOf(row.getSectionRowIndex()));
            return draggedRows;
        }

        if (isRowSelected(row)) {
            return getAllVisibleSelectedRows();
        }

        draggedRows.add(getDraggedRowKey(row));
    }

    return draggedRows;
}
 
Example #7
Source File: Leaf.java    From EasyML with Apache License 2.0 6 votes vote down vote up
/**
 * Create a leaf node for the Tree
 *
 * @param name   name of the TreeItem
 * @param module Attached moduleId for the TreeItem
 */
public Leaf(String name,
		T module,
		String style) {
	// add context menu
	this.menu = new ContextMenu();
	label = new Label(name);
	this.setWidget(label);

	label.addMouseDownHandler(new MouseDownHandler() {
		@Override
		public void onMouseDown(MouseDownEvent event) {
			// display the context menu when right click
			if (event.getNativeButton() == NativeEvent.BUTTON_RIGHT) {
				menu.setPopupPosition(event.getClientX(), event.getClientY());
				menu.show();
			}
		}
	});

	// set moduleId
	this.module = module;
	this.addStyleName("bda-treeleaf");
	if (!style.equals(""))
		this.addStyleName(style);
}
 
Example #8
Source File: SvgArrowWidget.java    From gantt with Apache License 2.0 6 votes vote down vote up
protected void handleMove(NativeEvent event) {
    Point movePoint = new Point(getTouchOrMouseClientX(event),
            getTouchOrMouseClientY(event));

    updateMovingData(movePoint);

    setWidth(movingData.getWidth());
    setHeight(movingData.getHeight());
    setTop((int) movingData.getTop());
    setLeft((int) movingData.getLeft());

    startingPoint.getStyle().setVisibility(Visibility.HIDDEN);
    endingPoint.getStyle().setVisibility(Visibility.HIDDEN);

    internalDrawCurve(movingData);
    event.stopPropagation();
}
 
Example #9
Source File: GanttWidget.java    From gantt with Apache License 2.0 6 votes vote down vote up
@Override
public void onMouseDown(MouseDownEvent event) {
    GWT.log("onMouseDown(MouseDownEvent)");
    if (event.getNativeButton() == NativeEvent.BUTTON_LEFT) {
        GanttWidget.this.onTouchOrMouseDown(event.getNativeEvent());
    } else {
        secondaryClickOnNextMouseUp = true;
        new Timer() {

            @Override
            public void run() {
                secondaryClickOnNextMouseUp = false;
            }
        }.schedule(CLICK_INTERVAL);
        event.stopPropagation();
    }
}
 
Example #10
Source File: CubaSingleSelectionModelConnector.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
protected BodyClickHandler createBodyClickHandler(Grid<JsonObject> grid) {
    return event -> {
        JsonObject row = grid.getEventCell().getRow();
        NativeEvent e = event.getNativeEvent();

        if (!e.getCtrlKey() && !e.getMetaKey()) {
            if (!grid.isSelected(row)) {
                grid.select(row);
            }
        } else {
            if (!grid.isSelected(row)) {
                grid.select(row);
            } else if (isDeselectAllowed()) {
                grid.deselect(row);
            }
        }
    };
}
 
Example #11
Source File: GanttWidget.java    From gantt with Apache License 2.0 6 votes vote down vote up
@Override
public void onDoubleClick(DoubleClickEvent event) {
    GWT.log("onDoubleClick(DoubleClickEvent)");
    if (event.getNativeButton() == NativeEvent.BUTTON_LEFT) {
        doubleClickDetectionMaxTimer.cancel();
        if (!insideDoubleClickDetectionInterval && numberOfMouseClicksDetected < 2) {
            return; // ignore double-click
        }
        if (targetBarElement != null) {
            disableClickOnNextMouseUp();
            targetBarElement = null;
        }
        Element bar = getBar(event.getNativeEvent());
        if (bar != null && numberOfMouseClicksDetected > 1) {
            fireClickRpc(bar, event.getNativeEvent());
        }
        cancelDoubleClickDetection();
    }
}
 
Example #12
Source File: VDDAbstractOrderedLayoutDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected Slot findSlotAtPosition(int clientX, int clientY,
        NativeEvent event) {
    com.google.gwt.dom.client.Element elementUnderMouse = WidgetUtil
            .getElementFromPoint(clientX, clientY);
    if (getLayout().getElement() != elementUnderMouse) {
        return getSlot(DOM.asOld(elementUnderMouse), event);
    }
    return null;
}
 
Example #13
Source File: CellTreeNodeView.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Fire an event to the {@link com.google.gwt.cell.client.AbstractCell}.
 *
 * @param event the native event
 */
@SuppressWarnings("unchecked")
protected void fireEventToCell(NativeEvent event) {
  if (parentNodeInfo == null) {
    return;
  }

  Cell<T> parentCell = parentNodeInfo.getCell();
  String eventType = event.getType();
  Element cellParent = getCellParent();
  Object key = getValueKey();
  Context context = new Context(getIndex(), 0, key);
  boolean cellWasEditing = parentCell.isEditing(context, cellParent, value);

  // Update selection.
  boolean isSelectionHandled = parentCell.handlesSelection() || KeyboardSelectionPolicy.BOUND_TO_SELECTION == tree.getKeyboardSelectionPolicy();
  HasData<T> display = (HasData<T>)parentNode.listView;
  CellPreviewEvent<T> previewEvent = CellPreviewEvent.fire(display, event, display, context, value, cellWasEditing, isSelectionHandled);

  // Forward the event to the cell.
  if (previewEvent.isCanceled() || !cellParent.isOrHasChild(Element.as(event.getEventTarget()))) {
    return;
  }
  Set<String> consumedEvents = parentCell.getConsumedEvents();
  if (consumedEvents != null && consumedEvents.contains(eventType)) {
    parentCell.onBrowserEvent(context, cellParent, value, event, parentNodeInfo.getValueUpdater());
    tree.cellIsEditing = parentCell.isEditing(context, cellParent, value);
    if (cellWasEditing && !tree.cellIsEditing) {
      CellBasedWidgetImpl.get().resetFocus(new Scheduler.ScheduledCommand() {
        @Override
        public void execute() {
          tree.setFocus(true);
        }
      });
    }
  }
}
 
Example #14
Source File: GanttUtil.java    From gantt with Apache License 2.0 5 votes vote down vote up
public static int getTouchOrMouseClientY(NativeEvent event) {
    if (isTouchEvent(event)) {
        return event.getChangedTouches().get(0).getClientY();
    } else {
        return event.getClientY();
    }
}
 
Example #15
Source File: StepWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onArrowChanged(boolean startingPointChanged, NativeEvent event) {
    Element target = GanttUtil.getElementFromPoint(GanttUtil.getTouchOrMouseClientX(event),
            GanttUtil.getTouchOrMouseClientY(event));
    if (target != null) {
        return gantt.getRpc().onStepRelationSelected(StepWidget.this, startingPointChanged, target);
    }
    return false;
}
 
Example #16
Source File: CubaSourceCodeEditorConnector.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void contextHelpIconClick(NativeEvent event) {
    MouseEventDetails details = MouseEventDetailsBuilder
            .buildMouseEventDetails(event, getWidget().getElement());

    getRpcProxy(HasContextHelpServerRpc.class).iconClick(details);
}
 
Example #17
Source File: VSliderPanel.java    From vaadin-sliderpanel with MIT License 5 votes vote down vote up
/**
 * checks whether the event comes from an element within the slider dom tree
 * 
 * @param event NativeEvent
 * @return true when events comes from within
 */
private boolean eventTargetsPopup(NativeEvent event) {
    EventTarget target = event.getEventTarget();
    if (Element.is(target)) {
        return getElement().isOrHasChild(Element.as(target));
    }
    return false;
}
 
Example #18
Source File: Tools.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPreviewNativeEvent(Event.NativePreviewEvent event) {
    super.onPreviewNativeEvent(event);

    NativeEvent nativeEvent = event.getNativeEvent();
    Element target = Element.as(nativeEvent.getEventTarget());

    if (Event.ONCLICK == event.getTypeInt()) {
        if (getElement().isOrHasChild(target)) {
            Scheduler.get().scheduleDeferred(this::hide);
        }
    }

    previewTableContextMenuEvent(event);
}
 
Example #19
Source File: MonitorController.java    From EasyML with Apache License 2.0 5 votes vote down vote up
@Override
public void onMouseUp(MouseUpEvent event) {
	super.onMouseUp(event);
	if (event.getNativeButton() == NativeEvent.BUTTON_RIGHT) {
		NodeShape shape = (NodeShape) getShapeUnderMouse();
		if (shape instanceof OutNodeShape) {
			OutNodeShape outShape = (OutNodeShape)shape;
			int x = outShape.getOffsetLeft() + 2*outShape.getRadius();
			int y = outShape.getOffsetTop() + 2*outShape.getRadius();
			outShape.getContextMenu().setPopupPosition(x,y);
			outShape.getContextMenu().show();
		}
	}
}
 
Example #20
Source File: GanttWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
private void internalMoveOrResizeCompleted(Element bar, Element newPosition, boolean move, NativeEvent event) {
    String stepUid = getStepUid(bar);
    String newStepUid = stepUid;
    if (newPosition != null && bar != newPosition) {
        newStepUid = getStepUid(newPosition);
    }

    boolean subBar = isSubBar(bar);
    long ownerStartDate = 0;
    long ownerEndDate = 0;
    double left = parseSize(bar.getStyle().getLeft(), "px");
    if (subBar) {
        double ownerLeft = bar.getParentElement().getOffsetLeft();
        left += ownerLeft;
        ownerStartDate = timeline.getDateForLeftPosition(ownerLeft);
        ownerLeft += GanttUtil.getBoundingClientRectWidth(bar.getParentElement());
        ownerEndDate = timeline.getDateForLeftPosition(ownerLeft);
    }
    long startDate = timeline.getDateForLeftPosition(left);
    left += GanttUtil.getBoundingClientRectWidth(bar);
    long endDate = timeline.getDateForLeftPosition(left);
    // update left-position to percentage (so that it scales again)
    if (subBar) {
        updateBarPercentagePosition(startDate, endDate, ownerStartDate, ownerEndDate, bar);
    } else {
        updateBarPercentagePosition(startDate, endDate, bar);
    }

    if (move) {
        if (isMovableStepsBetweenRows() && stepUid == newStepUid) {
            resetBarYPosition(bar);
        }
        getRpc().onMove(stepUid, newStepUid, startDate, endDate, event, bar);
    } else {
        getRpc().onResize(stepUid, startDate, endDate, event, bar);
    }
}
 
Example #21
Source File: CubaMainTabSheetWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void handleBadDD(NativeEvent event) {
    Element target = WidgetUtil.getElementUnderMouse(event);
    if (target == null) {
        VDragAndDropManager.get().interruptDrag();
        return;
    }

    Node targetParent = DOM.asOld(target).getParentNode();
    if (!getElement().isOrHasChild(targetParent)) {
        VDragAndDropManager.get().interruptDrag();
    }
}
 
Example #22
Source File: CollapseController.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onMouseDown(MouseDownEvent event, Element source) {
  if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
    return false;
  }
  handleClick(panel.fromToggle(source));
  return false;
}
 
Example #23
Source File: VDragDropUtil.java    From cuba with Apache License 2.0 5 votes vote down vote up
private static VTransferable createTransferable(ComponentConnector layout,
        ComponentConnector widgetConnector, NativeEvent event) {
    VTransferable transferable = new VTransferable();
    transferable.setDragSource(layout);
    transferable.setData(Constants.TRANSFERABLE_DETAIL_COMPONENT,
            widgetConnector);
    transferable.setData(Constants.TRANSFERABLE_DETAIL_MOUSEDOWN,
            MouseEventDetailsBuilder.buildMouseEventDetails(event)
                    .serialize());
    return transferable;
}
 
Example #24
Source File: VLayoutDragDropMouseHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
private boolean isElementNode(NativeEvent event) {
    EventTarget eventTarget = event.getEventTarget();
    if (Element.is(eventTarget)) {
        return true;
    }
    return false;
}
 
Example #25
Source File: FocusFrameController.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onMouseDown(MouseDownEvent event, Element source) {
  if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
    return false;
  }
  focus.focusWithoutScroll(panel.asBlip(source));
  // Cancel bubbling, so that other blips do not grab focus.
  return true;
}
 
Example #26
Source File: VLayoutDragDropMouseHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
private boolean isEventOnScrollBar(NativeEvent event) {
    Element element = Element.as(event.getEventTarget());
    ;

    if (WidgetUtil.mayHaveScrollBars(element)) {

        final int nativeScrollbarSize = WidgetUtil.getNativeScrollbarSize();

        int x = WidgetUtil.getTouchOrMouseClientX(event)
                - element.getAbsoluteLeft();
        int y = WidgetUtil.getTouchOrMouseClientY(event)
                - element.getAbsoluteTop();

        // Hopefully we have horizontal scroll.
        final int scrollWidth = element.getScrollWidth();
        final int clientWidth = element.getClientWidth();
        if (scrollWidth > clientWidth
                && clientWidth - nativeScrollbarSize < x) {
            return true;
        }

        // Hopefully we have vertical scroll.
        final int scrollHeight = element.getScrollHeight();
        final int clientHeight = element.getClientHeight();
        if (scrollHeight > clientHeight
                && clientHeight - nativeScrollbarSize < y) {
            return true;
        }

    }

    return false;
}
 
Example #27
Source File: HTML5Support.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrop(DropEvent event) {
    NativeEvent nativeEvent = event.getNativeEvent();
    if (validate(nativeEvent) && vaadinDragEvent != null) {
        nativeEvent.preventDefault();
        nativeEvent.stopPropagation();

        // event stopped, just notify global handler
        // Haulmont API
        if (globalDropHandler != null) {
            globalDropHandler.onDrop(event);
        }

        vaadinDragEvent.setCurrentGwtEvent(nativeEvent);
        VDragAndDropManager.get().setCurrentDropHandler(dropHandler);

        // FIXME only text currently supported
        String data;
        if (BrowserInfo.get().isIE()) {
            // IE does not support MIME types
            // http://www.developerfusion.com/article/144828/the-html5-drag-and-drop-api/
            data = event.getData("text");
        } else {
            data = event.getData("text/plain");
        }

        vaadinDragEvent.getTransferable().setData("html5Data", data);

        VDragAndDropManager.get().endDrag();
        vaadinDragEvent = null;
    }
}
 
Example #28
Source File: GanttUtil.java    From gantt with Apache License 2.0 5 votes vote down vote up
public static int getTouchOrMouseClientX(NativeEvent event) {
    if (isTouchEvent(event)) {
        return event.getChangedTouches().get(0).getClientX();
    } else {
        return event.getClientX();
    }
}
 
Example #29
Source File: VDragDropUtil.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a transferable for the tabsheet
 * 
 * @param tabsheet
 *            The tabsheet the event occurred
 * @param tab
 *            The tab on which the event occurred
 * @param event
 *            The event
 * @param root
 *            The root widget
 * @return
 */
private static VTransferable createTabsheetTransferableFromMouseDown(
        VDDTabSheet tabsheet, TabCaption tab, NativeEvent event) {
    VTransferable transferable = new VTransferable();
    transferable.setDragSource(Util.findConnectorFor(tabsheet));
    transferable.setData(Constants.TRANSFERABLE_DETAIL_COMPONENT,
            tabsheet.getTab(tabsheet.getTabPosition(tab)));
    transferable.setData(Constants.TRANSFERABLE_DETAIL_INDEX,
            tabsheet.getTabPosition(tab));
    transferable.setData(Constants.TRANSFERABLE_DETAIL_MOUSEDOWN,
            MouseEventDetailsBuilder.buildMouseEventDetails(event)
                    .serialize());
    return transferable;
}
 
Example #30
Source File: VDragDropUtil.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a transferable for the Accordion
 * 
 * @param accordion
 *            The Accordion where the event occurred
 * @param tab
 *            The tab on which the event occurred
 * @param event
 *            The event
 * @param root
 *            The root widget
 * @return
 */
private static VTransferable createAccordionTransferableFromMouseDown(
        VDDAccordion accordion, StackItem tab, NativeEvent event) {
    VTransferable transferable = new VTransferable();
    transferable.setDragSource(Util.findConnectorFor(accordion));
    transferable.setData(Constants.TRANSFERABLE_DETAIL_COMPONENT,
            accordion.getTab(accordion.getTabPosition(tab)));
    transferable.setData(Constants.TRANSFERABLE_DETAIL_INDEX,
            accordion.getTabPosition(tab));
    transferable.setData(Constants.TRANSFERABLE_DETAIL_MOUSEDOWN,
            MouseEventDetailsBuilder.buildMouseEventDetails(event)
                    .serialize());
    return transferable;
}