Java Code Examples for com.google.gwt.dom.client.NodeList

The following examples show how to use com.google.gwt.dom.client.NodeList. These examples are extracted from open source projects. 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 Project: nalu   Source File: NaluPluginGWT.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void updateMetaNameContent(String name,
                                  String content) {
  NodeList<Element> metaTagList = Document.get()
                                          .getElementsByTagName("meta");
  for (int i = 0; i < metaTagList.getLength(); i++) {
    if (metaTagList.getItem(i) instanceof MetaElement) {
      MetaElement nodeListElement = (MetaElement) metaTagList.getItem(i);
      if (!Objects.isNull(nodeListElement.getName())) {
        if (nodeListElement.getName()
                           .equals(name)) {
          nodeListElement.removeFromParent();
          break;
        }
      }
    }
  }
  MetaElement metaElement = Document.get()
                                    .createMetaElement();
  metaElement.setName("name");
  metaElement.setContent("content");
  Element headerElement = getHeaderNode();
  if (!Objects.isNull(headerElement)) {
    headerElement.appendChild(metaElement);
  }
}
 
Example 2
Source Project: calendar-component   Source File: DateCell.java    License: Apache License 2.0 6 votes vote down vote up
private void clearSelectionRange() {
    if (eventRangeStart > -1) {
        // clear all "selected" class names
        Element main = getElement();
        NodeList<Node> nodes = main.getChildNodes();

        for (int i = 0; i <= 47; i++) {
            Element c = (Element) nodes.getItem(i);
            if (c == null) {
                continue;
            }
            c.removeClassName("v-daterange");
        }

        eventRangeStart = -1;
    }
}
 
Example 3
Source Project: cuba   Source File: CubaGridLayoutSlot.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
protected Element findElementByClassName(Element element, String className) {
    if (element == null) {
        return null;
    }

    if (element.getClassName().contains(className)) {
        return element;
    }

    NodeList<Node> childNodes = element.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.getItem(i);
        if (child instanceof Element) {
            Element childElement = findElementByClassName((Element) child, className);
            if (childElement != null) {
                return childElement;
            }
        }
    }
    return null;
}
 
Example 4
Source Project: cuba   Source File: HtmlAttributesExtensionConnector.java    License: Apache License 2.0 6 votes vote down vote up
protected void withElement(String querySelector, Consumer<Element> action) {
    ServerConnector parent = getParent();

    if (parent instanceof AbstractComponentConnector) {
        Widget widget = ((AbstractComponentConnector) parent).getWidget();
        if (widget != null) {
            Element element = widget.getElement();
            if (DEFAULT_SELECTOR.equals(querySelector)) {
                action.accept(element);
            } else {
                NodeList<Element> subElements = findSubElements(element, querySelector);
                for (int i = 0; i < subElements.getLength(); i++) {
                    action.accept(subElements.getItem(i));
                }
            }
        }
    }
}
 
Example 5
Source Project: swellrt   Source File: DomHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets a list of descendants of e that match the given class name.
 *
 * If the browser has the native method, that will be called. Otherwise, it
 * traverses descendents of the given element and returns the list of elements
 * with matching classname.
 *
 * @param e
 * @param className
 */
public static NodeList<Element> getElementsByClassName(Element e, String className) {
  if (QuirksConstants.SUPPORTS_GET_ELEMENTS_BY_CLASSNAME) {
    return getElementsByClassNameNative(e, className);
  } else {
    NodeList<Element> all = e.getElementsByTagName("*");
    if (all == null) {
      return null;
    }
    JsArray<Element> ret = JavaScriptObject.createArray().cast();
    for (int i = 0; i < all.getLength(); ++i) {
      Element item = all.getItem(i);
      if (className.equals(item.getClassName())) {
        ret.push(item);
      }
    }
    return ret.cast();
  }
}
 
Example 6
/**
 * Removes all link tags in the head if not initialized.
 */
private void removeCssLinks() {
	if (this.isInit) {
		return;
	}
	this.isInit = true;
	// Remove all existing link element
	NodeList<Element> links = this.getHead().getElementsByTagName(LinkElement.TAG);
	int size = links.getLength();
	for (int i = 0; i < size; i++) {
		LinkElement elem = LinkElement.as(links.getItem(0));
		if ("stylesheet".equals(elem.getRel())) {
			elem.removeFromParent();
		}
	}
}
 
Example 7
Source Project: gantt   Source File: TimelineWidget.java    License: Apache License 2.0 6 votes vote down vote up
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 8
Source Project: incubator-retired-wave   Source File: DomHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets a list of descendants of e that match the given class name.
 *
 * If the browser has the native method, that will be called. Otherwise, it
 * traverses descendents of the given element and returns the list of elements
 * with matching classname.
 *
 * @param e
 * @param className
 */
