Example usage for com.google.gwt.dom.client SpanElement getNextSibling

List of usage examples for com.google.gwt.dom.client SpanElement getNextSibling

Introduction

In this page you can find the example usage for com.google.gwt.dom.client SpanElement getNextSibling.

Prototype

@Override
    public Node getNextSibling() 

Source Link

Usage

From source file:org.nuxeo.ecm.platform.annotations.gwt.client.view.decorator.AnnoteaDecoratorVisitor.java

License:Apache License

private void processDecoratedNode(Node node, String data, Node parent) {
    String[] selectedText = getSelectedText(data, textToAnnotate);
    if (selectedText[1].trim().length() == 0 && selectedText[2].trim().length() == 0
            && node.getParentNode().getNodeName().equalsIgnoreCase("tr")) {
        // don't add nodes to tr
        textToAnnotate -= selectedText[0].length();
        return;//w  w  w  .  jav  a2s.  c  om
    }
    Document document = node.getOwnerDocument();
    SpanElement spanElement = getSpanElement(document);
    spanElement.setInnerText(selectedText[1]);
    insertBefore(parent, node.getNextSibling(), spanElement);
    if (selectedText[2].length() > 0) {
        insertBefore(parent, spanElement.getNextSibling(), document.createTextNode(selectedText[2]));
    }
    textToAnnotate -= selectedText[0].length();
}

From source file:org.waveprotocol.wave.client.clipboard.Clipboard.java

License:Apache License

/**
 * Hijacks the paste fragment by hiding a span with metadata at the end of the
 * fragment.//w ww .jav a2 s . c om
 *
 * @param xmlInRange The xml string to pass into the magic span element
 * @param annotations The annotation string to pass into the magic span
 *        element
 * @param origRange the current range. The span element will be inserted
 *        before the start
 *
 * @return The new adjusted selection. The end will be adjusted such that it
 *         encloses the original selection and the span with metadata
 */
private PointRange<Node> hijackFragment(String xmlInRange, String annotations, PointRange<Node> origRange) {
    Point<Node> origStart = origRange.getFirst();
    Point<Node> origEnd = origRange.getSecond();
    SpanElement spanForXml = Document.get().createSpanElement();
    spanForXml.setAttribute(WAVE_XML_ATTRIBUTE, xmlInRange);
    spanForXml.setAttribute(WAVE_ANNOTATIONS_ATTRIBUTE, annotations);
    spanForXml.setClassName(MAGIC_CLASSNAME);

    LOG.trace().log("original point: " + origStart);

    // NOTE(user): An extra span is required at the end for Safari, otherwise
    // the span with the metadata may get discarded.
    SpanElement trailingSpan = Document.get().createSpanElement();
    trailingSpan.setInnerHTML("&nbsp;");

    if (origEnd.isInTextNode()) {
        Text t = (Text) origEnd.getContainer();
        t.setData(t.getData().substring(0, origEnd.getTextOffset()));
        origEnd.getContainer().getParentElement().insertAfter(spanForXml, t);
        origEnd.getContainer().getParentElement().insertAfter(trailingSpan, spanForXml);
    } else {
        origEnd.getContainer().insertAfter(spanForXml, origEnd.getNodeAfter());
        origEnd.getContainer().insertAfter(trailingSpan, spanForXml);
    }

    Point<Node> newEnd = Point.<Node>inElement(spanForXml.getParentElement(), trailingSpan.getNextSibling());
    LOG.trace().log("new point: " + newEnd);
    LOG.trace().logPlainText("parent: " + spanForXml.getParentElement().getInnerHTML());
    assert newEnd.getNodeAfter() == null
            || newEnd.getNodeAfter().getParentElement() == newEnd.getContainer() : "inconsistent point";
    return new PointRange<Node>(origStart, newEnd);
}