Java Code Examples for com.google.gwt.dom.client.Element#is()

The following examples show how to use com.google.gwt.dom.client.Element#is() . 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 vote down vote up
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 2
Source File: DOMHelper.java    From gwt-material with Apache License 2.0 6 votes vote down vote up
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 3
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 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: HTML5Support.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onDragEnter(DragEnterEvent event) {
    NativeEvent nativeEvent = event.getNativeEvent();

    if (validate(nativeEvent)) {
        VTransferable transferable = new VTransferable();
        transferable.setDragSource(connector);

        vaadinDragEvent = VDragAndDropManager.get()
                .startDrag(transferable, event.getNativeEvent(), false);

        vaadinDragEvent.setCurrentGwtEvent(nativeEvent);

        VDragAndDropManager.get().setCurrentDropHandler(dropHandler);

        dropHandler.dragEnter(vaadinDragEvent);

        nativeEvent.preventDefault();
        nativeEvent.stopPropagation();

    } else if (vaadinDragEvent != null
            && Element.is(nativeEvent.getEventTarget())) {
        vaadinDragEvent.setCurrentGwtEvent(nativeEvent);
        VDragAndDropManager.get().setCurrentDropHandler(null);
        VDragAndDropManager.get().interruptDrag();
        vaadinDragEvent = null;

        nativeEvent.preventDefault();
        nativeEvent.stopPropagation();
    }

    if (globalDragEnterHandler != null) {
        globalDragEnterHandler.onDragEnter(event);
    }
}
 
Example 6
Source File: HTML5Support.java    From cuba with Apache License 2.0 5 votes vote down vote up
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 7
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 8
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 9
Source File: ClientUtils.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Dumps Element content and traverse its children.
 * <p/><b>WARNING:</b> it is com.google.gwt.dom.client.Element not com.google.gwt.xml.client.Element!!!
 * 
 * @param elm an element to dump
 * @param indent row indentation for current level
 * @param indentIncrement increment for next level
 * @param sb dumped content
 * @return dumped content
 */
public static StringBuilder dump(Element elm, String indent, String indentIncrement, StringBuilder sb) {
    int childCount = elm.getChildCount();
    String innerText = elm.getInnerText();
    String lang = elm.getLang();
    String nodeName = elm.getNodeName();
    short nodeType = elm.getNodeType();
    String getString = elm.getString();
    String tagNameWithNS = elm.getTagName();
    String xmlLang = elm.getAttribute("xml:lang");

    sb.append(ClientUtils.format("%sElement {nodeName: %s, nodeType: %s, tagNameWithNS: %s, lang: %s,"
            + " childCount: %s, getString: %s, xmlLang: %s}\n",
            indent, nodeName, nodeType, tagNameWithNS, lang, childCount, getString, xmlLang));
    NodeList<Node> childNodes = elm.getChildNodes();
    indent += indentIncrement;
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.getItem(i);
        if (Element.is(child)) {
            dump(Element.as(child), indent, indentIncrement, sb);
        } else {
            sb.append(ClientUtils.format("%sNode: nodeType: %s, nodeName: %s, childCount: %s, nodeValue: %s\n",
                    indent, child.getNodeType(), child.getNodeName(), child.getChildCount(), child.getNodeValue()));
        }
    }
    return sb;
}
 
Example 10
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 11
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 12
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 13
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);
  }
}