Java Code Examples for com.google.gwt.user.client.Event#preventDefault()
The following examples show how to use
com.google.gwt.user.client.Event#preventDefault() .
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: SessionDatesSelector.java From unitime with Apache License 2.0 | 6 votes |
@Override public void onBrowserEvent(Event event) { switch (DOM.eventGetType(event)) { case Event.ONMOUSEDOWN: SelectionMode mode = null; for (SelectionMode m: SelectionMode.values()) if (hasUnselectedDays(m)) { mode = m; break; } if (mode != null) setAllSelected(true, mode); else setAllSelected(false, SelectionMode.All); if (iCursor != null) iPanel.getWidget().setCursor(iCursor); event.preventDefault(); break; } super.onBrowserEvent(event); }
Example 2
Source File: InputMultiSelect.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
@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: JsFacade.java From actor-platform with GNU Affero General Public License v3.0 | 6 votes |
@UsedByApp public void handleLinkClick(Event event) { Element target = Element.as(event.getEventTarget()); String href = target.getAttribute("href"); if (href.startsWith("send:")) { String msg = href.substring("send:".length()); msg = URL.decode(msg); if (lastVisiblePeer != null) { messenger.sendMessage(lastVisiblePeer, msg); event.preventDefault(); } } else { if (JsElectronApp.isElectron()) { JsElectronApp.openUrlExternal(href); event.preventDefault(); } } }
Example 4
Source File: VComboBoxMultiselect.java From vaadin-combobox-multiselect with Apache License 2.0 | 6 votes |
/** * 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 5
Source File: CubaTreeTableWidget.java From cuba with Apache License 2.0 | 5 votes |
@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 6
Source File: IntervalSelector.java From unitime with Apache License 2.0 | 5 votes |
@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: UniTimeTableHeader.java From unitime with Apache License 2.0 | 5 votes |
@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 8
Source File: Button.java From swellrt with Apache License 2.0 | 5 votes |
/** * 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 9
Source File: SuggestPopup.java From cuba with Apache License 2.0 | 5 votes |
@Override public void onBrowserEvent(Event event) { if (event.getTypeInt() == Event.ONCONTEXTMENU) { event.stopPropagation(); event.preventDefault(); return; } super.onBrowserEvent(event); }
Example 10
Source File: SingleDateSelector.java From unitime with Apache License 2.0 | 5 votes |
@Override public void onBrowserEvent(Event event) { switch (DOM.eventGetType(event)) { case Event.ONMOUSEDOWN: MouseDownEvent.fireNativeEvent(event, this); event.stopPropagation(); event.preventDefault(); break; } }
Example 11
Source File: Button.java From incubator-retired-wave with Apache License 2.0 | 5 votes |
/** * 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 12
Source File: SessionDatesSelector.java From unitime with Apache License 2.0 | 5 votes |
@Override public void onBrowserEvent(Event event) { switch (DOM.eventGetType(event)) { case Event.ONMOUSEDOWN: if (isEnabled()) { setValue(!getValue(), true); iPanel.getWidget().setCursor(iCursor); } event.preventDefault(); break; } super.onBrowserEvent(event); }
Example 13
Source File: SuggestionMenu.java From incubator-retired-wave with Apache License 2.0 | 4 votes |
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 14
Source File: InputSlider.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 4 votes |
private void killEvent(Event event) { event.preventDefault(); event.stopPropagation(); }
Example 15
Source File: CollapsibleSplitLayoutPanel.java From core with GNU Lesser General Public License v2.1 | 4 votes |
@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 16
Source File: SuggestionMenu.java From swellrt with Apache License 2.0 | 4 votes |
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 17
Source File: CubaPopupButtonWidget.java From cuba with Apache License 2.0 | 4 votes |
@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 18
Source File: FinderPanel.java From core with GNU Lesser General Public License v2.1 | 4 votes |
@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: CubaFileUploadProgressWindow.java From cuba with Apache License 2.0 | 4 votes |
private void onResizeEvent(Event event) { if (resizable && WidgetUtil.isTouchEventOrLeftMouseButton(event)) { switch (event.getTypeInt()) { case Event.ONMOUSEDOWN: case Event.ONTOUCHSTART: showResizingCurtain(); if (BrowserInfo.get().isIE()) { resizeBox.getStyle().setVisibility(Style.Visibility.HIDDEN); } resizing = true; startX = WidgetUtil.getTouchOrMouseClientX(event); startY = WidgetUtil.getTouchOrMouseClientY(event); origW = getElement().getOffsetWidth(); origH = getElement().getOffsetHeight(); DOM.setCapture(getElement()); event.preventDefault(); break; case Event.ONMOUSEUP: case Event.ONTOUCHEND: setSize(event); case Event.ONTOUCHCANCEL: DOM.releaseCapture(getElement()); case Event.ONLOSECAPTURE: hideResizingCurtain(); if (BrowserInfo.get().isIE()) { resizeBox.getStyle().clearVisibility(); } resizing = false; break; case Event.ONMOUSEMOVE: case Event.ONTOUCHMOVE: if (resizing) { setSize(event); event.preventDefault(); } break; default: event.preventDefault(); break; } } }
Example 20
Source File: CubaFileUploadProgressWindow.java From cuba with Apache License 2.0 | 4 votes |
@Override public void onBrowserEvent(final Event event) { boolean bubble = true; final int type = event.getTypeInt(); final Element target = DOM.eventGetTarget(event); if (resizing || resizeBox == target) { onResizeEvent(event); bubble = false; } else if (isClosable() && target == closeBox) { if (type == Event.ONCLICK) { closeWindow(); } bubble = false; } else if (header.isOrHasChild(target) && !dragging) { // dblclick handled in connector if (type != Event.ONDBLCLICK && draggable) { if (type == Event.ONMOUSEDOWN) { /* * Prevents accidental selection of window caption or * content. (#12726) */ event.preventDefault(); headerDragPending = event; } else if (type == Event.ONMOUSEMOVE && headerDragPending != null) { // ie won't work unless this is set here dragging = true; onDragEvent(headerDragPending); onDragEvent(event); headerDragPending = null; } else { headerDragPending = null; } bubble = false; } } else if (dragging || !contents.isOrHasChild(target)) { onDragEvent(event); bubble = false; } /* * If clicking on other than the content, move focus to the window. * After that this windows e.g. gets all keyboard shortcuts. */ if (type == Event.ONMOUSEDOWN && !contentPanel.getElement().isOrHasChild(target) && target != closeBox) { contentPanel.focus(); } if (!bubble) { event.stopPropagation(); } else { // Super.onBrowserEvent takes care of Handlers added by the // ClickEventHandler super.onBrowserEvent(event); } }