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:com.extjs.gxt.ui.client.widget.Shim.java

License:sencha.com license

protected void shim(NodeList<Element> elements) {
    for (int i = 0; i < elements.getLength(); i++) {
        Element e = elements.getItem(i);
        Rectangle bounds = El.fly(e).getBounds(true);
        if (bounds.height > 0 && bounds.width > 0 && El.fly(e).isVisible()) {
            shims.add(createShim(e, bounds.x, bounds.y, bounds.width, bounds.height));
        }//  w w w . j a  v  a  2s  .c o m
    }
}

From source file:com.extjs.gxt.ui.client.widget.tree.TreeItem.java

License:Open Source License

protected void renderChildren() {
    int count = getItemCount();
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < count; i++) {
        TreeItem child = getItem(i);/*from   w  w w .  ja va2 s  .  c  o m*/
        Joint joint = child.calculateJoint();
        sb.append(child.getUI().getTemplate(child.getId(), child.getText(), child.calculateIconStyle(),
                joint.value(), getDepth()));
    }

    getContainer().setInnerHTML(sb.toString());

    NodeList<Element> elems = getContainer().getChildNodes().cast();
    for (int i = 0, len = elems.getLength(); i < len; i++) {
        TreeItem child = getItem(i);
        child.setElement(elems.getItem(i));
    }
    childrenRendered = true;
}

From source file:com.google.gwt.site.demo.AbstractDemos.java

License:Apache License

@Override
public void onContentLoaded() {
    GQuery demos = $("//div[@id='content']//div[starts-with(@id, '" + prefix + "')]");

    NodeList<Element> nodeList = demos.get();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Element item = nodeList.getItem(i);

        Widget demo = getDemoToLoad(item.getId().replace(prefix, ""));
        if (demo != null) {
            HTMLPanel panel = HTMLPanel.wrap(item);
            panel.add(demo);/* w ww  .  j  a  v  a  2  s. c o m*/
        }
    }
}

From source file:com.google.livingstories.client.contentmanager.ObjectElementProofreader.java

License:Apache License

public String proofread(String incomingHtml) {
    HTML asHTML = new HTML(incomingHtml);
    Element element = asHTML.getElement();
    boolean changed = false;

    NodeList<Element> embeds = element.getElementsByTagName("embed");

    // since we will be removing embeds, iterate from len-1 to 0:
    for (int i = embeds.getLength() - 1; i >= 0; i--) {
        changed = true;//from  www.ja  v  a 2  s  .  com
        Element embed = embeds.getItem(i);
        Element embedParent = embed.getParentElement();
        if (embedParent.getTagName().equalsIgnoreCase("object")) {
            // The wrapped object idiom: shouldn't be necessary at all.
            embedParent.removeChild(embed);
        } else {
            Element objectElement = document.createObjectElement();

            for (String attribute : EMBED_ATTRIBUTES) {
                String value = embed.getAttribute(attribute);

                if (!value.isEmpty()) {
                    TranslatedAttributeRecord record = TranslatedAttributeRecord
                            .getFromEmbedAttribute(attribute);

                    if (record == null) {
                        addParam(objectElement, attribute, value);
                    } else {
                        record.setAttributeForObject(objectElement, value);
                        if (record == TranslatedAttributeRecord.SRC) {
                            addParam(objectElement, "movie", value);
                        }
                    }
                }
            }
            embedParent.replaceChild(objectElement /* new */, embed /* old */);
        }
    }

    // now iterate over objects, looking for places where the "data" value is not replicated as
    // a "movie" param.
    NodeList<Element> objectElements = element.getElementsByTagName("object");

    // again, iterate from len-1 to 0:
    for (int i = objectElements.getLength() - 1; i >= 0; i--) {
        Element objectElement = objectElements.getItem(i);
        Element objectParent = objectElement.getParentElement();

        if (objectParent.getTagName().equalsIgnoreCase("object")) {
            // nested object idiom. Unnecessary.
            changed = true;
            objectParent.removeChild(objectElement);
        } else {
            boolean foundMovieParam = false;

            for (Element child = objectElement.getFirstChildElement(); !foundMovieParam
                    && child != null; child = child.getNextSiblingElement()) {
                foundMovieParam = child.getNodeName().equalsIgnoreCase("param")
                        && child.getAttribute("name").equalsIgnoreCase("movie");
            }

            if (!foundMovieParam) {
                // duplicate it from the data attribute of the object itself.
                changed = true;
                addParam(objectElement, "movie", objectElement.getAttribute("data"));
            }
        }
    }

    return (changed
            // so that we don't worry about embedded comment indicators in the original html:
            ? (element.getInnerHTML() + "\n<!--\n" + incomingHtml.replaceAll("-+", "-") + "\n-->\n")
            : null);
}

From source file:com.google.livingstories.client.lsp.ContentRenderer.java

License:Apache License

/**
 * Find the custom tags in the HTML and process them.
 */// w ww  .  j  a  va  2 s  .c o  m
