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

The following examples show how to use com.google.gwt.user.client.Event#getTypeInt() . 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: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 6 votes vote down vote up
/**
 * Handles special behavior of the mouse down event.
 *
 * @param event
 */
private void handleMouseDownEvent(Event event) {
	/*
	 * Prevent the keyboard focus from leaving the textfield by preventing
	 * the default behaviour of the browser. Fixes #4285.
	 */
	if (event.getTypeInt() == Event.ONMOUSEDOWN) {
		debug("VComboBoxMultiselect: blocking mouseDown event to avoid blur");

		event.preventDefault();
		event.stopPropagation();

		/*
		 * In IE the above wont work, the blur event will still trigger. So,
		 * we set a flag here to prevent the next blur event from happening.
		 * This is not needed if do not already have focus, in that case
		 * there will not be any blur event and we should not cancel the
		 * next blur.
		 */
		if (BrowserInfo.get()
			.isIE() && this.focused) {
			this.preventNextBlurEventInIE = true;
			debug("VComboBoxMultiselect: Going to prevent next blur event on IE");
		}
	}
}
 
Example 2
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 6 votes vote down vote up
/**
 * Handles special behavior of the mouse down event.
 *
 * @param event
 */
private void handleMouseDownEvent(Event event) {
	/*
	 * Prevent the keyboard focus from leaving the textfield by preventing
	 * the default behaviour of the browser. Fixes #4285.
	 */
	if (event.getTypeInt() == Event.ONMOUSEDOWN) {
		debug("VComboBoxMultiselect: blocking mouseDown event to avoid blur");

		event.preventDefault();
		event.stopPropagation();

		/*
		 * In IE the above wont work, the blur event will still trigger. So,
		 * we set a flag here to prevent the next blur event from happening.
		 * This is not needed if do not already have focus, in that case
		 * there will not be any blur event and we should not cancel the
		 * next blur.
		 */
		if (BrowserInfo.get()
			.isIE() && this.focused) {
			this.preventNextBlurEventInIE = true;
			debug("VComboBoxMultiselect: Going to prevent next blur event on IE");
		}
	}
}
 
Example 3
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 6 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	debug("VComboBoxMultiselect.SP: onBrowserEvent()");

	if (event.getTypeInt() == Event.ONCLICK) {
		final Element target = DOM.eventGetTarget(event);
		if (target == this.up || target == DOM.getChild(this.up, 0)) {
			this.lazyPageScroller.scrollUp();
		} else if (target == this.down || target == DOM.getChild(this.down, 0)) {
			this.lazyPageScroller.scrollDown();
		}

	}

	/*
	 * Prevent the keyboard focus from leaving the textfield by
	 * preventing the default behaviour of the browser. Fixes #4285.
	 */
	handleMouseDownEvent(event);
}
 
Example 4
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 5
Source File: CubaSimpleDayCell.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);

    // if not click event or some other event was fired
    if (event.getTypeInt() != Event.ONCLICK) {
        return;
    }

    // if day cell has expanded events
    if (getElement().getClassName().contains("scrollable")) {
        return;
    }

    Element target = Element.as(event.getEventTarget());
    Widget widget = WidgetUtil.findWidget(target);
    if ((widget instanceof CubaSimpleDayCell) || target.getClassName().contains("spacer")) {
        CubaCalendarWidget cubaCalendar = (CubaCalendarWidget) calendar;
        if (cubaCalendar.getDayClickListener() != null) {
            cubaCalendar.getDayClickListener().accept(getDate());
        }
    }
}
 
Example 6
Source File: VSliderPanel.java    From vaadin-sliderpanel with MIT License 5 votes vote down vote up
@Override
public void onBrowserEvent(final Event event) {
    if (!isEnabled()) {
        return;
    }
    if (event != null && (event.getTypeInt() == Event.ONCLICK)) {
        animateTo(!this.expand, this.animationDuration, true);
    }
    super.onBrowserEvent(event);
}
 
