Java Code Examples for com.google.gwt.dom.client.Element#as()
The following examples show how to use
com.google.gwt.dom.client.Element#as() .
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: DOMHelper.java From gwt-material with Apache License 2.0 | 6 votes |
public static Element getChildElementById(Element parent, String id) { if (parent != null) { for (int i = 0; i < parent.getChildCount(); i++) { Node childNode = parent.getChild(i); if (Element.is(childNode)) { Element child = Element.as(childNode); if (child.getId().equals(id)) { return child; } if (child.getChildCount() > 0) { return getChildElementById(child, id); } } } } return null; }
Example 2
Source File: DOMHelper.java From gwt-material with Apache License 2.0 | 6 votes |
public static Element getChildElementByClass(Element parent, String className) { if (parent != null) { for (int i = 0; i < parent.getChildCount(); i++) { Node childNode = parent.getChild(i); if (Element.is(childNode)) { Element child = Element.as(childNode); if (child.getClassName().contains(className)) { return child; } if (child.getChildCount() > 0) { return getChildElementByClass(child, className); } } } } return null; }
Example 3
Source File: TimelineWidget.java From gantt with Apache License 2.0 | 6 votes |
private Element getLastResolutionElement() { DivElement div = getResolutionDiv(); if (div == null) { return null; } NodeList<Node> nodeList = div.getChildNodes(); if (nodeList == null) { return null; } int blockCount = nodeList.getLength(); if (blockCount < 1) { return null; } if (containsResBlockSpacer()) { int index = blockCount - 2; if (blockCount > 1 && index >= 0) { return Element.as(getResolutionDiv().getChild(index)); } return null; } return Element.as(getResolutionDiv().getLastChild()); }
Example 4
Source File: CubaDateCell.java From cuba with Apache License 2.0 | 6 votes |
@Override public void onBrowserEvent(Event event) { super.onBrowserEvent(event); // ONCLICK is invoked after mouseDown and mouseUp events, so we need // to check that rangeSelect event was not fired if (event.getTypeInt() == Event.ONCLICK && !rangeSelect) { Element target = Element.as(event.getEventTarget()); String targetSlotNumber = getSlotNumberStyle(target); for (DateCellSlot slot : slots) { String className = slot.getElement().getClassName(); if (containsSlotNumber(className, targetSlotNumber)) { CubaCalendarWidget calendar = (CubaCalendarWidget) weekgrid.getCalendar(); if (calendar.getDayClickListener() != null) { calendar.getDayClickListener().accept(slot.getFrom()); } break; } } } }
Example 5
Source File: TimelineWidget.java From gantt with Apache License 2.0 | 5 votes |
private void fillWeekResolutionBlock(DivElement resBlock, boolean fillWeekBlock, Date date, int index, Weekday weekDay, boolean firstWeek, boolean lastBlock, int left, boolean even) { if (fillWeekBlock) { resBlock.setInnerText(formatWeekCaption(date)); if (even) { resBlock.addClassName(STYLE_EVEN); } else { resBlock.removeClassName(STYLE_EVEN); } if (styleElementForLeft == null && isTimelineOverflowingHorizontally()) { resBlock.getStyle().setPosition(Position.RELATIVE); resBlock.getStyle().setLeft(left, Unit.PX); } resBlock.removeClassName(STYLE_FIRST); resBlock.removeClassName(STYLE_LAST); } if (firstWeek && (weekDay == Weekday.Last || lastBlock)) { Element firstEl = resolutionDiv.getFirstChildElement(); if (!firstEl.hasClassName(STYLE_FIRST)) { firstEl.addClassName(STYLE_FIRST); } } else if (lastBlock) { Element lastEl = Element.as(resolutionDiv.getLastChild()); if (!lastEl.hasClassName(STYLE_LAST)) { lastEl.addClassName(STYLE_LAST); } } }
Example 6
Source File: GanttWidget.java From gantt with Apache License 2.0 | 5 votes |
/** * Helper method to find Step element by given starting point and y-position * and delta-y. Starting point is there to optimize performance a bit as * there's no need to iterate through every single step element. * * @param startFromBar * Starting point element * @param newY * target y-axis position * @param deltay * delta-y relative to starting point element. * @return Step element at y-axis position. May be same element as given * startFromBar element. */ protected Element findStepElement(Element startFromBar, int startTopY, int startBottomY, int newY, double deltay) { boolean subStep = isSubBar(startFromBar); if (subStep) { startFromBar = startFromBar.getParentElement(); } if (isBetween(newY, startTopY, startBottomY)) { GWT.log("findStepElement returns same: Y " + newY + " between " + startTopY + "-" + startBottomY); return startFromBar; } int startIndex = getChildIndex(content, startFromBar); Element barCanditate; int i = startIndex; if (deltay > 0) { i++; for (; i < content.getChildCount(); i++) { barCanditate = Element.as(content.getChild(i)); if (isBetween(newY, barCanditate.getAbsoluteTop(), barCanditate.getAbsoluteBottom())) { if (!subStep && i == (startIndex + 1)) { // moving directly over the following step will be // ignored (if not sub-step). return startFromBar; } return barCanditate; } } } else if (deltay < 0) { i--; for (; i >= getAdditonalContentElementCount(); i--) { barCanditate = Element.as(content.getChild(i)); if (isBetween(newY, barCanditate.getAbsoluteTop(), barCanditate.getAbsoluteBottom())) { return barCanditate; } } } return startFromBar; }
Example 7
Source File: HTML5Support.java From cuba with Apache License 2.0 | 5 votes |
private boolean validate(NativeEvent event) { if (!Element.is(event.getEventTarget())) { return false; } Element target = Element.as(event.getEventTarget()); Widget widget = Util.findWidget(target, null); if (widget == null) { return false; } ComponentConnector connector = Util.findConnectorFor(widget); while (connector == null && widget != null) { widget = widget.getParent(); connector = Util.findConnectorFor(widget); } if (this.connector == connector) { return true; } else if (connector == null) { return false; } else if (connector.getWidget() instanceof VDDHasDropHandler) { // Child connector handles its own drops return false; } // Over non droppable child return true; }
Example 8
Source File: VLayoutDragDropMouseHandler.java From cuba with Apache License 2.0 | 5 votes |
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 9
Source File: CubaOrderedLayoutSlot.java From cuba with Apache License 2.0 | 5 votes |
@Override public void onClick(ClickEvent event) { Element target = Element.as(event.getNativeEvent().getEventTarget()); ComponentConnector componentConnector = Util.findConnectorFor(getWidget()); if (target == contextHelpIcon && componentConnector instanceof HasContextHelpConnector) { HasContextHelpConnector connector = (HasContextHelpConnector) componentConnector; if (hasContextHelpIconListeners(componentConnector.getState())) { connector.contextHelpIconClick(event); } } }
Example 10
Source File: CubaFieldGroupLayoutComponentSlot.java From cuba with Apache License 2.0 | 5 votes |
@Override public void onBrowserEvent(Event event) { if (DOM.eventGetType(event) == Event.ONCLICK) { Element target = Element.as(event.getEventTarget()); ComponentConnector componentConnector = Util.findConnectorFor(getWidget()); if (target == contextHelpIndicatorElement && componentConnector instanceof HasContextHelpConnector) { HasContextHelpConnector connector = (HasContextHelpConnector) componentConnector; if (hasContextHelpIconListeners(componentConnector.getState())) { connector.contextHelpIconClick(event); } } } }
Example 11
Source File: CubaCheckBoxConnector.java From cuba with Apache License 2.0 | 5 votes |
@Override public void onClick(ClickEvent event) { super.onClick(event); Element target = Element.as(event.getNativeEvent().getEventTarget()); if (target == getWidget().contextHelpIcon) { if (hasContextHelpIconListeners(getState())) { contextHelpIconClick(event); } } }
Example 12
Source File: GanttWidget.java From gantt with Apache License 2.0 | 5 votes |
private int getBgGridCellHeight() { int gridBlockHeightPx = 0; int firstStepIndex = getAdditonalContentElementCount(); if (firstStepIndex < content.getChildCount()) { Element firstBar = Element.as(content.getChild(firstStepIndex)); gridBlockHeightPx = getElementHeightWithMargin(firstBar); } return gridBlockHeightPx; }
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: SignalEventImpl.java From incubator-retired-wave with Apache License 2.0 | 4 votes |
/** * @return The target element of the event. */ public Element getTarget() { return Element.as(nativeEvent.getEventTarget()); }
Example 15
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 16
Source File: PopupButtonConnector.java From cuba with Apache License 2.0 | 4 votes |
public void onPreviewNativeEvent(NativePreviewEvent event) { if (isEnabled()) { Element target = Element .as(event.getNativeEvent().getEventTarget()); switch (event.getTypeInt()) { case Event.ONCLICK: if (getWidget().isOrHasChildOfButton(target)) { if (getState().popupVisible && getState().buttonClickTogglesPopupVisibility) { getWidget().sync(); rpc.setPopupVisible(false); } } break; case Event.ONMOUSEDOWN: if (!getWidget().isOrHasChildOfPopup(target) && !getWidget().isOrHasChildOfConsole(target) && !getWidget().isOrHasChildOfButton(target) && getState().closePopupOnOutsideClick) { if (getState().popupVisible) { getWidget().sync(); rpc.setPopupVisible(false); } } break; case Event.ONKEYPRESS: if (getWidget().isOrHasChildOfPopup(target)) { // Catch children that use keyboard, so we can unfocus // them // when // hiding getWidget().addToActiveChildren(target); } break; case Event.ONKEYDOWN: if (getState().popupVisible) { getWidget().onKeyDownOnVisiblePopup(event.getNativeEvent(), this); } break; default: break; } } }
Example 17
Source File: VLayoutDragDropMouseHandler.java From cuba with Apache License 2.0 | 4 votes |
/** * 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: CubaTooltip.java From cuba with Apache License 2.0 | 4 votes |
@Override protected void handleShowHide(DomEvent domEvent, boolean isFocused) { // CAUTION copied from parent with changes Event event = Event.as(domEvent.getNativeEvent()); Element element = Element.as(event.getEventTarget()); // We can ignore move event if it's handled by move or over already if (currentElement == element && handledByFocus) { return; } // If the parent (sub)component already has a tooltip open and it // hasn't changed, we ignore the event. // TooltipInfo contains a reference to the parent component that is // checked in it's equals-method. if (currentElement != null && isTooltipOpen()) { TooltipInfo currentTooltip = getTooltipFor(currentElement); TooltipInfo newTooltip = getTooltipFor(element); if (currentTooltip != null && currentTooltip.equals(newTooltip)) { return; } } TooltipInfo info = getTooltipFor(element); if (info == null) { handleHideEvent(); currentConnector = null; } else { boolean elementIsIndicator = elementIsIndicator(element); if (closing) { closeTimer.cancel(); closing = false; } if (isTooltipOpen()) { closeNow(); } setTooltipText(info); updatePosition(event, isFocused); if (BrowserInfo.get().isIOS()) { element.focus(); } showTooltip(domEvent instanceof MouseDownEvent && elementIsIndicator); } handledByFocus = isFocused; currentElement = element; }
Example 19
Source File: SignalEventImpl.java From swellrt with Apache License 2.0 | 4 votes |
/** * @return The target element of the event. */ public Element getTarget() { return Element.as(nativeEvent.getEventTarget()); }
Example 20
Source File: DateCellDayItem.java From calendar-component with Apache License 2.0 | 4 votes |
@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(); } }