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

The following examples show how to use com.google.gwt.user.client.Event#stopPropagation() . 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: InputMultiSelect.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	super.onBrowserEvent(event);
	boolean mustKillEvent = false;
	if (DOM.eventGetType(event) == Event.ONKEYDOWN) {
		switch (event.getKeyCode()) {
			case KeyCodes.KEY_ENTER:
				if (this.getDropdown().isOpen()) {
					((MultiSelectionHandler) this.getSelectionHandler()).onEnterKeyDown();
					mustKillEvent = true;
				}
				break;
			case KeyCodes.KEY_TAB:
			case KeyCodes.KEY_ESCAPE:
				this.getDropdown().close();
				break;
			default:
				break;
		}
	}
	if (mustKillEvent) {
		event.preventDefault();
		event.stopPropagation();
	}
}
 
Example 3
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 4
Source File: AriaLink.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {

    int type = DOM.eventGetType(event);
    switch (type) {
        case Event.ONKEYDOWN:
            if(event.getKeyCode()== KeyCodes.KEY_ENTER)
            {
                if(handler!=null)
                    handler.onClick(null);
                event.stopPropagation();
            }
            break;
        default:
            return;

    }

}
 
Example 5
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 6
Source File: SingleDateSelector.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	switch (DOM.eventGetType(event)) {
    case Event.ONMOUSEDOWN:
    	MouseDownEvent.fireNativeEvent(event, this);
    	event.stopPropagation();
    	event.preventDefault();
    	break;
	}
}
 
Example 7
Source File: Button.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Overrides the same method as per Label. Updates the CSS style on the parent
 * DIV, and then passes on control to the superclass implementation.
 *
 * @see com.google.gwt.user.client.ui.Label#onBrowserEvent(com.google.gwt.user.client.Event)
 */
@Override
public void onBrowserEvent(Event event) {

  switch (event.getTypeInt()) {
  case Event.ONMOUSEDOWN:
    me.replaceClassName(ButtonStyle.mouseUp, ButtonStyle.mouseDown);
    if (cancelMouseDownBubble) {
      event.stopPropagation();
    }
    if (preventMouseDownDefault) {
      event.preventDefault();
    }
    break;
  case Event.ONMOUSEUP:
    me.replaceClassName(ButtonStyle.mouseDown, ButtonStyle.mouseUp);
    break;
  case Event.ONMOUSEOVER:
    me.replaceClassName(ButtonStyle.mouseOut, ButtonStyle.mouseOver);
    break;
  case Event.ONMOUSEOUT:
    me.replaceClassName(ButtonStyle.mouseOver, ButtonStyle.mouseOut);
    break;
  }

  // Call to super to handle all event generation.
  super.onBrowserEvent(event);
}
 
Example 8
Source File: UniTimeTableHeader.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	switch (DOM.eventGetType(event)) {
	case Event.ONKEYPRESS:
		MenuItem item = iAccessKeys.get(Character.toLowerCase((char)event.getCharCode()));
		if (item != null) {
			event.stopPropagation();
			event.preventDefault();
			item.getScheduledCommand().execute();
		}
	}
	super.onBrowserEvent(event);
	
}
 
Example 9
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 10
Source File: TextButton.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
  if (mouseListener == null) {
    super.onBrowserEvent(event);
    return;
  }

  switch (event.getTypeInt()) {
    case Event.ONMOUSEDOWN:
      mouseListener.onMouseDown();
      break;
    case Event.ONMOUSEOUT:
      mouseListener.onMouseLeave();
      break;
    case Event.ONMOUSEOVER:
      mouseListener.onMouseEnter();
      break;
    case Event.ONMOUSEUP:
      mouseListener.onMouseUp();
      break;
    case Event.ONCLICK:
      mouseListener.onClick();
      if (stopPropagation) {
        event.stopPropagation();
      }
      break;
  }
  super.onBrowserEvent(event);
}
 
Example 11
Source File: SignalEventImpl.java    From swellrt with Apache License 2.0 5 votes vote down vote up
public static <T extends SignalEventImpl> T create(SignalEventFactory<T> factory,
    Event event, boolean cancelBubbleIfNullified) {
  if (hasBeenConsumed(event)) {
    return null;
  } else {
    T signal = createInner(factory, event);
    if (cancelBubbleIfNullified && signal == null) {
      event.stopPropagation();
    }
    return signal;
  }
}
 
Example 12
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 13
Source File: DesktopUniversalPopup.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
  super.onBrowserEvent(event);

  // We don't want anything outside the popup to receive events
  event.stopPropagation();
}
 
Example 14
Source File: Tab.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    int type = DOM.eventGetType(event);
    switch (type) {
        case Event.ONKEYDOWN:
            if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
                tabLayout.selectTab(index);
                event.stopPropagation();
            }
            break;
        default:
            break;
    }
}
 