private HTMLPanel processTagsInChunk(String chunk) {
    HTMLPanel contentPanel = new HTMLPanel(chunk);

    try {
        // Process each type of tag
        for (ContentTag tag : contentTags) {
            NodeList<Element> tagNodeList = contentPanel.getElement().getElementsByTagName(tag.getTagName());
            List<Element> tagElements = new ArrayList<Element>();
            for (int i = 0; i < tagNodeList.getLength(); i++) {
                // First iterate over the node list and copy all the elements into a new list. Can't 
                // iterate and modify them at the same time because the list changes dynamically.
                tagElements.add(tagNodeList.getItem(i));
            }

            for (Element tagElement : tagElements) {
                Widget widget = tag.createWidgetToReplaceTag(tagElement);

                if (widget != null) {
                    // To replace the existing tag with the widget created above, the HTMLPanel needs
                    // to have the id of the element being replaced. Since we can't expect users to assign
                    // unique ids in every tag, we do this here automatically.
                    String uniqueId = HTMLPanel.createUniqueId();
                    tagElement.setId(uniqueId);
                    contentPanel.addAndReplaceElement(widget, uniqueId);
                }
            }
        }
    } catch (Exception e) {
        // Just return the panel with the original content
    }

    return contentPanel;
}

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

License:Apache License

protected Widget getContent(AssetContentItem contentItem) {
    // Add the content
    HTML contentHTML = new HTML(contentItem.getContent());
    // So that lightbox centering in firefox works, enclose each sized <object>
    // with a div styled to exactly that size.
    NodeList<Element> objectElements = contentHTML.getElement().getElementsByTagName("object");
    Document document = Document.get();
    for (int i = 0, len = objectElements.getLength(); i < len; i++) {
        Element objectElement = objectElements.getItem(i);
        String width = objectElement.getAttribute("width");
        String height = objectElement.getAttribute("height");
        if (width.matches("[0-9]+%?") && height.matches("[0-9]+%?")) {
            DivElement div = document.createDivElement();
            div.getStyle().setProperty("width", width + (width.endsWith("%") ? "" : "px"));
            div.getStyle().setProperty("height", height + (height.endsWith("%") ? "" : "px"));
            objectElement.getParentElement().replaceChild(div, objectElement);
            div.appendChild(objectElement);
        }//from  w w w.  j  a v a2 s .  c o  m
    }
    // In case there are images within the content, we should fire a PopupImageLoadedEvent
    // so that any popup window displaying this view has a chance to reposition itself.
    NodeList<Element> imageElements = contentHTML.getElement().getElementsByTagName("img");
    for (int i = 0; i < imageElements.getLength(); i++) {
        ImageElement image = imageElements.getItem(i).cast();
        addImageLoadHandler(image);
    }
    return contentHTML;
}

From source file:com.google.livingstories.client.ui.AutoHidePopupPanel.java

License:Apache License

@Override
public void hide(boolean autoClosed) {
    if (skipHide) {
        skipHide = false;//w  w w .  ja va2 s. com
        return;
    }
    if (getWidget() != null) {
        // clear the "data" attribute of all HTML objects within the widget, so that no playback
        // persists.
        NodeList<Element> objects = getWidget().getElement().getElementsByTagName("object");
        for (int i = 0, len = objects.getLength(); i < len; i++) {
            scrubber.scrub(objects.getItem(i));
            scrubbed = true;
            // in point of fact, we're safe in FF, but this indicates an implementation problem where
            // a popup is reused that shouldn't be, and we want to catch this on _all_ browsers.
        }
    }
    super.hide(autoClosed);
}

From source file:com.google.livingstories.client.util.dom.GwtNodeAdapter.java

License:Apache License

@Override
public List<NodeAdapter> getChildNodes() {
    NodeList<Node> childNodes = node.getChildNodes();
    List<NodeAdapter> nodes = new ArrayList<NodeAdapter>(childNodes.getLength());
    for (int i = 0; i < childNodes.getLength(); i++) {
        nodes.add(new GwtNodeAdapter(childNodes.getItem(i)));
    }//  w  ww.  j a va2 s.  c  o  m
    return nodes;
}

From source file:com.google.speedtracer.client.SourceViewer.java

License:Apache License

/**
 * Returns the cell that contains the line contents for a row.
 *///from w ww  .j a v a 2 s.c  om
private TableCellElement getRowContentCell(TableRowElement row) {
    NodeList<TableCellElement> cells = row.getElementsByTagName("td").cast();

    for (int i = 0, n = cells.getLength(); i < n; i++) {
        TableCellElement cell = cells.getItem(i);
        if (cell.getClassName().indexOf(LINE_CONTENT) >= 0) {
            return cell;
        }
    }

    return null;
}

From source file:com.googlecode.mgwt.css.client.updater.CssUpdater.java

License:Apache License

private Element getHead() {
    NodeList<Element> nodeList = Document.get().getElementsByTagName("head");
    if (nodeList.getLength() != 1) {
        throw new RuntimeException("can not find head element, does your html include a head section?");
    }// w w w.j a  v a 2 s. c  o m
    return nodeList.getItem(0);
}