Example usage for com.google.gwt.dom.client NodeList getLength

List of usage examples for com.google.gwt.dom.client NodeList getLength

Introduction

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

Prototype

public int getLength() 

Source Link

Usage

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

License:Apache License

private List<Element> getElementsToRemove(NodeList<Element> nodes, String className) {
    List<Element> elementsToRemove = new ArrayList<Element>();
    for (int i = 0; i < nodes.getLength(); ++i) {
        Element element = nodes.getItem(i);
        CSSClassManager manager = new CSSClassManager(element);
        if (manager.isClassPresent(className)) {
            elementsToRemove.add(element);
        }/* w w w. jav  a 2  s . com*/
    }
    return elementsToRemove;
}

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

License:Apache License

public void testStraight() {
    createDocument();/*www  .  j a  v a2s .c  om*/
    Element bNode = RootPanel.getBodyElement().getElementsByTagName("b").getItem(0);
    assertNotNull(bNode);

    AnnoteaDecoratorVisitor processor = new AnnoteaDecoratorVisitor(bNode, 8, 13, getDefaultAnnotation(), null);
    Visitor visitor = new Visitor(processor);
    visitor.process(bNode);
    assertNotNull(bNode);

    NodeList list = bNode.getChildNodes();
    SpanElement span = SpanElement.as(bNode.getParentElement());
    assertEquals(3, list.getLength());
    assertEquals(span.getInnerHTML(),
            "<b>Nuxeo EP 5 - <span class=\"decorate decorate0\">Nuxeo An</span>notation</b>");

    processor = new AnnoteaDecoratorVisitor(bNode, 5, 23, getDefaultAnnotation(), null);
    visitor = new Visitor(processor);
    visitor.process(bNode);
    assertEquals(5, bNode.getChildNodes().getLength());
    assertEquals(span.getInnerHTML(),
            "<b>Nuxeo EP 5 - <span class=\"decorate decorate0\">Nuxeo An</span>no<span class=\"decorate decorate0\">tatio</span>n</b>");
}

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

License:Apache License

public void testReverse() {
    createDocument();/*from www  . ja  v a  2s .c  o m*/
    Element bNode = RootPanel.getBodyElement().getElementsByTagName("b").getItem(0);
    assertNotNull(bNode);

    AnnoteaDecoratorVisitor processor = new AnnoteaDecoratorVisitor(bNode, 5, 23, getDefaultAnnotation(), null);
    Visitor visitor = new Visitor(processor);
    visitor.process(bNode);
    assertNotNull(bNode);

    NodeList list = bNode.getChildNodes();
    SpanElement span = SpanElement.as(bNode.getParentElement());
    assertEquals(3, list.getLength());
    assertEquals(span.getInnerHTML(),
            "<b>Nuxeo EP 5 - Nuxeo Anno<span class=\"decorate decorate0\">tatio</span>n</b>");

    processor = new AnnoteaDecoratorVisitor(bNode, 8, 13, getDefaultAnnotation(), null);
    visitor = new Visitor(processor);
    visitor.process(bNode);
    assertEquals(5, bNode.getChildNodes().getLength());
    assertEquals(span.getInnerHTML(),
            "<b>Nuxeo EP 5 - <span class=\"decorate decorate0\">Nuxeo An</span>no<span class=\"decorate decorate0\">tatio</span>n</b>");
}

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

License:Apache License

public void testMultiLine() {
    createDocument();//from  w ww.  j a  va 2  s  .c o  m
    Element bNode = RootPanel.getBodyElement().getElementsByTagName("b").getItem(0);
    assertNotNull(bNode);

    AnnoteaDecoratorVisitor processor = new AnnoteaDecoratorVisitor(bNode, 48, 13, getDefaultAnnotation(),
            null);
    Visitor visitor = new Visitor(processor);
    visitor.process(bNode.getOwnerDocument());
    NodeList list = bNode.getChildNodes();
    assertEquals(2, list.getLength());

    DivElement div = DivElement.as(RootPanel.getBodyElement().getElementsByTagName("div").getItem(0));
    @SuppressWarnings("unused")
    String testString = div.getInnerHTML();
    assertTrue(div.getInnerHTML().contains(parsedResult));
}

From source file:org.opencms.acacia.client.entity.CmsEntityBackend.java

License:Open Source License

/**
 * Returns a list of DOM elements matching the given selector.<p>
 *
 * @param selector the CSS selector//from   www  .  j  a v  a2s  . com
 * @param context the context element
 *
 * @return the matching elements
 */
protected List<Element> select(String selector, Element context) {

    NodeList<Element> elements = CmsDomUtil.querySelectorAll(selector, context);
    List<Element> result = new ArrayList<Element>();
    for (int i = 0; i < elements.getLength(); i++) {
        result.add(elements.getItem(i));
    }
    return result;
}