Example 15
Source File: CubaButtonWidget.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean handleKeyboardEvents(Event event) {
    int type = DOM.eventGetType(event);
    // Synthesize clicks based on keyboard events AFTER the normal key
    // handling.
    if ((event.getTypeInt() & Event.KEYEVENTS) != 0) {
        switch (type) {
            case Event.ONKEYDOWN:
                // Button should not react on shortcuts with ENTER and SPACE
                if (isShortcut(event)
                        && (event.getKeyCode() == KeyCodes.KEY_ENTER
                        || event.getKeyCode() == KeyCodes.KEY_SPACE)) {
                    return true;
                }
                // Stop propagation when the user starts pressing a button that
                // we are handling to prevent actions from getting triggered
                if (event.getKeyCode() == KeyCodes.KEY_SPACE) {
                    isFocusing = true;
                    event.preventDefault();
                    event.stopPropagation();
                    return true;
                } else if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
                    isFocusing = true;
                    event.preventDefault();
                    event.stopPropagation();
                    return true;
                }
                break;

            // CAUTION IE sometimes does not generate ONKEYPRESS for ENTER, so we override default Vaadin behavior
            case Event.ONKEYUP:
                if (isFocusing) {
                    if (event.getKeyCode() == KeyCodes.KEY_SPACE) {
                        isFocusing = false;
                        onClick();
                        event.stopPropagation();
                        event.preventDefault();
                        return true;
                    } else if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
                        isFocusing = false;
                        onClick();
                        event.stopPropagation();
                        event.preventDefault();
                        return true;
                    }
                } else if (isShortcut(event)
                        && (event.getKeyCode() == KeyCodes.KEY_ENTER
                        || event.getKeyCode() == KeyCodes.KEY_SPACE)) {
                    return true;
                }
                break;
            case Event.ONKEYPRESS: {
                // Button should not react on shortcuts with ENTER and SPACE
                if (isShortcut(event)
                        && (event.getKeyCode() == KeyCodes.KEY_ENTER
                        || event.getKeyCode() == KeyCodes.KEY_SPACE)) {
                    return true;
                }
            }
        }
    }

    return false;
}
 
Example 16
Source File: SuggestionsContainer.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected void preventEvent(Event event) {
    event.stopPropagation();
    event.preventDefault();
}
 
Example 17
Source File: InputSlider.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void killEvent(Event event) {
	event.preventDefault();
	event.stopPropagation();
}
 
Example 18
Source File: TimeGrid.java    From unitime with Apache License 2.0 4 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	if (Event.ONMOUSEMOVE == DOM.eventGetType(event) && !iSelection.isActive() && iMoving != null) {
		iMoving.onBrowserEvent(event);
		if (iMoving.iCursor != null)
			getElement().getStyle().setCursor(iMoving.iCursor);
		return;
	}

	double x = event.getClientX() - getAbsoluteLeft() + Window.getScrollLeft();
	double y = event.getClientY() - getAbsoluteTop() + Window.getScrollTop();

	int slot = 3 * Math.min(Math.max(0, (int)Math.round(4 * (y - 1 + iStart * iCellHeight) / iCellHeight)), 96);
	int day = Math.min(Math.max(0, (int)Math.floor((x - 2) / iCellWidth)), iDays.length - 1);
	int weeks = (isSingleRoom() ? iSelectedWeeks.size() : iRoomResources.size());
	int week = Math.min(Math.max(0, (int)Math.floor(weeks * (x - 2 - iCellWidth * day) / (iCellWidth - 6))), weeks - 1);
	if (iRTL) {
		day = iDays.length - day - 1;
		week = weeks - week - 1;
	}
	int dayOfWeek = iDays[day];
	int h = slot / 12;
	int m = 5 * (slot % 12);
	String time = (CONSTANTS.useAmPm() ? (h == 0 ? "12": h <= 12 ? h : h-12) : h) + ":" + (m < 10 ? "0" : "") + m + (CONSTANTS.useAmPm() ? (h <= 11 ? "a" : "p") : "");
	
	int dayInv = (iDayOfWeeks == null ? (7 + dayOfWeek - iPropertiesProvider.getFirstDayOfWeek()) % 7 : dayOfWeek);
	String text = (iDayOfWeeks == null ? CONSTANTS.longDays()[dayOfWeek] : iDayOfWeeks.get(dayOfWeek)) + " " + (isSingleRoom() ? iSelectedWeeks.get(week) : iSelectedWeeks.get(0)).getDayNames().get(dayInv) +
			" " + time + (isSingleRoom() ? "" : " " + iRoomResources.get(week).getName());
	ResourceInterface room = (isSingleRoom() ? iRoomResources.get(0) : iRoomResources.get(week));
	iPopup.setPopupPosition(event.getClientX() + Window.getScrollLeft(), event.getClientY() + Window.getScrollTop());
	
	getElement().getStyle().setCursor(Cursor.CROSSHAIR);
	
	switch (DOM.eventGetType(event)) {
	case Event.ONMOUSEDOWN:
		iSelection.setStart(dayOfWeek, slot, week);
		iSelection.setEnd(dayOfWeek, slot, week);
		iSelection.setVisible(true);
		iSelection.setActive(true);
		break;
	case Event.ONMOUSEMOVE:
		iSelection.setEnd(dayOfWeek, slot, week);
		if (!iPopup.isShowing()) iPopup.show();
		if (!room.getId().equals(iLastRoomId)) {
			RoomHint.showHint(iPopup.getElement(), room.getId(), "", (room.hasDistance() ? String.valueOf(Math.round(room.getDistance())) : ""), false);
			iLastRoomId = room.getId();
		}
		break;
	case Event.ONMOUSEUP:
		onMouseUp();
		break;
	case Event.ONMOUSEOVER:
		if (!iPopup.isShowing() && (iSelection.isActive() || iMoving == null)) iPopup.show();
		if (iSelection.isActive() && !iSelection.isVisible()) {
			iSelection.setVisible(true);					
		}
		if (!room.getId().equals(iLastRoomId)) {
			RoomHint.showHint(iPopup.getElement(), room.getId(), "", (room.hasDistance() ? String.valueOf(Math.round(room.getDistance())) : ""), false);
			iLastRoomId = room.getId();
		}
		break;
	case Event.ONMOUSEOUT:
		Element child = DOM.eventGetToElement(event);
		if (child != null && !getElement().isOrHasChild(child)) {
			if (iPopup.isShowing()) {
				iPopup.hide();
				RoomHint.hideHint(); iLastRoomId = null;
			}
			iSelection.setVisible(false);
		}
		/*
		if (iSelection.isActive() && !DOM.isOrHasChild(TimeGrid.this.getElement(), DOM.eventGetToElement(event))) {
			iSelection.setActive(false);
		}
		*/
		break;
	}
	
	iHint.setText((iSelection.isVisible() && iSelection.isActive() ? iSelection.toString() : text));
	
	event.preventDefault();
	event.stopPropagation();
}
 
