List of usage examples for com.google.gwt.dom.client Element getNextSibling
@Override
public Node getNextSibling()
From source file:com.bfr.client.selection.impl.RangeImplIE6.java
License:Apache License
/** * Get the IE start or end point of the given range, have to search for it * to find it properly.// w ww . j ava2s. c om * * @param range used to get the document * @param selRange the selection we are getting the point of * @param start whether to get the start or end point * @return RangeEndPoint representing this, or null on error */ private RangeEndPoint getRangeEndPoint(Range range, JSRange selRange, boolean start) { RangeEndPoint res = null; // Create a cursor at either the beginning or end of the range, to // get that point's immediate parent JSRange checkRange = cloneRange(selRange); collapseRange(checkRange, start); Element parent = getCommonAncestor(checkRange); String compareFcn = BOUNDARY_STRINGS[start ? Range.START_TO_START : Range.END_TO_END]; Node compNode; // Test element we move around the document to check relative selection Element testElement = getTestElement(range.getDocument()); try { // Move the test element backwards past nodes until we are in front // of the desired range endpoint for (compNode = parent.getLastChild(); compNode != null; compNode = testElement.getPreviousSibling()) { parent.insertBefore(testElement, compNode); moveToElementText(checkRange, testElement); if (compareBoundaryPoint(checkRange, selRange, compareFcn) <= 0) { break; } } if (compNode == null) { // Sometimes selection at beginning of a span causes a fail compNode = testElement.getNextSibling(); } if (compNode == null) { } else if (compNode.getNodeType() == Node.ELEMENT_NODE) { // We only represent text elements right now, so if this is not // then go find one. Check if the desired selection is at the // beginning or end of this element, first select the entire // element to determine whether the endpoint is at the // beginning or the end of it, ie whether to look forward or // backward. testElement.removeFromParent(); moveToElementText(checkRange, (Element) compNode); int cmp = compareBoundaryPoint(checkRange, selRange, compareFcn); boolean dir = (cmp == 0) ? !start : (cmp < 0); Text closest = Range.getAdjacentTextElement(compNode, parent, dir, true); if (closest == null) { dir = !dir; closest = Range.getAdjacentTextElement(compNode, parent, dir, true); } if (closest != null) { // Found a text node in one direction or the other res = new RangeEndPoint(closest, dir ? 0 : closest.getLength()); } } else { // Get the proper offset, move the end of the check range to the // boundary of the actual range and get its length moveRangePoint(checkRange, selRange, BOUNDARY_STRINGS[start ? Range.END_TO_START : Range.END_TO_END]); res = new RangeEndPoint((Text) compNode, getText(checkRange).length()); } } catch (Exception ex) { GWT.log("Failed to find IE selection", ex); } finally { // Make sure this gets removed from the document no matter what testElement.removeFromParent(); } return (res == null) ? new RangeEndPoint() : res; }
From source file:com.sencha.gxt.widget.core.client.ListView.java
License:sencha.com license
protected void onAdd(List<M> models, final int index) { if (!isOrWasAttached()) { return;// w ww.j a va 2 s. c o m } boolean empty = all.getCount() == 0; // add on sorted store, fires multiple adds while store has all models // before firing if (empty && models.size() == store.size()) { refresh(); return; } SafeHtmlBuilder sb = new SafeHtmlBuilder(); bufferRender(models, sb); Element d = Document.get().createDivElement(); d.setInnerSafeHtml(sb.toSafeHtml()); List<Element> list = appearance.findElements(d.<XElement>cast()); final Element ref = index == 0 ? null : all.getElement(index - 1); final Element n = ref == null ? null : ref.getParentElement(); for (int i = list.size() - 1; i >= 0; i--) { Element e = list.get(i); if (index == 0) { getElement().insertFirst(e); } else { Node next = ref == null ? null : ref.getNextSibling(); if (next == null) { n.appendChild(e); } else { n.insertBefore(e, next); } } } all.insert(Util.toElementArray(list), index); updateIndexes(index, -1); }
From source file:com.vaadin.client.WidgetUtil.java
License:Apache License
/** * Detaches and re-attaches the element from its parent. The element is * reattached at the same position in the DOM as it was before. * //from w ww . ja v a2s .com * Does nothing if the element is not attached to the DOM. * * @param element * The element to detach and re-attach */ public static void detachAttach(Element element) { if (element == null) { return; } Node nextSibling = element.getNextSibling(); Node parent = element.getParentNode(); if (parent == null) { return; } parent.removeChild(element); if (nextSibling == null) { parent.appendChild(element); } else { parent.insertBefore(element, nextSibling); } }
From source file:org.rstudio.studio.client.workbench.views.help.model.HelpInfo.java
License:Open Source License
public final ParsedInfo parse(String defaultSignature) { HashMap<String, String> values = new HashMap<String, String>(); HashMap<String, String> args = new HashMap<String, String>(); HashMap<String, String> slots = new HashMap<String, String>(); String html = getHTML();//ww w .j a v a 2 s .c om if (html != null) { DivElement div = Document.get().createDivElement(); div.setInnerHTML(html); // disable all links NodeList<Element> anchors = div.getElementsByTagName("a"); for (int i = 0; i < anchors.getLength(); i++) { Element anchor = anchors.getItem(i); Element parent = anchor.getParentElement(); Node child = anchor.getFirstChild(); while (child != null) { parent.insertBefore(child, anchor); child = child.getNextSibling(); } } // parse all description lists NodeList<Element> descriptionLists = div.getElementsByTagName("dl"); for (int i = 0; i < descriptionLists.getLength(); i++) parseDescriptionList(args, descriptionLists.getItem(i)); // get all h2 and h3 headings NodeList<Element> h2headings = div.getElementsByTagName("h2"); NodeList<Element> h3headings = div.getElementsByTagName("h3"); ArrayList<Element> headings = new ArrayList<Element>(); for (int i = 0; i < h2headings.getLength(); i++) headings.add(h2headings.getItem(i)); for (int i = 0; i < h3headings.getLength(); i++) headings.add(h3headings.getItem(i)); // the first h2 heading is the title -- handle that specially if (headings.size() > 0) { Element titleElement = headings.get(0); String title = titleElement.getInnerText(); values.put("Title", title); } // iterate through them for (int i = 1; i < headings.size(); i++) { Element heading = headings.get(i); String name = heading.getInnerText(); if (name.equals("Arguments")) { parseArguments(args, heading); } if (name.equals("Slots")) { parseDescriptionList(slots, heading); } StringBuffer value = new StringBuffer(); Node sibling = heading.getNextSibling(); while (sibling != null && !sibling.getNodeName().toLowerCase().equals("h2") && !sibling.getNodeName().toLowerCase().equals("h3")) { value.append(DomUtils.getHtml(sibling)); sibling = sibling.getNextSibling(); } values.put(name, value.toString()); } } String signature = getSignature(); if (signature == null) signature = defaultSignature; return new ParsedInfo(getPackageName(), signature, values, args, slots); }
From source file:org.waveprotocol.wave.client.common.util.DomHelper.java
License:Apache License
/** * @param element The element to unwrap. If not attached, does nothing. *///from w ww.jav a 2s . co m public static void unwrap(Element element) { if (element.hasParentElement()) { moveNodes(element.getParentElement(), element.getFirstChild(), null, element.getNextSibling()); element.removeFromParent(); } }
From source file:org.waveprotocol.wave.client.editor.content.paragraph.IeNodeletHelper.java
License:Apache License
/** * Some IE element classes require their html nodelets be attached to * somewhere under the body of html document in order for implementation to * work. See, e.g., {@link ParagraphHelperIE#onEmpty(Element)} *//*from w w w. j a v a 2 s . com*/ public static Point<Node> beforeImplementation(Element nodelet) { // Get point after nodelet Point<Node> point = nodelet.getParentNode() != null ? Point.inElement(nodelet.getParentNode(), nodelet.getNextSibling()) : null; // Attach nodelet to document body Document.get().getBody().appendChild(nodelet); return point; }
From source file:org.waveprotocol.wave.client.editor.selection.html.SelectionImplIE.java
License:Apache License
/** * Search for node by pasting that element at a textRange and locating that * element directly using getElementById. This is a huge shortcut when there * are many nodes in parent. However, use with caution as it can fragment text * nodes.// w ww . j a v a 2 s . co m * * NOTE(user): The text node fragmentation is a real issue, it causes repairs * to happen. The constant splitting and repairing can also have performance * issues that needs to be investigated. We should repair the damage here, * when its clear how to fix the problem. * * @param target * @param parent * @return Point */ @SuppressWarnings("unused") // NOTE(user): Use later for nodes with many siblings. private Point<Node> searchForRangeUsingPaste(JsTextRangeIE target, Element parent) { Element elem = null; try { target.pasteHTML("<b id='__paste_target__'>X</b>"); elem = Document.get().getElementById("__paste_target__"); Node nextSibling = elem.getNextSibling(); if (DomHelper.isTextNode(nextSibling)) { return Point.inText(nextSibling, 0); } else { return Point.inElement(parent, nextSibling); } } finally { if (elem != null) { elem.removeFromParent(); } } }
From source file:org.waveprotocol.wave.client.editor.selection.html.SelectionImplIE.java
License:Apache License
/** * @param range/*from w ww. j av a 2 s . com*/ * @param element * @return input range collapsed after element */ @SuppressWarnings("unused") // TODO(zdwang): Dead code. Left here, as it may be useful later. private JsTextRangeIE collapseAfterElement(JsTextRangeIE range, Element element) { Node next = element.getNextSibling(); return (next != null) ? collapseBeforeNode(range, next) : collapseAtEnd(range, element.getParentElement()); }
From source file:sf.wicklet.gwt.client.util.GwtDomUtil.java
License:Apache License
public static void replace(final com.google.gwt.dom.client.Element oelm, final com.google.gwt.dom.client.Element nelm) { final com.google.gwt.dom.client.Node parent = oelm.getParentNode(); final com.google.gwt.dom.client.Node mark = oelm.getNextSibling(); parent.removeChild(oelm);// ww w.j av a2s.c om parent.insertBefore(nelm, mark); }