From source file:org.opencms.acacia.client.widgets.complex.CmsDataViewValueAccessor.java

License:Open Source License

/**
 * Replaces the value in the editor with a list of other values.<p>
 *
 * @param replacementValues the list of replacement values
 *///from ww w  .  j  a va 2s  .  c o m
public void replaceValue(List<CmsDataViewValue> replacementValues) {

    CmsAttributeHandler handler = (CmsAttributeHandler) m_handler;
    Element parent = CmsDomUtil
            .getAncestor(m_widget.getElement(), I_CmsLayoutBundle.INSTANCE.form().attributeValue())
            .getParentElement();
    NodeList<Node> siblings = parent.getChildNodes();
    for (int j = 0; j < siblings.getLength(); j++) {
        Node node = siblings.getItem(j);
        if (node instanceof Element) {
            Element elem = (Element) node;
            if (elem.isOrHasChild(m_widget.getElement())) {
                m_index = j;
                break;
            }
        }
    }
    Panel container = handler.removeAttributeValueAndReturnPrevParent(m_index, true);
    int i = m_index;
    for (CmsDataViewValue value : replacementValues) {
        CmsEntity entity = CmsEntityBackend.getInstance().createEntity(null, m_entity.getTypeName());

        writeValueToEntity(value, entity);

        // handler.addNewAttributeValue(entity);
        handler.insertNewAttributeValue(entity, i, container);
        i += 1;
    }

    handler.updateButtonVisisbility();
}

From source file:org.opencms.ade.containerpage.client.ui.CmsContainerPageElementPanel.java

License:Open Source License

/**
 * Returns if the option bar position collides with any iframe child elements.<p>
 * //from   w w  w  . j a va2  s .c  om
 * @return <code>true</code> if there are iframe child elements located no less than 25px below the upper edge of the element
 */
private boolean isOptionbarIFrameCollision() {

    if (RootPanel.getBodyElement().isOrHasChild(getElement())) {
        int elementTop = getElement().getAbsoluteTop();
        NodeList<Element> frames = getElement().getElementsByTagName(CmsDomUtil.Tag.iframe.name());
        for (int i = 0; i < frames.getLength(); i++) {

            if ((frames.getItem(i).getAbsoluteTop() - elementTop) < 25) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.opencms.ade.contenteditor.client.CmsContentEditor.java

License:Open Source License

/**
 * Returns if the given element or it's descendants are inline editable.<p>
 *
 * @param element the element/* w  ww.  ja  va 2 s.  com*/
 *
 * @return <code>true</code> if the element has editable descendants
 */
public static boolean hasEditable(Element element) {

    NodeList<Element> children = CmsDomUtil.querySelectorAll("[property^=\"opencms://\"]", element);
    return (children != null) && (children.getLength() > 0);
}

From source file:org.opencms.ade.contenteditor.client.CmsContentEditor.java

License:Open Source License

/**
 * Replaces the id's within about attributes of the given element and all it's children.<p>
 *
 * @param element the element/*ww  w  . j  a  v  a2 s  .com*/
 * @param oldId the old id
 * @param newId the new id
 */
public static void replaceResourceIds(Element element, String oldId, String newId) {

    NodeList<Element> children = CmsDomUtil
            .querySelectorAll("[property^=\"opencms://\"][about*=\"" + oldId + "\"]", element);
    if (children.getLength() > 0) {
        for (int i = 0; i < children.getLength(); i++) {
            Element child = children.getItem(i);
            String about = child.getAttribute("about");
            about = about.replace(oldId, newId);
            child.setAttribute("about", about);
        }
    }
}

From source file:org.opencms.ade.contenteditor.client.CmsContentEditor.java

License:Open Source License

/**
 * Sets all annotated child elements editable.<p>
 *
 * @param element the element//from   ww w  .ja v  a  2 s  .  c  om
 * @param serverId the editable resource structure id
 * @param editable <code>true</code> to enable editing
 *
 * @return <code>true</code> if the element had editable elements
 */
public static boolean setEditable(Element element, String serverId, boolean editable) {

    I_CmsLayoutBundle.INSTANCE.editorCss().ensureInjected();
    NodeList<Element> children = CmsDomUtil
            .querySelectorAll("[property^=\"opencms://\"][about*=\"" + serverId + "\"]", element);
    if (children.getLength() > 0) {
        for (int i = 0; i < children.getLength(); i++) {
            Element child = children.getItem(i);
            if (editable) {
                child.addClassName(I_CmsLayoutBundle.INSTANCE.editorCss().inlineEditable());
            } else {
                child.removeClassName(I_CmsLayoutBundle.INSTANCE.editorCss().inlineEditable());
            }
        }
        return true;
    }
    return false;
}