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

The following examples show how to use com.google.gwt.dom.client.EventTarget. 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: TimetableGrid.java    From unitime with Apache License 2.0 6 votes vote down vote up
public void onBrowserEvent(Event event) {
	EventTarget related = event.getRelatedEventTarget();
    switch (DOM.eventGetType(event)) {
	case Event.ONCLICK:
		if (getCell().hasId() && getCell().getType() == TimetableGridCell.Type.Class) {
			UniTimeFrameDialog.openDialog(MESSAGES.dialogSuggestions(), "gwt.jsp?page=suggestions&menu=hide&id=" + getCell().getId(),"900","90%");
			select(false);
		}
		break;
	case Event.ONMOUSEOVER:
        if (related == null || !getElement().isOrHasChild((Element)related.cast())) {
			select(true);
        }
		break;
	case Event.ONMOUSEOUT:
        if (related == null || !getElement().isOrHasChild((Element)related.cast())) {
        	select(false);
        }
		break;
	}
   
    super.onBrowserEvent(event);
}
 
Example #2
Source File: CubaSuggestionFieldWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void handleOnBlur(BlurEvent event) {
    removeStyleName(MODIFIED_STYLENAME);

    if (BrowserInfo.get().isIE()) {
        if (iePreventBlur) {
            textField.setFocus(true);
            iePreventBlur = false;
        } else {
            resetComponentState();
        }
    } else {
        if (!suggestionsPopup.isShowing()) {
            resetComponentState();
            return;
        }

        EventTarget eventTarget = event.getNativeEvent().getRelatedEventTarget();
        if (eventTarget == null) {
            resetComponentState();
            return;
        }

        if (Element.is(eventTarget)) {
            Widget widget = WidgetUtil.findWidget(Element.as(eventTarget), null);
            if (widget != suggestionsContainer) {
                resetComponentState();
            }
        }
    }
}
 
Example #3
Source File: VLayoutDragDropMouseHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
private boolean isChildOfRoot(NativeEvent event) {
    EventTarget eventTarget = event.getEventTarget();
    Element targetElement = Element.as(eventTarget);
    if (root.getElement() != targetElement
            && root.getElement().isOrHasChild(targetElement)) {
        return true;
    }
    return false;
}
 
Example #4
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 #5
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 #6
Source File: VSliderPanel.java    From vaadin-sliderpanel with MIT License 5 votes vote down vote up
/**
 * checks whether the event come's from a elements that lays visually within the slider<br>
 * it doesn't lay directly in the dom tree - for example dropdown popups
 * 
 * @param event NativeEvent
 * @return true when events comes from within
 */
private boolean eventTargetsInnerElementsPopover(NativeEvent event) {
    EventTarget target = event.getEventTarget();
    if (Element.is(target)) {
        Element targetElement = Element.as(target);

        int absoluteLeft = targetElement.getAbsoluteLeft();
        int absoluteTop = targetElement.getAbsoluteTop();
        
        return contentNode.getAbsoluteLeft() <= absoluteLeft && contentNode.getAbsoluteRight() >= absoluteLeft && contentNode.getAbsoluteTop() <= absoluteTop
                && contentNode.getAbsoluteBottom() >= absoluteTop;
    }
    return false;
}
 
Example #7
Source File: InputBoolean.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean eventTargetsLabelOrChild(DomEvent<?> event) {
	Event nativeEvent = Event.as(event.getNativeEvent());
	EventTarget target = nativeEvent.getEventTarget();
	if (Element.is(target)) {
		return this.labelElement.isOrHasChild(Element.as(target));
	}
	return false;
}
 
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: WidgetComboBox.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * See class docs
 */