public static NodeList<Element> getElementsByClassName(Element e, String className) {
  if (QuirksConstants.SUPPORTS_GET_ELEMENTS_BY_CLASSNAME) {
    return getElementsByClassNameNative(e, className);
  } else {
    NodeList<Element> all = e.getElementsByTagName("*");
    if (all == null) {
      return null;
    }
    JsArray<Element> ret = JavaScriptObject.createArray().cast();
    for (int i = 0; i < all.getLength(); ++i) {
      Element item = all.getItem(i);
      if (className.equals(item.getClassName())) {
        ret.push(item);
      }
    }
    return ret.cast();
  }
}
 
Example 9
Source Project: nalu   Source File: NaluPluginGWT.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void updateMetaPropertyContent(String property,
                                      String content) {
  NodeList<Element> metaTagList = Document.get()
                                          .getElementsByTagName("meta");
  for (int i = 0; i < metaTagList.getLength(); i++) {
    if (metaTagList.getItem(i) instanceof MetaElement) {
      MetaElement nodeListElement = (MetaElement) metaTagList.getItem(i);
      if (!Objects.isNull(nodeListElement.getAttribute("property"))) {
        if (nodeListElement.getAttribute("property")
                           .equals(property)) {
          nodeListElement.removeFromParent();
          break;
        }
      }
    }
  }
  MetaElement metaElement = Document.get()
                                    .createMetaElement();
  metaElement.setAttribute("property",
                           property);
  metaElement.setContent("content");
  Element headerElement = getHeaderNode();
  if (!Objects.isNull(headerElement)) {
    headerElement.appendChild(metaElement);
  }
}
 
Example 10
Source Project: demo-gwt-springboot   Source File: DemoGwtWebApp.java    License: Apache License 2.0 5 votes vote down vote up
private void addMetaElements() {
	logger.info("Add viewport");
	MetaElement element = Document.get().createMetaElement();
	element.setName("viewport");
	element.setContent("width=device-width, initial-scale=1.0");

	NodeList<Element> node = Document.get().getElementsByTagName("head");
	Element elementHead = node.getItem(0);
	elementHead.appendChild(element);
}
 
Example 11
Source Project: cuba   Source File: CubaFieldGroupLayoutConnector.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
protected com.google.gwt.dom.client.Element findCaptionTextChildElement(Element captionElement) {
    NodeList<Node> childNodes = captionElement.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.getItem(i);
        if (child instanceof com.google.gwt.dom.client.Element
            && ((com.google.gwt.dom.client.Element) child).getClassName().contains(CAPTIONTEXT_STYLENAME)) {
            return (com.google.gwt.dom.client.Element) child;
        }
    }

    return null;
}
 
Example 12
Source Project: cuba   Source File: IframeCoverUtility.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adds iframe covers for all child iframe elements
 * 
 * @param rootElement
 *            The parent element
 * @return A set of elements with the iframe covers
 */
private static Set<Element> addIframeCovers(Element rootElement) {
    Set<Element> coveredIframes = new HashSet<Element>();
    NodeList<com.google.gwt.dom.client.Element> iframes = rootElement
            .getElementsByTagName("iframe");
    for (int i = 0; i < iframes.getLength(); i++) {
        Element iframe = (Element) iframes.getItem(i);
        addIframeCover(iframe);
        coveredIframes.add(iframe);
    }
    return coveredIframes;
}
 
Example 13
Source Project: gwt-material   Source File: DOMHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static Element getElementByAttribute(NodeList<Element> elems, String attr, String value) {
    if (elems != null) {
        for (int i = 0; i < elems.getLength(); i++) {
            Element child = elems.getItem(i);
            if (child.getAttribute(attr).equals(value)) {
                return child;
            }
        }
    }
    return null;
}
 
Example 14
Source Project: proarc   Source File: ClientUtils.java    License: 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 15
Source Project: GridExtensionPack   Source File: WrappingGridConnector.java    License: Apache License 2.0 5 votes vote down vote up
private Element[] getGridParts(String elem, Element parent) {
	NodeList<Element> elems = parent.getElementsByTagName(elem);
	Element[] ary = new Element[elems.getLength()];
	for (int i = 0; i < ary.length; ++i) {
		ary[i] = elems.getItem(i);
	}
	return ary;
}
 
Example 16
Source Project: GridExtensionPack   Source File: WrappingGridConnector.java    License: Apache License 2.0 5 votes vote down vote up
private Element[] getGridParts(String elem) {
	NodeList<Element> elems = grid.getElement().getElementsByTagName(elem);
	Element[] ary = new Element[elems.getLength()];
	for (int i = 0; i < ary.length; ++i) {
		ary[i] = elems.getItem(i);
	}
	return ary;
}
 
