Java Code Examples for com.google.gwt.dom.client.Element#getChild()
The following examples show how to use
com.google.gwt.dom.client.Element#getChild() .
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 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 |
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: GroupedListBox.java From swcv with MIT License | 6 votes |
protected int getIndexInGroup(String group, int index) { if (group == null) return index; int adjusted = index; Element elm = getElement(); int sz = elm.getChildCount(); for (int i = 0; i < sz; i++) { Node child = elm.getChild(i); if (isMatchingGroup(child, group)) { break; } if (isGroup(child)) { adjusted -= child.getChildCount(); } else { adjusted -= 1; } } return adjusted; }
Example 4
Source File: GroupedListBox.java From gwt-traction with Apache License 2.0 | 6 votes |
@Override public Node getInsertBeforeElement(int index) { Node before = null; Element parent = getElement(); // make sure we're not past the initial "group" of // ungrouped options int max = getIndexOfFirstGroup(); if (index < 0 || index > max) { if (max < getChildCount()) { before = parent.getChild(max); } } else if (0 <= index && index < getChildCount()) { before = parent.getChild(index); } return before; }
Example 5
Source File: NavSpy.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
private void collectHeadings(Element element, List<Element> headings) { for (int i = 0; i < element.getChildCount(); i++) { Node node = element.getChild(i); if (node instanceof Element) { Element child = (Element) node; String tagName = child.getTagName(); if (tagName != null && Heading.HEADING_TAGS.contains(tagName.toLowerCase())) { if (this.spyName != null && this.spyName.equals(child.getAttribute(Heading.ATTRIBUTE_DATA_SUMMARY))) { headings.add(child); } } else { this.collectHeadings(child, headings); } } } }
Example 6
Source File: MaterialToastTest.java From gwt-material with Apache License 2.0 | 5 votes |
public void testMultipleToasts() { for (int i = 1; i <= 5; i++) { MaterialToast.fireToast("test" + i); } Element toastContainer = $("body").find("#toast-container").asElement(); assertNotNull(toastContainer); assertEquals(toastContainer.getChildCount(), 5); // Check each toasts for (int i = 0; i < 5; i++) { Element toastElement = (Element) toastContainer.getChild(i); assertEquals(toastElement.getInnerHTML(), "test" + (i + 1)); } toastContainer.setInnerHTML(""); assertEquals(toastContainer.getChildCount(), 0); }
Example 7
Source File: MaterialToastTest.java From gwt-material with Apache License 2.0 | 5 votes |
public void testToastWithStyling() { MaterialToast.fireToast("test", "rounded"); Element toastContainer = $("body").find("#toast-container").asElement(); assertNotNull(toastContainer); assertEquals(toastContainer.getChildCount(), 1); assertNotNull(toastContainer.getChild(0)); assertTrue(toastContainer.getChild(0) instanceof Element); Element toastElement = (Element) toastContainer.getChild(0); assertTrue(toastElement.hasClassName("rounded")); toastContainer.setInnerHTML(""); }
Example 8
Source File: MaterialToastTest.java From gwt-material with Apache License 2.0 | 5 votes |
public void testToastWithWidget() { MaterialLink link = new MaterialLink(); new MaterialToast(link).toast("test"); Element toastContainer = $("body").find("#toast-container").asElement(); assertNotNull(toastContainer); assertEquals(toastContainer.getChildCount(), 1); assertNotNull(toastContainer.getChild(0)); assertTrue(toastContainer.getChild(0) instanceof Element); Element toastElement = (Element) toastContainer.getChild(0); // Check the span text assertEquals($(toastElement.getChild(0)).text(), "test"); // Check the added link to toast component assertEquals(link.getElement(), toastElement.getChild(1)); toastContainer.setInnerHTML(""); }
Example 9
Source File: MaterialToastTest.java From gwt-material with Apache License 2.0 | 5 votes |
public void testToastStructure() { MaterialToast.fireToast("test"); Element toastContainer = $("body").find("#toast-container").asElement(); assertNotNull(toastContainer); assertEquals(toastContainer.getChildCount(), 1); assertNotNull(toastContainer.getChild(0)); assertTrue(toastContainer.getChild(0) instanceof Element); Element toastElement = (Element) toastContainer.getChild(0); assertEquals(toastElement.getInnerHTML(), "test"); toastContainer.setInnerHTML(""); }
Example 10
Source File: GroupedListBox.java From swcv with MIT License | 5 votes |
protected OptionElement getOption(int index) { checkIndex(index); // first check ungrouped Element elm = getElement(); int sz = elm.getChildCount(); int firstGroup = getIndexOfFirstGroup(); if (index >= 0 && index < firstGroup && index < sz) { return option(elm.getChild(index)); } // then go through the groups int childIndex = index - firstGroup; for (int i = firstGroup; i <= index && i < sz; i++) { Node child = elm.getChild(i); if (isGroup(child)) { if (childIndex < child.getChildCount()) { return option(child.getChild(childIndex)); } else { childIndex -= child.getChildCount(); } } } return null; }
Example 11
Source File: SelectionImplIE.java From swellrt with Apache License 2.0 | 4 votes |
private Point<Node> binarySearchForRange(JsTextRangeIE target, Element parent) { try { JsTextRangeIE attempt = JsTextRangeIE.create(); int low = 0; int high = parent.getChildCount() - 1; while (low <= high) { int mid = (low + high) >>> 1; Node node = parent.getChild(mid); node.getParentNode().insertBefore(setter, node); attempt.moveToElementText(setter).collapse(false); int cmp = attempt.compareEndPoints(CompareMode.StartToEnd, target); if (cmp == 0) { if (DomHelper.isTextNode(node)) { return Point.inText(node, 0); } else { return Point.inElement(parent, node); } } else if (cmp > 0) { high = mid - 1; } else { if (DomHelper.isTextNode(node)) { JsTextRangeIE dup = attempt.duplicate(); dup.setEndPoint(EndToEnd, target); if (dup.getText().length() <= node.<Text> cast().getLength()) { return Point.inText(node, dup.getText().length()); } } else { attempt.moveToElementText(node.<Element> cast()).collapse(false); if (attempt.compareEndPoints(StartToStart, target) >= 0) { return Point.inElement(parent, node); } } low = mid + 1; } setter.removeFromParent(); } return Point.<Node> end(parent); } finally { setter.removeFromParent(); } }
Example 12
Source File: GroupedListBox.java From swcv with MIT License | 4 votes |
@Override public void insertItem(String item, String value, int index) { // find the delimiter if there is one int pipe = (item != null) ? item.indexOf('|') : -1; while (pipe != -1 && pipe + 1 != item.length() && item.charAt(pipe + 1) == '|') { pipe = item.indexOf('|', pipe + 2); } // extract the group if we found a delimiter String group = null; if (pipe != -1) { group = item.substring(0, pipe).trim(); item = item.substring(pipe + 1).trim(); // make sure we convert || -> | in the group name group = group.replace("||", "|"); } Element parent = getSelectElement(); Node before = null; if (group != null) { OptGroupElement optgroup = findOptGroupElement(group); if (optgroup != null) { // add it to this optgroup parent = optgroup; // adjust the index to inside the group int adjusted = getIndexInGroup(group, index); // we had a real index (wasn't negative which means // add to the end), but it was too low for this group. // put it at the beginning of the group. if (adjusted < 0 && index >= 0) { adjusted = 0; } // check the range and if it's out of range, we'll // just add it to the end // of the group (before == null) if (0 <= adjusted && adjusted < optgroup.getChildCount()) { before = optgroup.getChild(adjusted); } } else { // add a new group and add the item to it optgroup = Document.get().createOptGroupElement(); optgroup.setLabel(group); parent.appendChild(optgroup); parent = optgroup; before = null; } } else { // make sure we're not past the initial "group" of // ungrouped options int max = getIndexOfFirstGroup(); if (index < 0 || index > max) { before = (max < parent.getChildCount()) ? parent.getChild(max) : null; } else if (0 <= index && index < parent.getChildCount()) { before = parent.getChild(index); } } OptionElement option = createOption(item, value); parent.insertBefore(option, before); }
Example 13
Source File: SelectionImplIE.java From incubator-retired-wave with Apache License 2.0 | 4 votes |
private Point<Node> binarySearchForRange(JsTextRangeIE target, Element parent) { try { JsTextRangeIE attempt = JsTextRangeIE.create(); int low = 0; int high = parent.getChildCount() - 1; while (low <= high) { int mid = (low + high) >>> 1; Node node = parent.getChild(mid); node.getParentNode().insertBefore(setter, node); attempt.moveToElementText(setter).collapse(false); int cmp = attempt.compareEndPoints(CompareMode.StartToEnd, target); if (cmp == 0) { if (DomHelper.isTextNode(node)) { return Point.inText(node, 0); } else { return Point.inElement(parent, node); } } else if (cmp > 0) { high = mid - 1; } else { if (DomHelper.isTextNode(node)) { JsTextRangeIE dup = attempt.duplicate(); dup.setEndPoint(EndToEnd, target); if (dup.getText().length() <= node.<Text> cast().getLength()) { return Point.inText(node, dup.getText().length()); } } else { attempt.moveToElementText(node.<Element> cast()).collapse(false); if (attempt.compareEndPoints(StartToStart, target) >= 0) { return Point.inElement(parent, node); } } low = mid + 1; } setter.removeFromParent(); } return Point.<Node> end(parent); } finally { setter.removeFromParent(); } }
Example 14
Source File: DomHelper.java From swellrt with Apache License 2.0 | 2 votes |
/** * Given a node/offset pair, return the node after the point. * * @param container * @param offset */ public static Node nodeAfterFromOffset(Element container, int offset) { return offset >= container.getChildCount() ? null : container.getChild(offset); }
Example 15
Source File: DomHelper.java From incubator-retired-wave with Apache License 2.0 | 2 votes |
/** * Given a node/offset pair, return the node after the point. * * @param container * @param offset */ public static Node nodeAfterFromOffset(Element container, int offset) { return offset >= container.getChildCount() ? null : container.getChild(offset); }