Example 7
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	super.onBrowserEvent(event);

	if (event.getTypeInt() == Event.ONPASTE) {
		if (this.textInputEnabled) {
			filterOptions(this.currentPage);
		}
	}
}
 
Example 8
Source File: SuggestPopup.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	if (event.getTypeInt() == Event.ONCONTEXTMENU) {
		event.stopPropagation();
		event.preventDefault();
		return;
	}
	super.onBrowserEvent(event);
}
 
Example 9
Source File: CubaScrollTableWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);

    if (isEnabled() && event.getTypeInt() == Event.ONCONTEXTMENU) {
        if (getStyleName().contains("-header-sortable")) {
            _delegate.showSortMenu(td, cid);
        }

        event.preventDefault();
        event.stopPropagation();
    }
}
 
Example 10
Source File: EventWrapper.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
public static String asString(Event event) {
  // Start with the event type string
  String string = DOM.eventGetTypeString(event);
  // Next type-specific fields
  switch (event.getTypeInt()) {
  case Event.ONKEYPRESS:
  case Event.ONKEYUP:
  case Event.ONKEYDOWN:
    string += key(event) + modifiers(event);
    break;
  case Event.ONCLICK:
  case Event.ONDBLCLICK:
  case Event.ONMOUSEMOVE:
    string += mousePoint(event) + modifiers(event);
    break;
  case Event.ONMOUSEDOWN:
  case Event.ONMOUSEUP:
    string += mousePoint(event) + mouseButtons(event) + modifiers(event);
    break;
  case Event.ONMOUSEOUT:
    string += mousePoint(event) + modifiers(event) + " to: " + getToElement(event);
    break;
  case Event.ONMOUSEOVER:
    string += mousePoint(event) + modifiers(event) + " from: " + getFromElement(event);
    break;
  case Event.ONMOUSEWHEEL:
    string += " " + getMouseWheelVelocityY(event) + mousePoint(event) + modifiers(event);
    break;
  case Event.ONFOCUS:
  case Event.ONBLUR:
  case Event.ONCHANGE:
  case Event.ONERROR:
  case Event.ONLOAD:
  case Event.ONLOSECAPTURE:
  case Event.ONSCROLL:
    break;
  }
  return string;
}
 
Example 11
Source File: MockComponent.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Invoked by GWT whenever a browser event is dispatched to this component.
 */
@Override
public void onBrowserEvent(Event event) {
  if (!shouldCancel(event)) return;
  switch (event.getTypeInt()) {
    case Event.ONTOUCHSTART:
    case Event.ONTOUCHEND:
      if (isForm()) {
        select();
      }
    case Event.ONTOUCHMOVE:
    case Event.ONTOUCHCANCEL:
      cancelBrowserEvent(event);
      DomEvent.fireNativeEvent(event, handlers);
      break;

    case Event.ONMOUSEDOWN:
    case Event.ONMOUSEUP:
    case Event.ONMOUSEMOVE:
    case Event.ONMOUSEOVER:
    case Event.ONMOUSEOUT:
      cancelBrowserEvent(event);
      mouseListeners.fireMouseEvent(this, event);
      break;

    case Event.ONCLICK:
      cancelBrowserEvent(event);
      select();
      break;

    default:
      // Ignore unexpected events
      break;
  }
}
 
Example 12
Source File: EventWrapper.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * @return A string describing which modifier keys were pressed,
 *        and whether this was a repeat event,  e.g., " shift ctrl"
 */
@SuppressWarnings("deprecation")
public static String modifiers(Event event) {
  // repeat is deprecated, but useful for debugging
  return (event.getAltKey() ? " alt" : "")
  + (event.getShiftKey() ? " shift" : "")
  + (event.getCtrlKey() ? " ctrl" : "")
  + (event.getMetaKey() ? " meta" : "")
  + ((event.getTypeInt() == Event.ONKEYDOWN) && event.getRepeat() ? " repeat" : "");
}
 
