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.gwtwidgets.client.stream.HtmlStreamReader.java

License:Apache License

private Message checkForEOF(Document document) {
    NodeList<Element> eSpans = document.getElementsByTagName("span");
    if (eSpans.getLength() == 0)
        return null;
    Element eSpan = eSpans.getItem(0);
    if ("EOF".equals(eSpan.getInnerText())) {
        Message message = new Message();
        message.setEOF(true);/*w  w w . j  a  v a2  s.c  o m*/
        return message;
    }
    return null;
}

From source file:org.gwtwidgets.client.stream.HtmlStreamReader.java

License:Apache License

protected Message readNextMessage() {
    Document document = getFrameContents(frame);
    if (null == document)
        return null;
    NodeList<Element> elements = document.getElementsByTagName("div");
    if (elements.getLength() == 0) {
        return checkForEOF(document);
    }//from  w  w w .j  a  v  a  2  s  . c o  m
    Element eDiv = elements.getItem(0);
    eDiv.getParentElement().removeChild(eDiv);
    Message message = decodeMessage(eDiv);
    lastMessageId = message.getSerialNumber();
    return message;
}

From source file:org.jahia.ajax.gwt.client.widget.content.ThumbsListView.java

License:Open Source License

public void setSize(int thumbnailSize) {
    NodeList<Element> imageThumbNails = DomQuery.select("#images-view .thumb");
    for (int i = 0; i < imageThumbNails.getLength(); i++) {
        Element currentThumbnail = imageThumbNails.getItem(i);
        currentThumbnail.getStyle().setWidth(thumbnailSize, Style.Unit.PX);
        currentThumbnail.getStyle().setHeight(thumbnailSize, Style.Unit.PX);
    }/*from w w  w. j  a v  a 2s.c  om*/
}

From source file:org.jahia.ajax.gwt.client.widget.edit.mainarea.MainModule.java

License:Open Source License

private void refreshImages(Element element) {
    NodeList<com.google.gwt.dom.client.Element> elementsByTagName = element.getElementsByTagName("img");
    if (elementsByTagName == null) {
        return;//from w w  w  .ja  v a  2s.c o  m
    }
    String base = JahiaGWTParameters.getContextPath() + "/files/default/";
    String suffix = "tst=" + System.currentTimeMillis();
    for (int i = 0; i < elementsByTagName.getLength(); i++) {
        com.google.gwt.dom.client.Element el = elementsByTagName.getItem(i);
        String url = el.getAttribute("src");
        if (url != null && url.startsWith(base)) {
            el.setAttribute("src", url + (url.indexOf('?') == -1 ? "?" : "&") + suffix);
        }
    }
}

From source file:org.jahia.ajax.gwt.client.widget.edit.mainarea.MainModule.java

License:Open Source License

private void refreshCSS(Element element) {
    NodeList<com.google.gwt.dom.client.Element> elementsByTagName = element.getElementsByTagName("link");
    if (elementsByTagName == null) {
        return;//from   w ww. j ava2  s .  c o  m
    }
    String base = JahiaGWTParameters.getContextPath() + "/modules/";
    String suffix = "tst=" + System.currentTimeMillis();
    for (int i = 0; i < elementsByTagName.getLength(); i++) {
        com.google.gwt.dom.client.Element el = elementsByTagName.getItem(i);
        String url = el.getAttribute("href");
        String type = el.getAttribute("type");
        if (type != null && type.equals("text/css") && url != null && url.startsWith(base)) {
            el.setAttribute("href", url + (url.indexOf('?') == -1 ? "?" : "&") + suffix);
        }
    }
}

From source file:org.jahia.ajax.gwt.client.widget.edit.mainarea.MainModule.java

License:Open Source License

private void refreshScripts(Element element) {
    NodeList<com.google.gwt.dom.client.Element> elementsByTagName = element.getElementsByTagName("script");
    if (elementsByTagName == null) {
        return;//from w  w  w.j  a va  2 s .co m
    }
    String base = JahiaGWTParameters.getContextPath() + "/modules/";
    String suffix = "tst=" + System.currentTimeMillis();
    for (int i = 0; i < elementsByTagName.getLength(); i++) {
        com.google.gwt.dom.client.Element el = elementsByTagName.getItem(i);
        String url = el.getAttribute("src");
        String type = el.getAttribute("type");
        if (type != null && type.equals("text/javascript") && url != null && url.startsWith(base)) {
            el.setAttribute("src", url + (url.indexOf('?') == -1 ? "?" : "&") + suffix);
        }
    }
}

From source file:org.jahia.ajax.gwt.client.widget.edit.mainarea.MainModule.java

License:Open Source License