Example 17
Source Project: swellrt   Source File: Clipboard.java    License: Apache License 2.0 5 votes vote down vote up
private String maybeGetAttributeFromContainer(Element srcContainer, String attribName) {
  NodeList<Element> elementsByClassName =
      DomHelper.getElementsByClassName(srcContainer, MAGIC_CLASSNAME);
  if (elementsByClassName != null && elementsByClassName.getLength() > 0) {
    return elementsByClassName.getItem(0).getAttribute(attribName);
  }
  return null;
}
 
Example 18
Source Project: swcv   Source File: GroupedListBox.java    License: MIT License 5 votes vote down vote up
protected OptGroupElement findOptGroupElement(String name)
{
    if (name == null)
        return null;
    NodeList<Element> optgroups = getElement().getElementsByTagName("OPTGROUP");
    for (int i = 0; i < optgroups.getLength(); i++)
    {
        Element optgroup = optgroups.getItem(i);
        if (isMatchingGroup(optgroup, name))
        {
            return OptGroupElement.as(optgroup);
        }
    }
    return null;
}
 
Example 19
Source Project: dashbuilder   Source File: SelectorDisplayerView.java    License: Apache License 2.0 5 votes vote down vote up
protected void showHint(String hint) {
    if (hintEnabled) {
        SelectElement selectElement = SelectElement.as(listBox.getElement());
        NodeList<OptionElement> options = selectElement.getOptions();
        options.getItem(0).setText(hint);
    } else {
        listBox.addItem(hint);
        hintEnabled = true;
    }
}
 
Example 20
Source Project: dashbuilder   Source File: SelectorDisplayerView.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setItemTitle(int index, String title) {
    SelectElement selectElement = SelectElement.as(listBox.getElement());
    NodeList<OptionElement> options = selectElement.getOptions();
    OptionElement optionElement = options.getItem(index + (hintEnabled ? 1: 0));
    if (optionElement != null) {
        optionElement.setTitle(title);
    }
}
 
Example 21
private void init() {
	NodeList<Element> tags = Document.get().getElementsByTagName("meta");
	for (int i = 0; i < tags.getLength(); i++) {
		MetaElement metaTag = (MetaElement) tags.getItem(i);
		String metaName = metaTag.getName();
		String metaContent = metaTag.getContent();
		if (META_NAME_CSRF_TOKEN.equals(metaName) && !Strings.isNullOrEmpty(metaContent)) {
			this.token = metaContent;
		}
		if (META_NAME_CSRF_HEADER.equals(META_NAME_CSRF_HEADER) && !Strings.isNullOrEmpty(metaContent)) {
			this.header = metaContent;
		}
	}
}
 
Example 22
private void setStyle(String clz, String value) {
  NodeList<Element> list;
  list = querySelector(clz);
  for (int i = 0; i < list.getLength(); i++) {
    Element n = list.getItem(i);
    n.setAttribute("style", value);
  }
}
 
Example 23
Source Project: incubator-retired-wave   Source File: Clipboard.java    License: Apache License 2.0 5 votes vote down vote up
private String maybeGetAttributeFromContainer(Element srcContainer, String attribName) {
  NodeList<Element> elementsByClassName =
      DomHelper.getElementsByClassName(srcContainer, MAGIC_CLASSNAME);
  if (elementsByClassName != null && elementsByClassName.getLength() > 0) {
    return elementsByClassName.getItem(0).getAttribute(attribName);
  }
  return null;
}
 
Example 24
Source Project: gwtbootstrap3-extras   Source File: SelectBase.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the item list.
 *
 * @return the item list
 */
public List<Option> getItems() {
    List<Option> selectedItems = new ArrayList<>(0);
    NodeList<OptionElement> items = selectElement.getOptions();
    for (int i = 0; i < items.getLength(); i++) {
        OptionElement item = items.getItem(i);
        Option option = itemMap.get(item);
        if (option != null)
            selectedItems.add(option);
    }
    return selectedItems;
}
 
Example 25
Source Project: core   Source File: ContentBox.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
private void setIconClassname(String styleName) {
    NodeList<Element> i = dp.getElement().getElementsByTagName("i");
    if (i.getLength() == 1) {
        Element iconElem = i.getItem(0);
        iconElem.setClassName(styleName);
    }
}
 
