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

The following examples show how to use com.google.gwt.dom.client.NodeList#getLength() . 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
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 3
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 4
/**
 * 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 5
Source Project: gantt   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 6
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 7
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 8
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 9
@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 10
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 11
Source Project: gwt-material   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 12
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 13
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 14
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 15
Source Project: swellrt   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 16
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 17
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 18
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 19
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 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);
		}
	});
}