Example 19
Source File: CubaPopupButtonWidget.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean handleKeyboardEvents(Event event) {
    int type = DOM.eventGetType(event);
    // Synthesize clicks based on keyboard events AFTER the normal key
    // handling.
    if ((event.getTypeInt() & Event.KEYEVENTS) != 0) {
        switch (type) {
            case Event.ONKEYDOWN:
                // Button should not react on shortcuts with ENTER and SPACE
                if (isShortcut(event)
                        && (event.getKeyCode() == KeyCodes.KEY_ENTER
                        || event.getKeyCode() == KeyCodes.KEY_SPACE)) {
                    return true;
                }
                // Stop propagation when the user starts pressing a button that
                // we are handling to prevent actions from getting triggered
                if (event.getKeyCode() == KeyCodes.KEY_SPACE) {
                    isFocusing = true;
                    event.preventDefault();
                    event.stopPropagation();
                    return true;
                } else if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
                    isFocusing = true;
                    event.stopPropagation();
                    return true;
                } else if (event.getKeyCode() == KeyCodes.KEY_DOWN) {
                    isFocusing = true;
                    event.stopPropagation();
                }
                break;

            // CAUTION IE sometimes does not generate ONKEYPRESS for ENTER, so we override default Vaadin behavior
            case Event.ONKEYUP:
                if (isFocusing) {
                    if (event.getKeyCode() == KeyCodes.KEY_SPACE) {
                        isFocusing = false;
                        onClick();
                        event.stopPropagation();
                        event.preventDefault();
                        return true;
                    } else if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
                        isFocusing = false;
                        onClick();
                        event.stopPropagation();
                        event.preventDefault();
                        return true;
                    } else if (event.getKeyCode() == KeyCodes.KEY_DOWN) {
                        isFocusing = false;
                        onClick();
                        event.stopPropagation();
                        event.preventDefault();
                        return true;
                    }
                } else if (isShortcut(event)
                        && (event.getKeyCode() == KeyCodes.KEY_ENTER
                        || event.getKeyCode() == KeyCodes.KEY_SPACE)) {
                    return true;
                }
                break;
            case Event.ONKEYPRESS: {
                // Button should not react on shortcuts with ENTER and SPACE
                if (isShortcut(event)
                        && (event.getKeyCode() == KeyCodes.KEY_ENTER
                        || event.getKeyCode() == KeyCodes.KEY_SPACE)) {
                    return true;
                }
            }
        }
    }

    return false;
}
 
Example 20
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;
    }
  }
}