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

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

Introduction

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

Prototype

@Override
    public Node getNextSibling() 

Source Link

Usage

From source file:client.net.sf.saxon.ce.dom.HTMLNodeWrapper.java

License:Mozilla Public License

/**
 * Get the value of the item as a CharSequence. This is in some cases more efficient than
 * the version of the method that returns a String.
 *//*from w ww. j  a  va 2 s  . c o  m*/

public CharSequence getStringValueCS() {
    switch (nodeKind) {
    case Type.DOCUMENT:
    case Type.ELEMENT:
        NodeList children1 = node.getChildNodes();
        StringBuffer sb1 = new StringBuffer(16);
        expandStringValue(children1, sb1);
        return sb1;

    case Type.ATTRIBUTE:
        return emptyIfNull(getValue(node)); // previously used xml.client attr cast

    case Type.TEXT:
        if (span == 1) {
            return emptyIfNull(getValue(node));
        } else {
            FastStringBuffer fsb = new FastStringBuffer(FastStringBuffer.SMALL);
            Node textNode = node;
            for (int i = 0; i < span; i++) {
                fsb.append(emptyIfNull(getValue(textNode)));
                textNode = textNode.getNextSibling();
            }
            return fsb.condense();
        }

    case Type.COMMENT:
    case Type.PROCESSING_INSTRUCTION:
        return emptyIfNull(getValue(node));

    default:
        return "";
    }
}

From source file:com.ait.toolkit.editors.ckeditor.client.CKEditor.java

License:Open Source License

/**
 * Use to disable CKEditor's instance//from w  w w  .  j  a va  2  s .co m
 * 
 * @param disabled
 */
public void setEnabled(boolean enabled) {
    // FIXME : rework this part to remove the !
    boolean disabled = !enabled;

    if (this.disabled != disabled) {
        this.disabled = disabled;

        if (disabled) {
            ScrollPanel scroll = new ScrollPanel();
            disabledHTML = new HTML();
            disabledHTML.setStyleName("GWTCKEditor-Disabled");
            scroll.setWidget(disabledHTML);

            if (config.getWidth() != null)
                scroll.setWidth(config.getWidth());

            if (config.getHeight() != null)
                scroll.setHeight(config.getHeight());

            String htmlString = new String();

            if (replaced) {
                htmlString = getHTML();
            } else {
                htmlString = waitingText;
            }

            DivElement divElement = DivElement.as(this.getElement().getFirstChildElement());
            Node node = divElement.getFirstChild();
            while (node != null) {
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    com.google.gwt.dom.client.Element element = com.google.gwt.dom.client.Element.as(node);
                    if (element.getTagName().equalsIgnoreCase("textarea")) {
                        destroyInstance();
                        replaced = false;
                        divElement.removeChild(node);
                        ckEditorNode = node;
                    }
                }
                node = node.getNextSibling();
            }
            disabledHTML.setHTML(htmlString);
            div.appendChild(scroll.getElement());

        } else {
            if (ckEditorNode != null) {
                DivElement divElement = DivElement.as(this.getElement().getFirstChildElement());
                Node node = divElement.getFirstChild();
                while (node != null) {
                    if (node.getNodeType() == Node.ELEMENT_NODE) {
                        com.google.gwt.dom.client.Element element = com.google.gwt.dom.client.Element.as(node);
                        if (element.getTagName().equalsIgnoreCase("div")) {
                            divElement.removeChild(node);

                        }
                    }
                    node = node.getNextSibling();
                }
                div.appendChild(baseTextArea);
                initInstance();

            }
        }
    }

}

From source file:com.axeiya.gwtckeditor.client.CKEditor.java

License:Open Source License

/**
 * Use to disable CKEditor's instance/*from   w w  w.ja  v a  2 s. c  o m*/
 * 
 * @param disabled
 */