@Override
public void onPreviewNativeEvent(Event.NativePreviewEvent event) {
  NativeEvent nativeEvent = event.getNativeEvent();
  EventTarget eventTarget = nativeEvent.getEventTarget();
  if (!Element.is(eventTarget)) //chrome fix
  {
    return;
  }

  Element target = (Element)Element.as(eventTarget);

  int type = event.getTypeInt();
  if (type == Event.ONKEYDOWN) {
    setKeyPressed(true);
    if (DOM.getCaptureElement() != null) return;

    boolean eventTargetsPopup = (target != null) && DOM.isOrHasChild(getElement(), target);
    int button = nativeEvent.getKeyCode();
    boolean alt = nativeEvent.getAltKey();
    boolean ctrl = nativeEvent.getCtrlKey();
    boolean shift = nativeEvent.getShiftKey();

    boolean hasModifiers = alt || ctrl || shift;

    if (eventTargetsPopup && isListPanelOpened()) {
      if (button == KeyCodes.KEY_UP && !hasModifiers) {
        moveCursor(-1);
        cancelAndPrevent(event);
      }
      else if (button == KeyCodes.KEY_DOWN && !hasModifiers) {
        moveCursor(1);
        cancelAndPrevent(event);
      }
      else if (button == KeyCodes.KEY_ENTER && !hasModifiers) {
        select(getHighlightRow());
        getChoiceButton().setFocus(false);
        ChangeEvent changeEvent = new ComboBoxChangeEvent(getHighlightRow(), ComboBoxChangeEvent.ChangeEventInputDevice.KEYBOARD);
        fireEvent(changeEvent);
        setKeyPressed(false);
      }
      else if (button == KeyCodes.KEY_ESCAPE && !hasModifiers) {
        hideList();
        setKeyPressed(false);
      }
      else if (button == KeyCodes.KEY_TAB && (!hasModifiers || !alt && !ctrl && shift)) {
        hideList();
        setKeyPressed(false);
      }
    }
    else if (eventTargetsPopup && !hasModifiers && button == KeyCodes.KEY_ENTER && getModel().getCount() > 0) {
      showList(true);
    }
  }
  else if (type == Event.ONKEYUP) {
    setKeyPressed(false);
  }
}
 
Example #11
Source File: DateCellDayItem.java    From calendar-component with Apache License 2.0 4 votes vote down vote up
@Override
public void onMouseUp(MouseUpEvent event) {
    if (mouseMoveCanceled
            || event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
        return;
    }

    Event.releaseCapture(getElement());
    setFocus(false);
    if (moveRegistration != null) {
        moveRegistration.removeHandler();
        moveRegistration = null;
    }

    int endX = event.getClientX();
    int endY = event.getClientY();
    int xDiff = 0, yDiff = 0;
    if (startX != -1 && startY != -1) {
        // Drag started
        xDiff = startX - endX;
        yDiff = startY - endY;
    }

    startX = -1;
    startY = -1;
    mouseMoveStarted = false;
    Style s = getElement().getStyle();
    s.setZIndex(1);

    if (!clickTargetsResize()) {

        // check if mouse has moved over threshold of 3 pixels
        boolean mouseMoved = (xDiff < -3 || xDiff > 3 || yDiff < -3 || yDiff > 3);

        if (!weekGrid.getCalendar().isDisabled() && mouseMoved) {
            // Item Move:
            // - calendar must be enabled
            // - calendar must not be in read-only mode
            weekGrid.itemMoved(this);

        } else if (!weekGrid.getCalendar().isDisabled() && getCalendarItem().isClickable()) {
            // Item Click:
            // - calendar must be enabled (read-only is allowed)
            EventTarget et = event.getNativeEvent().getEventTarget();
            Element e = Element.as(et);
            if (e == caption || e == eventContent
                    || e.getParentElement() == caption) {
                if (weekGrid.getCalendar().getItemClickListener() != null) {
                    weekGrid.getCalendar().getItemClickListener().itemClick(calendarItem);
                }
            }
        }

    } else {
        // click targeted resize bar
        removeGlobalResizeStyle();
        if (weekGrid.getCalendar().getItemResizeListener() != null) {
            weekGrid.getCalendar().getItemResizeListener().itemResized(calendarItem);
        }
        dateCell.recalculateItemWidths();
    }
}
 
Example #12
Source File: SuggestionMenu.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
private void handleEventInner(Event event) {
  switch (DOM.eventGetType(event)) {
    case Event.ONCONTEXTMENU:
      event.preventDefault();
      break;
    case Event.ONKEYPRESS:
    case Event.ONKEYDOWN: {
      // NOTE(user): It is necessary to stop propagation on the key events to
      // prevent them from leaking to the blip/wave presenters.
      int keyCode = DOM.eventGetKeyCode(event);

      // Move left/right to previous/next drop down widget
      switch (keyCode) {
        case KeyCodes.KEY_LEFT:
        case KeyCodes.KEY_RIGHT:
          handler.handleLeftRight(keyCode == KeyCodes.KEY_RIGHT);
          event.stopPropagation();
          return;
        case KeyCodes.KEY_ENTER:
          event.stopPropagation();
      }

      if (keyCode >= '1' && keyCode <= '9') {
        // TODO(danilatos): Is this ok? i18n etc?
        int index = keyCode - '1';

        if (index >= 0 && index < getItems().size()) {
          MenuItem item = getItems().get(index);
          if (item == null) {
            return;
          }

          item.getCommand().execute();
          DOM.eventPreventDefault(event);
        }
      }
      break;
    }
    case Event.ONMOUSEOUT: {
      // Need to check that we really seem to have left the menu, as
      // mouse-out events get triggered whenever the mouse moves between
      // selections in the menu.
      EventTarget target = event.getRelatedEventTarget();
      Element targetElement = Element.as(target);
      if (!getElement().isOrHasChild(targetElement)) {
        handler.handleMouseOut();
      }
      break;
    }
    case Event.ONMOUSEOVER: {
      handler.handleMouseOver();
      break;
    }
  }
}
 
