Example usage for com.google.gwt.dom.client Element getPreviousSiblingElement

List of usage examples for com.google.gwt.dom.client Element getPreviousSiblingElement

Introduction

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

Prototype

@Override
    public Element getPreviousSiblingElement() 

Source Link

Usage

From source file:com.arcbees.gquery.elastic.client.ElasticImpl.java

License:Apache License

private void bind() {
    resizeHandlerRegistration = Window.addResizeHandler(new ResizeHandler() {
        @Override//from   www.ja  v a  2 s .  c  o  m
        public void onResize(ResizeEvent event) {
            if (options.isAutoResize()) {
                layout();
            }
        }
    });

    if (MutationObserver.isSupported()) {
        mutationObserver = new MutationObserver(new DomMutationCallback() {
            @Override
            public void onNodesRemoved(JsArray<Node> removedNodes) {
                onItemsRemoved();
            }

            @Override
            public void onNodesInserted(JsArray<Node> addedNodes, Node nextSibling) {
                onItemsInserted(toElementList(addedNodes));
            }

            @Override
            public void onNodesAppended(JsArray<Node> addedNodes) {
                onItemsAppended(toElementList(addedNodes));
            }
        });

        mutationObserver.observe(container);
    } else {
        // try old api with DomMutationEvent
        $(container).on("DOMNodeInserted", new Function() {
            @Override
            public boolean f(Event event) {
                Node node = event.getEventTarget().cast();

                if (node.getNodeType() != Node.ELEMENT_NODE || node.getParentElement() != container) {
                    return false;
                }

                final Element element = node.cast();
                Element prevSibling = element.getPreviousSiblingElement();
                Element nextSibling = element.getNextSiblingElement();

                if (prevSibling != null && getStyleInfo(prevSibling) != null
                        && (nextSibling == null || getStyleInfo(nextSibling) == null)) {
                    onItemsAppended(new ArrayList<Element>() {
                        {
                            this.add(element);
                        }
                    });
                } else {
                    onItemsInserted(new ArrayList<Element>() {
                        {
                            this.add(element);
                        }
                    });
                }
                return false;
            }
        }).on("DOMNodeRemoved", new Function() {
            @Override
            public boolean f(Event event) {
                Node node = event.getEventTarget().cast();

                if (node.getNodeType() != Node.ELEMENT_NODE || node.getParentElement() != container) {
                    return false;
                }

                onItemsRemoved();
                return false;
            }
        });
    }
}

From source file:com.vaadin.client.componentlocator.LegacyLocatorStrategy.java

License:Apache License

/**
 * Generates a String locator using domChild[x] parts for the element
 * relative to the baseElement.//from  ww w. j av a  2  s.  c  om
 * 
 * @param element
 *            The target element
 * @param baseElement
 *            The starting point for the locator. The generated path is
 *            relative to this element.
 * @return A String locator that can be used to locate the target element
 *         using {@link #getElementByDOMPath(Element, String)} or null if
 *         the locator String cannot be created.
 */
private String getDOMPathForElement(Element element, Element baseElement) {
    Element e = element;
    String path = "";
    while (true) {
        int childIndex = -1;
        Element siblingIterator = e;
        while (siblingIterator != null) {
            childIndex++;
            siblingIterator = siblingIterator.getPreviousSiblingElement().cast();
        }

        path = PARENTCHILD_SEPARATOR + "domChild[" + childIndex + "]" + path;

        JavaScriptObject parent = e.getParentElement();
        if (parent == null) {
            return null;
        }
        // The parent check is a work around for Firefox 15 which fails to
        // compare elements properly (#9534)
        if (parent == baseElement) {
            break;
        }

        e = parent.cast();
    }

    return path;
}