private void parseFrameContent(boolean forceImageRefresh, boolean forceCssRefresh,
        boolean forceJavascriptRefresh) {
    try {//w w w.ja  va  2s .  com
        frameError = null;
        final IFrameElement iframe = IFrameElement.as(frame.getElement());
        Document contentDocument = iframe.getContentDocument();
        Element body = (Element) contentDocument.getElementsByTagName("body").getItem(0);
        Element head = (Element) contentDocument.getElementsByTagName("head").getItem(0);
        setHashMarker(frame.getCurrentFrameUrl());
        if (forceImageRefresh) {
            refreshImages(body);
        }
        if (head != null) {
            if (forceCssRefresh) {
                refreshCSS(head);
            }
            if (forceJavascriptRefresh) {
                refreshScripts(head);
            }
        }
        Hover.getInstance().removeAll();
        List<Element> el = null;
        List<Element> elBody = null;
        if ("true".equals(body.getAttribute("jahia-parse-html"))) {
            Element innerElement = getInnerElement();
            elBody = ModuleHelper.getAllJahiaTypedElementsRec(body);
            if (body.equals(innerElement)) {
                el = elBody;
            } else {
                el = ModuleHelper.getAllJahiaTypedElementsRec(getInnerElement());
            }

        } else if (body.getAttribute("jahia-error-code") != null
                && !"".equals(body.getAttribute("jahia-error-code"))) {
            frameError = body.getAttribute("jahia-error-code");
        } else {
            NodeList<com.google.gwt.dom.client.Element> el1 = body.getElementsByTagName("div");
            int i = 0;
            Element e = null;
            while (i < el1.getLength()) {
                e = (Element) el1.getItem(i);
                if ("mainmodule".equals(e.getAttribute(ModuleHelper.JAHIA_TYPE))) {
                    el = Arrays.asList(e);
                    elBody = Arrays.asList(e);
                    break;
                }
                i++;
            }

        }
        if (contextMenu != null) {
            contextMenu.hide();
        }

        if (el != null && elBody != null) {
            ModuleHelper.tranformLinks((Element) contentDocument.getDocumentElement());
            ModuleHelper.initAllModules(MainModule.this, body, el, elBody, config);
            editLinker.getSidePanel().enable();
        } else {
            // if body empty, this is not a jahia page
            path = "";
            // clear side panel
            editLinker.getSidePanel().disable();
        }
        editLinker.getMainModule().unmask();
        needParseAfterLayout = true;
        layout();
    } catch (Exception e) {
        Log.error("Error in EditFrame: " + e.getMessage(), e);
    }
}

From source file:org.jboss.as.console.client.core.Header.java

License:Open Source License

public void highlight(String name) {
    toggleSubnavigation(name);/*from   ww  w. jav  a2s . c om*/

    com.google.gwt.user.client.Element target = linksPane.getElementById("header-links-ref");
    if (target != null) // standalone doesn't provide any top level links
    {
        NodeList<Node> childNodes = target.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node n = childNodes.getItem(i);
            if (Node.ELEMENT_NODE == n.getNodeType()) {
                Element element = (Element) n;
                if (element.getId().equals("header-" + name)) {
                    element.addClassName("header-link-selected");
                    element.setAttribute("aria-selected", "true");
                } else {
                    element.removeClassName("header-link-selected");
                    element.setAttribute("aria-selected", "false");
                }
            }
        }
    }

}

From source file:org.jboss.as.console.client.shared.homepage.ContentBox.java

License:Open Source License

private void setIconClassname(String styleName) {
    NodeList<Element> i = dp.getElement().getElementsByTagName("i");
    if (i.getLength() == 1) {
        Element iconElem = i.getItem(0);
        iconElem.setClassName(styleName);
    }/* w ww . j a v  a2 s  . c  o  m*/
}

From source file:org.jboss.errai.cdi.demo.stock.client.local.App.java

License:Apache License

/**
 * Handles a new tick from the server by updating the HTML UI.
 * <p>//from   ww w.  j ava2 s.c o m
 * This method doesn't do anything (it just returns immediately) until after
 * {@link #subscriptionCompleted(SubscriptionReply)} has been called.
 *
 * @param tick
 *          The tick that just happened
 */
public void tickHappened(@Observes Tick tick) {
    if (!registrationComplete)
        return;
    try {
        tickerLabel.setText("New tick at " + new Date() + ": " + tick);
    } catch (Exception e) {
        tickerLabel.setText(e.toString());
    }
    DivElement stockBoxDiv = getStockBoxDiv(tick);

    addTick(getChartData(stockBoxDiv), tick);

    // update the stock box with current tick data
    NodeList<Element> nl = stockBoxDiv.getElementsByTagName("span");
    for (int i = 0; i < nl.getLength(); i++) {
        Element el = nl.getItem(i);
        if (el.getClassName().contains("stockName")) {
            el.setInnerText(tick.getSymbol());
        } else if (el.getClassName().contains("bidAsk")) {
            el.setInnerText(tick.getFormattedPrice());
        } else if (el.getClassName().contains("change")) {
            el.setInnerText(tick.getFormattedChange());
            String strobeCssColor = tick.getChange().signum() >= 0 ? "rgb(40, 155, 40)" : "rgb(155, 40, 40)";
            strobe(el, strobeCssColor, "rgb(0, 0, 0)");
        } else if (el.getClassName().contains("time")) {
            DateTimeFormat format = DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_MEDIUM);
            el.setInnerText(format.format(tick.getTime()));
        }
    }

    // finally, update the chart
    double endTime = tick.getTime().getTime();
    double startTime = endTime - chartTimeSpan;
    redrawChart(stockBoxDiv, startTime, endTime);
}