Example 26
Source Project: core   Source File: Header.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public void highlight(String name)
{
    toggleSubnavigation(name);

    com.google.gwt.user.client.Element target = linksPane.getElementById("header-links-ref");
    if(target!=null) // TODO: i think this cannot happen, does it?
    {
        NodeList<Node> childNodes = target.getChildNodes();
        for(int i=0; i<childNodes.getLength(); i++)
        {
            Node n = childNodes.getItem(i);
            if(Node.ELEMENT_NODE == n.getNodeType())
            {
                Element element = (Element) n;
                if(element.getId().equals("header-"+name))
                {
                    element.addClassName("header-link-selected");
                    element.setAttribute("aria-selected", "true");
                }
                else {
                    element.removeClassName("header-link-selected");
                    element.setAttribute("aria-selected", "false");
                }
            }
        }
    }
}
 
Example 27
Source Project: nalu   Source File: NaluPluginGWT.java    License: Apache License 2.0 4 votes vote down vote up
private Element getHeaderNode() {
  NodeList<Element> node = Document.get()
                                   .getElementsByTagName("head");
  return node.getItem(0);
}
 
Example 28
Source Project: calendar-component   Source File: DateCell.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public void onMouseUp(MouseUpEvent event) {

    if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
        return;
    }

    Event.releaseCapture(getElement());
    setFocus(false);

    // Drag initialized?
    if (eventRangeStart >= 0) {
        Element main = getElement();
        if (eventRangeStart > eventRangeStop) {
            if (eventRangeStop <= -1) {
                eventRangeStop = 0;
            }
            int temp = eventRangeStart;
            eventRangeStart = eventRangeStop;
            eventRangeStop = temp;
        }

        // This happens for single clicks without dragging on the calendar
        if(eventRangeStart == eventRangeStop) {
            handleEventRange(event);
        }

        NodeList<Node> nodes = main.getChildNodes();

        int slotStart = -1;
        int slotEnd = -1;

        // iterate over all child nodes, until we find first the start,
        // and then the end
        for (int i = 0; i < nodes.getLength(); i++) {
            Element element = (Element) nodes.getItem(i);
            boolean isRangeElement = element.getClassName().contains("v-daterange");

            if (isRangeElement && slotStart == -1) {
                slotStart = i;
                slotEnd = i; // to catch one-slot selections

            } else if (isRangeElement) {
                slotEnd = i;

            } else if (slotStart != -1 && slotEnd != -1) {
                break; // FIXME ! is 'else if' right
            }
        }

        clearSelectionRange();

        int startMinutes = firstHour * 60 + slotStart * 30;
        int endMinutes = (firstHour * 60) + (slotEnd + 1) * 30;
        Date currentDate = getDate();

        if (weekgrid.getCalendar().getRangeSelectListener() != null) {

            SelectionRange weekSelection = new SelectionRange();
            weekSelection.sMin = startMinutes;
            weekSelection.eMin = endMinutes;
            weekSelection.setStartDay(DateConstants.toRPCDate(
                    currentDate.getYear(),
                    currentDate.getMonth(),
                    currentDate.getDate()));

            weekgrid.getCalendar().getRangeSelectListener().rangeSelected(weekSelection);
        }
        eventRangeStart = -1;

    } else {

        // Click event
        eventRangeStart = -1;
        cancelRangeSelect();
    }
}
 
Example 29
Source Project: calendar-component   Source File: DateCell.java    License: Apache License 2.0 4 votes vote down vote up
private void handleEventRange(final MouseEvent event) {

        if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
            return;
        }

        if (eventRangeStart >= 0) {

            int newY = event.getY();
            int fromY, toY;

            if (newY < eventRangeStart) {
                fromY = newY;
                toY = eventRangeStart;
            } else {
                fromY = eventRangeStart;
                toY = newY;
            }

            eventRangeStop = newY;

            Element main = getElement();
            NodeList<Node> nodes = main.getChildNodes();
            for (int i = 0; i < nodes.getLength(); i++) {

                Element c = (Element) nodes.getItem(i);

                if (Arrays.stream(slotElements).anyMatch(e -> e == c)) {

                    int elemStart = c.getOffsetTop();
                    int elemStop = elemStart + getSlotHeight();
                    if (elemStart >= fromY && elemStart <= toY) {
                        c.addClassName("v-daterange");
                    } else if (elemStop >= fromY && elemStop <= toY) {
                        c.addClassName("v-daterange");
                    } else if (elemStop >= fromY && elemStart <= toY) {
                        c.addClassName("v-daterange");
                    } else {
                        c.removeClassName("v-daterange");
                    }
                }
            }
        }

        event.preventDefault();
    }
 
Example 30
Source Project: cuba   Source File: HtmlAttributesExtensionConnector.java    License: Apache License 2.0 4 votes vote down vote up
private static native NodeList<Element> findSubElements(Element parent, String querySelector) /*-{
    return parent.querySelectorAll(querySelector);
}-*/;