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

The following examples show how to use com.google.gwt.dom.client.NativeEvent. These examples are extracted from open source projects. 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 Project: EasyML   Source File: Leaf.java    License: 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 2
Source Project: cuba   Source File: CubaSingleSelectionModelConnector.java    License: 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 3
Source Project: cuba   Source File: CubaWindowWidget.java    License: 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 4
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 5
Source Project: gantt   Source File: SvgArrowWidget.java    License: 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 6
Source Project: cuba   Source File: HTML5Support.java    License: 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 7
Source Project: cuba   Source File: VDDHorizontalLayoutDropHandler.java    License: 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 8
Source Project: cuba   Source File: VDDVerticalLayoutDropHandler.java    License: 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 9
Source Project: gantt   Source File: SvgArrowWidget.java    License: 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 10
Source Project: gantt   Source File: GanttWidget.java    License: 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 11
Source Project: gantt   Source File: GanttWidget.java    License: 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 12
Source Project: incubator-retired-wave   Source File: CollapseController.java    License: 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 13
Source Project: consulo   Source File: GwtTreeCell.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Context context, Element parent, TreeState.TreeNodeState value, NativeEvent event, ValueUpdater<TreeState.TreeNodeState> valueUpdater) {
  String type = event.getType();

  if (type.equals(BrowserEvents.DBLCLICK)) {

    myCellTree.getTreeViewModel().getDoubleClickHandler().accept(value);
  }
  else {
    super.onBrowserEvent(context, parent, value, event, valueUpdater);
  }
}
 
Example 14
Source Project: incubator-retired-wave   Source File: FocusManager.java    License: Apache License 2.0 5 votes vote down vote up
private void dispatch(KeyEvent<?> event) {
     if (checkStatDialogCondition(event)) {
       StatDialog.show();
     } else {
Timer timer = null;
       if (Timing.isEnabled()) {
         Timing.enterScope();
         Timing.setScopeValue(ExecutionTree.class, new ExecutionTree());
         timer = Timing.start("Key event dispatch");
       }
       try {
         // Only respond to key events on the body element. Otherwise, the key
         // event was probably targeted to some editable input element, and that
         // should own the events.
         NativeEvent realEvent = event.getNativeEvent();
         Element target = realEvent.getEventTarget().cast();
         if (!"body".equals(target.getTagName().toLowerCase())) {
           return;
         }
         // Test that the event is meaningful (and stop bubbling if it is not).
         SignalEvent signal = SignalEventImpl.create(realEvent.<Event>cast(), true);
         if (signal != null) {
           KeyCombo key = EventWrapper.getKeyCombo(signal);
           if (globalHandler.onKeySignal(key)) {
             event.preventDefault();
           }
         }
       } finally {
         Timing.stop(timer);
         Timing.exitScope();
       }
     }
   }
 
Example 15
Source Project: EasyML   Source File: MonitorController.java    License: 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 16
Source Project: calendar-component   Source File: DateCell.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onMouseDown(MouseDownEvent event) {
    if (event.getNativeButton() == NativeEvent.BUTTON_LEFT) {
        Element e = Element.as(event.getNativeEvent().getEventTarget());
        if (e.getClassName().contains("reserved") || isDisabled()
                || !weekgrid.getParentCalendar().isRangeSelectAllowed()) {
            eventRangeStart = -1;
        } else {
            eventRangeStart = event.getY();
            eventRangeStop = eventRangeStart;
            Event.setCapture(getElement());
            setFocus(true);
        }
    }
}
 
Example 17
Source Project: cuba   Source File: CubaMainTabSheetWidget.java    License: 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 18
Source Project: cuba   Source File: Tools.java    License: 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 Project: cuba   Source File: CubaSourceCodeEditorConnector.java    License: 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 20
Source Project: cuba   Source File: VDDAbstractOrderedLayoutDropHandler.java    License: 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 21
Source Project: consulo   Source File: CellTreeNodeView.java    License: 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 22
Source Project: cuba   Source File: VLayoutDragDropMouseHandler.java    License: 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 23
@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 24
Source Project: cuba   Source File: VLayoutDragDropMouseHandler.java    License: 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 25
Source Project: cuba   Source File: HTML5Support.java    License: 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 26
Source Project: cuba   Source File: VDragDropUtil.java    License: 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 27
Source Project: cuba   Source File: VDragDropUtil.java    License: 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;
}
 
Example 28
Source Project: cuba   Source File: VDragDropUtil.java    License: 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 29
Source Project: gantt   Source File: GanttWidget.java    License: 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 30
Source Project: vaadin-sliderpanel   Source File: VSliderPanel.java    License: 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;
}