public void setEnabled(boolean enabled) {
    //FIXME : rework this part to remove the !
    boolean disabled = !enabled;

    if (this.disabled != disabled) {
        this.disabled = disabled;

        if (disabled) {
            ScrollPanel scroll = new ScrollPanel();
            disabledHTML = new HTML();
            disabledHTML.setStyleName("GWTCKEditor-Disabled");
            scroll.setWidget(disabledHTML);

            if (config.getWidth() != null)
                scroll.setWidth(config.getWidth());

            if (config.getHeight() != null)
                scroll.setHeight(config.getHeight());

            String htmlString = new String();

            if (replaced) {
                htmlString = getHTML();
            } else {
                htmlString = waitingText;
            }

            DivElement divElement = DivElement.as(this.getElement().getFirstChildElement());
            Node node = divElement.getFirstChild();
            while (node != null) {
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    com.google.gwt.dom.client.Element element = com.google.gwt.dom.client.Element.as(node);
                    if (element.getTagName().equalsIgnoreCase("textarea")) {
                        destroyInstance();
                        replaced = false;
                        divElement.removeChild(node);
                        ckEditorNode = node;
                    }
                }
                node = node.getNextSibling();
            }
            disabledHTML.setHTML(htmlString);
            div.appendChild(scroll.getElement());

        } else {
            if (ckEditorNode != null) {
                DivElement divElement = DivElement.as(this.getElement().getFirstChildElement());
                Node node = divElement.getFirstChild();
                while (node != null) {
                    if (node.getNodeType() == Node.ELEMENT_NODE) {
                        com.google.gwt.dom.client.Element element = com.google.gwt.dom.client.Element.as(node);
                        if (element.getTagName().equalsIgnoreCase("div")) {
                            divElement.removeChild(node);

                        }
                    }
                    node = node.getNextSibling();
                }
                div.appendChild(baseTextArea);
                initInstance();

            }
        }
    }

}

From source file:com.bfr.client.selection.Range.java

License:Apache License

/**
 * Returns the next adjacent text node in the given direction.  Will move
 * down the hierarchy (if traversingUp is not set), then through siblings,
 * then up (but not past topMostNode), looking for the first node
 * <p/>//from  w w w  . j  av a2s . c om
 * This could be non-statically included in the Node class
 *
 * @param current      An element to start the search from, can be any type
 *                     of node.
 * @param topMostNode  A node that this will traverse no higher than
 * @param forward      whether to search forward or backward
 * @param traversingUp if true, will not look at the children of this element
 * @return the next (previous) text node, or null if no more
 */
public static Text getAdjacentTextElement(Node current, Node topMostNode, boolean forward,
        boolean traversingUp) {
    Text res = null;
    Node node;

    // If traversingUp, then the children have already been processed
    if (!traversingUp) {
        if (current.getChildCount() > 0) {
            node = forward ? current.getFirstChild() : current.getLastChild();

            if (node.getNodeType() == Node.TEXT_NODE) {
                res = (Text) node;
            } else {
                // Depth first traversal, the recursive call deals with
                // siblings
                res = getAdjacentTextElement(node, topMostNode, forward, false);
            }
        }
    }

    if (res == null) {
        node = forward ? current.getNextSibling() : current.getPreviousSibling();
        // Traverse siblings
        if (node != null) {
            if (node.getNodeType() == Node.TEXT_NODE) {
                res = (Text) node;
            } else {
                // Depth first traversal, the recursive call deals with
                // siblings
                res = getAdjacentTextElement(node, topMostNode, forward, false);
            }
        }
    }

    // Go up and over if still not found
    if ((res == null) && (current != topMostNode)) {
        node = current.getParentNode();
        // Stop at document (technically could stop at "html" tag)
        if ((node != null) && (node.getNodeType() != Node.DOCUMENT_NODE)) {
            res = getAdjacentTextElement(node, topMostNode, forward, true);
        }
    }

    return res;
}

From source file:com.dom_distiller.client.DomWalker.java

License:Open Source License

/**
 * Walk the subtree rooted at n./*from w w w  .  j  a v a2 s.c om*/
 */