Example 13
Source File: CubaSearchSelectWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    if (event.getTypeInt() == Event.ONPASTE) {
        // ignore paste
        return;
    }
    super.onBrowserEvent(event);
}
 
Example 14
Source File: RoomsTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) { 
    if(event.getTypeInt() == Event.ONCLICK) {
    	event.stopPropagation(); 
    } 
    super.onBrowserEvent(event); 
}
 
Example 15
Source File: VComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	super.onBrowserEvent(event);

	if (event.getTypeInt() == Event.ONPASTE) {
		if (this.textInputEnabled) {
			filterOptions(this.currentPage);
		}
	}
}
 
Example 16
Source File: InputDatePicker.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	int type = event.getTypeInt();
	Element target = event.getCurrentTarget();
	if (type == Event.ONCLICK) {
		String dataDate = target.getAttribute(InputDatePicker.ATTRIBUTE_DATA_DATE);
		String dataCursor = target.getAttribute(InputDatePicker.ATTRIBUTE_DATA_CURSOR);
		String dataYear = target.getAttribute(InputDatePicker.ATTRIBUTE_DATA_YEAR);
		if (dataDate != null && dataDate.length() > 0) {
			this.mode = Mode.CALENDAR;
			this.setValue(InputDatePicker.ATTRIBUTE_DATE_FORMAT.parse(dataDate), true);
		} else if (dataCursor != null && dataCursor.length() > 0) {
			this.mode = Mode.CALENDAR;
			this.cursor = InputDatePicker.ATTRIBUTE_DATE_FORMAT.parse(dataCursor);
			this.redraw();
		} else if (dataYear != null && dataYear.length() > 0) {
			this.openMonthOfYear(Integer.valueOf(dataYear));
		} else if (target == this.monthPickerButton) {
			if (this.mode != Mode.MONTH) {
				this.mode = Mode.MONTH;
			} else {
				this.mode = Mode.CALENDAR;
			}
			this.redraw();
		}
		event.stopPropagation();
		event.preventDefault();
	} else if (type == Event.ONKEYDOWN) {
		this.handleKeyPress(event.getKeyCode());
		event.stopPropagation();
		event.preventDefault();
	} else {
		super.onBrowserEvent(event);
	}
}
 
Example 17
Source File: EventPreviewAutoHiderRegistrar.java    From swellrt with Apache License 2.0 4 votes vote down vote up
@Override
public void onPreviewNativeEvent(NativePreviewEvent previewEvent) {
  if (autoHiders.isEmpty()) {
    return;
  }

  // TODO(danilatos,user,user): Push signal down a layer - clean this up.
  Event event = Event.as(previewEvent.getNativeEvent());
  int lowLevelType = event.getTypeInt();

  // TODO(danilatos): Insert this logic deeply rather than
  // sprinkling it in event handlers. Also the return value
  // of onEventPreview is the reverse of signal handlers.
  SignalEvent signal = SignalEventImpl.create(event, false);
  if (signal == null) {
    return;
  }

  // Key events (excluding escape) and mousewheel events use hideTopmostAutoHiderForKeyEvent
  if (lowLevelType == Event.ONMOUSEWHEEL || signal.isKeyEvent()) {
    if (hideTopmostAutoHiderForKeyEvent(false)) {
      // TODO(user): We don't call previewEvent.cancel() here, since for the floating-buttons
      // menu we want, for example, space-bar to still shift focus to the next blip.
      // The to-do is to audit the previewEvent.cancel call below and see why it's there (and if
      // it's not needed, eliminate it).
      return;
    }
  }

  // Pressing escape at any time causes us to close and discard the event.
  if (signal.getKeySignalType() == KeySignalType.NOEFFECT &&
      event.getKeyCode() == KeyCodes.KEY_ESCAPE) {
    if (hideTopmostAutoHiderForKeyEvent(true)) {
      previewEvent.cancel();
      return;
    }
  }

  // Click events and mouse-wheel events that fall through use hideAllAfter.
  if (lowLevelType == Event.ONMOUSEDOWN || lowLevelType == Event.ONMOUSEWHEEL) {
    hideAllAfter(signal.getTarget());
  }

  // Otherwise we don't do anything and the event continues as usual.
}
 
