Java Code Examples for com.google.gwt.dom.client.NodeList#getItem()

The following examples show how to use com.google.gwt.dom.client.NodeList#getItem() . 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   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: cuba   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 3
/**
 * 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 4
Source Project: swellrt   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 5
Source Project: nalu   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 6
Source Project: gwtbootstrap3-extras   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 7
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 8
Source Project: cuba   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 9
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 10
Source Project: proarc   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 11
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 12
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 13
Source Project: swcv   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 14
@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 15
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 16
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 17
Source Project: nalu   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 18
Source Project: calendar-component   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 19
Source Project: calendar-component   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 20
Source Project: unitime   File: Client.java    License: Apache License 2.0 4 votes vote down vote up
public void onModuleLoadDeferred() {
	// register triggers
	GWT.runAsync(new RunAsyncCallback() {
		@Override
		public void onSuccess() {
			for (Triggers t: Triggers.values())
				t.register();
			callGwtOnLoadIfExists();
		}
		@Override
		public void onFailure(Throwable reason) {
		}
	});
	
	// load page
	if (RootPanel.get("UniTimeGWT:Body") != null) {
		LoadingWidget.getInstance().show(MESSAGES.waitLoadingPage());
		Scheduler.get().scheduleDeferred(new ScheduledCommand() {
			@Override
			public void execute() {
				initPageAsync(Window.Location.getParameter("page"));
			}
		});
	}
	
	// load components
	for (final Components c: Components.values()) {
		final RootPanel p = RootPanel.get(c.id());
		if (p != null) {
			Scheduler.get().scheduleDeferred(new ScheduledCommand() {
				@Override
				public void execute() {
					initComponentAsync(p, c);
				}
			});
		}
		if (p == null && c.isMultiple()) {
			NodeList<Element> x = getElementsByName(c.id());
			if (x != null && x.getLength() > 0)
				for (int i = 0; i < x.getLength(); i++) {
					Element e = x.getItem(i);
					e.setId(DOM.createUniqueId());
					final RootPanel q = RootPanel.get(e.getId());
					Scheduler.get().scheduleDeferred(new ScheduledCommand() {
						@Override
						public void execute() {
							initComponentAsync(q, c);
						}
					});
				}
		}
	}
	
	Window.addWindowClosingHandler(new Window.ClosingHandler() {
		@Override
		public void onWindowClosing(Window.ClosingEvent event) {
			if (isLoadingDisplayed() || LoadingWidget.getInstance().isShowing()) return;
			LoadingWidget.showLoading(MESSAGES.waitPlease());
			iPageLoadingTimer = new Timer() {
				@Override
				public void run() {
					RPC.execute(new IsSessionBusyRpcRequest(), new AsyncCallback<GwtRpcResponseBoolean>() {
						@Override
						public void onFailure(Throwable caught) {
							LoadingWidget.hideLoading();
						}
						@Override
						public void onSuccess(GwtRpcResponseBoolean result) {
							if (result.getValue()) {
								iPageLoadingTimer.schedule(500);
							} else {
								LoadingWidget.hideLoading();
							}
						}
					});
				}
			};
			iPageLoadingTimer.schedule(500);
		}
	});
}