public void walk(Node top) {
    // Conceptually, this maintains a pointer to the currently "walked" node. When first seeing
    // the node, it calls visit() on it. The next node to visit is then (1) the first child, (2)
    // the next sibling, or (3) the next sibling of the first ancestor w/ a next sibling.
    //
    // Every time the walk "crosses" the "exit" of a node (i.e. when the pointer goes from
    // somewhere in the node's subtree to somewhere outside of that subtree), exit() is called
    // for that node (unless visit() for that node returned false).
    if (!visitor.visit(top))
        return;
    Node n = top.getFirstChild();
    if (n != null) {
        while (n != top) {
            // shouldExit is used to suppress the exit call for the current node when visit()
            // returns false.
            boolean shouldExit = false;
            if (visitor.visit(n)) {
                Node c = n.getFirstChild();
                if (c != null) {
                    n = c;
                    continue;
                }
                shouldExit = true;
            }

            while (n != top) {
                if (shouldExit)
                    visitor.exit(n);
                Node s = n.getNextSibling();
                if (s != null) {
                    n = s;
                    break;
                }
                n = n.getParentNode();
                shouldExit = true;
            }
        }
    }
    visitor.exit(top);
}

From source file:com.google.livingstories.client.lsp.views.contentitems.QuoteContentItemView.java

License:Apache License

public Node getFirstTextNode(Node node) {
    if (node == null) {
        return null;
    }/*from  ww w  .  j  av  a 2  s  .  c o  m*/

    if (node.getNodeType() == Node.TEXT_NODE && !node.getNodeValue().trim().isEmpty()) {
        return node;
    }
    Node childResult = getFirstTextNode(node.getFirstChild());
    return (childResult == null) ? getFirstTextNode(node.getNextSibling()) : childResult;
}

From source file:com.pleft.client.ckeditor.CKEditor.java

License:Open Source License

/**
 * Use to disable CKEditor's instance/*from   w w  w.j ava  2s  .  c o m*/
 * 
 * @param disabled
 */
public void setDisabled(boolean disabled) {

    if (this.disabled != disabled) {
        this.disabled = disabled;

        if (GWT.isScript() || enabledInHostedMode) {
            if (disabled) {
                ScrollPanel scroll = new ScrollPanel();
                disabledHTML = new HTML();
                disabledHTML.setStyleName("GWTCKEditor-Disabled");
                scroll.setWidget(disabledHTML);

                if (config.getWidth() != null)
                    scroll.setWidth(config.getWidth());

                scroll.setHeight(Integer.toString(config.getHeight()));

                String htmlString = new String();

                if (replaced) {
                    htmlString = getHTML();
                } else {
                    htmlString = waitingText;
                }

                DivElement divElement = DivElement.as(this.getElement().getFirstChildElement());
                Node node = divElement.getFirstChild();
                while (node != null) {
                    if (node.getNodeType() == Node.ELEMENT_NODE) {
                        Element element = Element.as(node);
                        if (element.getTagName().equalsIgnoreCase("textarea")) {
                            destroyInstance();
                            replaced = false;
                            divElement.removeChild(node);
                            ckEditorNode = node;
                        }
                    }
                    node = node.getNextSibling();
                }
                disabledHTML.setHTML(htmlString);
                div.appendChild(scroll.getElement());

            } else {
                if (ckEditorNode != null) {
                    DivElement divElement = DivElement.as(this.getElement().getFirstChildElement());
                    Node node = divElement.getFirstChild();
                    while (node != null) {
                        if (node.getNodeType() == Node.ELEMENT_NODE) {
                            Element element = Element.as(node);
                            if (element.getTagName().equalsIgnoreCase("div")) {
                                divElement.removeChild(node);

                            }
                        }
                        node = node.getNextSibling();
                    }
                    div.appendChild(baseTextArea);
                    initInstance();

                }
            }
        } else {
            textArea.setEnabled(disabled);
        }
    }

}

From source file:de.catma.ui.client.ui.tagger.editor.LeafFinder.java

License:Open Source License