Example 18
Source File: FinderPanel.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    switch (event.getTypeInt()) {
        case Event.ONMOUSEDOWN:
            mouseDown = true;

  /*
   * Resize glassElem to take up the entire scrollable window area,
   * which is the greater of the scroll size and the client size.
   */
            int width = Math.max(Window.getClientWidth(),
                    Document.get().getScrollWidth());
            int height = Math.max(Window.getClientHeight(),
                    Document.get().getScrollHeight());
            glassElem.getStyle().setHeight(height, Style.Unit.PX);
            glassElem.getStyle().setWidth(width, Style.Unit.PX);
            Document.get().getBody().appendChild(glassElem);

            offset = getEventPosition(event) - getAbsolutePosition();
            Event.setCapture(getElement());
            event.preventDefault();
            break;

        case Event.ONMOUSEUP:
            mouseDown = false;

            glassElem.removeFromParent();

            // Handle double-clicks.
            // Fake them since the double-click event aren't fired.
            if (this.toggleDisplayAllowed) {
                double now = Duration.currentTimeMillis();
                if (now - this.lastClick < DOUBLE_CLICK_TIMEOUT) {
                    now = 0;
                    toggleCollapsedState();
                }
                this.lastClick = now;
            }

            Event.releaseCapture(getElement());
            event.preventDefault();
            break;

        case Event.ONMOUSEMOVE:
            if (mouseDown) {
                int size;
                if (reverse) {
                    size = getTargetPosition() + getTargetSize() - getSplitterSize()
                            - getEventPosition(event) + offset;
                } else {
                    size = getEventPosition(event) - getTargetPosition() - offset;
                }
                ((LayoutData) target.getLayoutData()).hidden = false;
                setAssociatedWidgetSize(size);
                event.preventDefault();
            }
            break;
    }
}
 
Example 19
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 20
Source File: EventPreviewAutoHiderRegistrar.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
@Override
public void onPreviewNativeEvent(NativePreviewEvent previewEvent) {
  if (autoHiders.isEmpty()) {
    return;
  }

  // TODO(danilatos,user,user): Push signal down a layer - clean this up.
  Event event = Event.as(previewEvent.getNativeEvent());
  int lowLevelType = event.getTypeInt();

  // TODO(danilatos): Insert this logic deeply rather than
  // sprinkling it in event handlers. Also the return value
  // of onEventPreview is the reverse of signal handlers.
  SignalEvent signal = SignalEventImpl.create(event, false);
  if (signal == null) {
    return;
  }

  // Key events (excluding escape) and mousewheel events use hideTopmostAutoHiderForKeyEvent
  if (lowLevelType == Event.ONMOUSEWHEEL || signal.isKeyEvent()) {
    if (hideTopmostAutoHiderForKeyEvent(false)) {
      // TODO(user): We don't call previewEvent.cancel() here, since for the floating-buttons
      // menu we want, for example, space-bar to still shift focus to the next blip.
      // The to-do is to audit the previewEvent.cancel call below and see why it's there (and if
      // it's not needed, eliminate it).
      return;
    }
  }

  // Pressing escape at any time causes us to close and discard the event.
  if (signal.getKeySignalType() == KeySignalType.NOEFFECT &&
      event.getKeyCode() == KeyCodes.KEY_ESCAPE) {
    if (hideTopmostAutoHiderForKeyEvent(true)) {
      previewEvent.cancel();
      return;
    }
  }

  // Click events and mouse-wheel events that fall through use hideAllAfter.
  if (lowLevelType == Event.ONMOUSEDOWN || lowLevelType == Event.ONMOUSEWHEEL) {
    hideAllAfter(signal.getTarget());
  }

  // Otherwise we don't do anything and the event continues as usual.
}