Example #13
Source File: FakeSignalEvent.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
@Override
public EventTarget getEventTarget() {
  // TODO Auto-generated method stub
  return null;
}
 
Example #14
Source File: SuggestionMenu.java    From swellrt with Apache License 2.0 4 votes vote down vote up
private void handleEventInner(Event event) {
  switch (DOM.eventGetType(event)) {
    case Event.ONCONTEXTMENU:
      event.preventDefault();
      break;
    case Event.ONKEYPRESS:
    case Event.ONKEYDOWN: {
      // NOTE(user): It is necessary to stop propagation on the key events to
      // prevent them from leaking to the blip/wave presenters.
      int keyCode = DOM.eventGetKeyCode(event);

      // Move left/right to previous/next drop down widget
      switch (keyCode) {
        case KeyCodes.KEY_LEFT:
        case KeyCodes.KEY_RIGHT:
          handler.handleLeftRight(keyCode == KeyCodes.KEY_RIGHT);
          event.stopPropagation();
          return;
        case KeyCodes.KEY_ENTER:
          event.stopPropagation();
      }

      if (keyCode >= '1' && keyCode <= '9') {
        // TODO(danilatos): Is this ok? i18n etc?
        int index = keyCode - '1';

        if (index >= 0 && index < getItems().size()) {
          MenuItem item = getItems().get(index);
          if (item == null) {
            return;
          }

          item.getCommand().execute();
          DOM.eventPreventDefault(event);
        }
      }
      break;
    }
    case Event.ONMOUSEOUT: {
      // Need to check that we really seem to have left the menu, as
      // mouse-out events get triggered whenever the mouse moves between
      // selections in the menu.
      EventTarget target = event.getRelatedEventTarget();
      Element targetElement = Element.as(target);
      if (!getElement().isOrHasChild(targetElement)) {
        handler.handleMouseOut();
      }
      break;
    }
    case Event.ONMOUSEOVER: {
      handler.handleMouseOver();
      break;
    }
  }
}
 
Example #15
Source File: FakeSignalEvent.java    From swellrt with Apache License 2.0 4 votes vote down vote up
@Override
public EventTarget getEventTarget() {
  // TODO Auto-generated method stub
  return null;
}
 
Example #16
Source File: TimeGrid.java    From unitime with Apache License 2.0 4 votes vote down vote up
public void onBrowserEvent(Event event) {
	if (iDummy) return;
    Element target = DOM.eventGetTarget(event);
    boolean anchor = false;
    for (; target != null; target = DOM.getParent(target)) {
    	String tag = target.getPropertyString("tagName");
    	if ("a".equalsIgnoreCase(tag)) {
    		anchor = true;
    		break;
    	} else if ("div".equalsIgnoreCase(tag)) {
    		break;
    	}
    }
	EventTarget related = event.getRelatedEventTarget();
    switch (DOM.eventGetType(event)) {
	case Event.ONCLICK:
		select(false);
		if (!anchor) {
			MeetingClickEvent e = new MeetingClickEvent(Meeting.this);
			for (MeetingClickHandler h: iMeetingClickHandlers)
				h.onMeetingClick(e);
		}
		break;
	case Event.ONMOUSEOVER:
        if (related == null || !getElement().isOrHasChild((Element)related.cast())) {
			select(true);
        }
		break;
	case Event.ONMOUSEOUT:
        if (related == null || !getElement().isOrHasChild((Element)related.cast())) {
        	select(false);
        }
		break;
	case Event.ONMOUSEMOVE:
		int relativeX = event.getClientX() - getElement().getAbsoluteLeft() + getElement().getScrollLeft() + getElement().getOwnerDocument().getScrollLeft();
		if (iRTL) relativeX = iCellWidth - relativeX;
		if (relativeX < iLeft - 6 - getDay() * iCellWidth || relativeX > iLeft - 2 - getDay() * iCellWidth + iWidth) {
			select(false);
		}
		break;
	}
    super.onBrowserEvent(event);
}
 
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: SignalEventImpl.java    From swellrt with Apache License 2.0 votes vote down vote up
EventTarget getEventTarget(); 
Example #19
Source File: SignalEventImpl.java    From incubator-retired-wave with Apache License 2.0 votes vote down vote up
EventTarget getEventTarget();