private Node ascentRight(Node node) {
    if (node != null) {
        Node sibling = node.getNextSibling();
        if (sibling == null) {
            return ascentRight(node.getParentNode());
        } else {/*ww  w  . ja va  2 s  .co m*/
            return sibling;
        }
    }
    return null;
}

From source file:info.magnolia.ui.vaadin.gwt.client.layout.thumbnaillayout.widget.ThumbnailsSizeKeeper.java

License:Open Source License

private void doUpdateAllThumbnailsSize(int width, int height) {
    Node element = thumbnailParent.getFirstChildElement();
    while (element != null) {
        doSetThumbnailSize(width, height, Element.as(element));
        element = element.getNextSibling();
    }// www. j a  va 2 s .  co  m
}

From source file:org.chromium.distiller.PageParameterParser.java

License:Open Source License

/**
 * Finds and adds the leaf node(s) closest to the given start node.
 * This recurses and keeps finding and, if necessary, adding the numeric text of valid nodes,
 * collecting the PageParamInfo.PageInfo's for the current adjacency group.
 * For backward search, i.e. nodes before start node, search terminates (i.e. recursion stops)
 * once a text node or anchor is encountered.  If the text node contains numeric text, it's
 * added to the current adjacency group.  Otherwise, a new group is created to break the
 * adjacency.// w w  w .  ja  v  a 2 s.c  o m
 * For forward search, i.e. nodes after start node, search continues (i.e. recursion continues)
 * until a text node or anchor with non-numeric text is encountered.  In the process, text nodes
 * and anchors with numeric text are added to the current adjacency group.  When a non-numeric
 * text node or anchor is encountered, a new group is started to break the adjacency, and search
 * ends.
 *
 * @return true to continue search, false to stop.
 *
 * @param start node to work on.
 * @param checkStart true to check start node.  Otherwise, the previous or next sibling of the
 * start node is checked.
 * @param backward true to search backward (i.e. nodes before start node), false to search
 * forward (i.e. nodes after start node).
 * @param baseAnchor created for the current document, only needed for forward search.
 */
private boolean findAndAddClosestValidLeafNodes(Node start, boolean checkStart, boolean backward,
        AnchorElement baseAnchor) {
    Node node = checkStart ? start : (backward ? start.getPreviousSibling() : start.getNextSibling());
    if (node == null) { // No sibling, try parent.
        node = start.getParentNode();
        if (sInvalidParentWrapper == null) {
            sInvalidParentWrapper = RegExp.compile("(BODY)|(HTML)");
        }
        if (sInvalidParentWrapper.test(node.getNodeName()))
            return false;
        return findAndAddClosestValidLeafNodes(node, false, backward, baseAnchor);
    }

    checkStart = false;
    switch (node.getNodeType()) {
    case Node.TEXT_NODE:
        String text = node.getNodeValue();
        // Text must contain words.
        if (text.isEmpty() || StringUtil.countWords(text) == 0)
            break;
        boolean added = addNonLinkTextIfValid(node.getNodeValue());
        // For backward search, we're done regardless if text was added.
        // For forward search, we're done only if text was invalid, otherwise continue.
        if (backward || !added)
            return false;
        break;

    case Node.ELEMENT_NODE:
        Element e = Element.as(node);
        if (e.hasTagName("A")) {
            // For backward search, we're done because we've already processed the anchor.
            if (backward)
                return false;
            // For forward search, we're done only if link was invalid, otherwise continue.
            mNumForwardLinksProcessed++;
            if (!addLinkIfValid(AnchorElement.as(e), baseAnchor))
                return false;
            break;
        }
        // Intentionally fall through.

    default:
        // Check children nodes.
        if (!node.hasChildNodes())
            break;
        checkStart = true; // We want to check the child node.
        if (backward) {
            // Start the backward search with the rightmost child i.e. last and closest to
            // given node.
            node = node.getLastChild();
        } else {
            // Start the forward search with the leftmost child i.e. first and closest to
            // given node.
            node = node.getFirstChild();
        }
        break;
    }

    return findAndAddClosestValidLeafNodes(node, checkStart, backward, baseAnchor);
}