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

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

Introduction

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

Prototype

public T getItem(int index) 

Source Link

Usage

From source file:com.vaadin.client.ui.ui.UIConnector.java

License:Apache License

/**
 * Finds a link tag for a style sheet with the given URL
 * //from   w  ww  .j  a  v  a  2  s .c om
 * @since 7.3
 * @param url
 *            the URL of the style sheet
 * @return the link tag or null if no matching link tag was found
 */
private LinkElement findStylesheetTag(String url) {
    NodeList<Element> linkTags = getHead().getElementsByTagName(LinkElement.TAG);
    for (int i = 0; i < linkTags.getLength(); i++) {
        final LinkElement link = LinkElement.as(linkTags.getItem(i));
        if ("stylesheet".equals(link.getRel()) && "text/css".equals(link.getType())
                && url.equals(link.getHref())) {
            return link;
        }
    }
    return null;
}

From source file:com.vaadin.client.ui.VContextMenu.java

License:Apache License

@Override
public String getSubPartName(com.google.gwt.user.client.Element subElement) {
    if (getElement().isOrHasChild(subElement)) {
        com.google.gwt.dom.client.Element e = subElement;
        {/*from  ww  w.  ja va2  s  . c  om*/
            while (e != null && !e.getTagName().toLowerCase().equals("tr")) {
                e = e.getParentElement();
                // ApplicationConnection.getConsole().log("Found row");
            }
        }
        com.google.gwt.dom.client.TableSectionElement parentElement = (TableSectionElement) e
                .getParentElement();
        NodeList<TableRowElement> rows = parentElement.getRows();
        for (int i = 0; i < rows.getLength(); i++) {
            if (rows.getItem(i) == e) {
                // ApplicationConnection.getConsole().log(
                // "Found index for row" + 1);
                return "option" + i;
            }
        }
        return null;
    } else {
        return null;
    }
}

From source file:com.vaadin.client.ui.VCustomLayout.java

License:Apache License

/**
 * Img elements needs some special handling in custom layout. Img elements
 * will get their onload events sunk. This way custom layout can notify
 * parent about possible size change./*w w  w  . j  a v  a  2  s .  com*/
 */
private void initImgElements() {
    NodeList<Element> nodeList = getElement().getElementsByTagName("IMG");
    for (int i = 0; i < nodeList.getLength(); i++) {
        ImageElement img = ImageElement.as(nodeList.getItem(i));
        DOM.sinkEvents(img, Event.ONLOAD);
    }
}

From source file:com.vaadin.client.ui.VMediaBase.java

License:Apache License

public void removeAllSources() {
    NodeList<com.google.gwt.dom.client.Element> l = media.getElementsByTagName(SourceElement.TAG);
    for (int i = l.getLength() - 1; i >= 0; i--) {
        media.removeChild(l.getItem(i));
    }//  www. j  a v a 2s. c  o  m

}

From source file:com.vaadin.client.ui.window.WindowConnector.java

License:Apache License

private Node cloneNodeFilteringMedia(Node node) {
    if (node instanceof Element) {
        Element old = (Element) node;
        if ("audio".equalsIgnoreCase(old.getTagName()) || "video".equalsIgnoreCase(old.getTagName())) {
            if (!old.hasAttribute("controls") && "audio".equalsIgnoreCase(old.getTagName())) {
                return null; // nothing to animate, so we won't add this to
                             // the clone
            }/*from  www  . jav a  2s  .c  o  m*/
            Element newEl = DOM.createElement(old.getTagName());
            if (old.hasAttribute("controls")) {
                newEl.setAttribute("controls", old.getAttribute("controls"));
            }
            if (old.hasAttribute("style")) {
                newEl.setAttribute("style", old.getAttribute("style"));
            }
            if (old.hasAttribute("class")) {
                newEl.setAttribute("class", old.getAttribute("class"));
            }
            return newEl;
        }
    }
    Node res = node.cloneNode(false);
    if (node.hasChildNodes()) {
        NodeList<Node> nl = node.getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            Node clone = cloneNodeFilteringMedia(nl.getItem(i));
            if (clone != null) {
                res.appendChild(clone);
            }
        }
    }
    return res;
}

From source file:com.vaadin.client.WidgetUtil.java

License:Apache License

public static void sinkOnloadForImages(Element element) {
    NodeList<com.google.gwt.dom.client.Element> imgElements = element.getElementsByTagName("img");
    for (int i = 0; i < imgElements.getLength(); i++) {
        DOM.sinkEvents(imgElements.getItem(i), Event.ONLOAD);
    }/*from   w ww.j a v  a  2  s  .co  m*/

}

From source file:com.vaadin.terminal.gwt.client.ui.TouchScrollDelegate.java

License:Open Source License

/**
 * Detects if a touch happens on a predefined element and the element has
 * something to scroll.//from   w w w . j a va  2s .  c o  m
 * 
 * @param touch
 * @return
 */
private boolean detectScrolledElement(Touch touch) {
    Element target = touch.getTarget().cast();
    for (Element el : scrollableElements) {
        if (el.isOrHasChild(target) && el.getScrollHeight() > el.getClientHeight()) {
            scrolledElement = el;
            NodeList<Node> childNodes = scrolledElement.getChildNodes();
            layers = new ArrayList<Element>();
            for (int i = 0; i < childNodes.getLength(); i++) {
                Node item = childNodes.getItem(i);
                if (item.getNodeType() == Node.ELEMENT_NODE) {
                    layers.add((Element) item);
                }
            }
            return true;

        }
    }
    return false;
}

From source file:com.vaadin.terminal.gwt.client.ui.VContextMenu.java

License:Open Source License

public String getSubPartName(Element subElement) {
    if (getElement().isOrHasChild(subElement)) {
        com.google.gwt.dom.client.Element e = subElement;
        {/*from  ww  w . ja v a2  s  . co m*/
            while (e != null && !e.getTagName().toLowerCase().equals("tr")) {
                e = e.getParentElement();
                // ApplicationConnection.getConsole().log("Found row");
            }
        }
        com.google.gwt.dom.client.TableSectionElement parentElement = (TableSectionElement) e
                .getParentElement();
        NodeList<TableRowElement> rows = parentElement.getRows();
        for (int i = 0; i < rows.getLength(); i++) {
            if (rows.getItem(i) == e) {
                // ApplicationConnection.getConsole().log(
                // "Found index for row" + 1);
                return "option" + i;
            }
        }
        return null;
    } else {
        return null;
    }
}

From source file:com.vaadin.terminal.gwt.client.ui.VCustomLayout.java

License:Open Source License

/**
 * Img elements needs some special handling in custom layout. Img elements
 * will get their onload events sunk. This way custom layout can notify
 * parent about possible size change.//  w  w w  . ja v  a2  s. c o m
 */
private void initImgElements() {
    NodeList<com.google.gwt.dom.client.Element> nodeList = getElement().getElementsByTagName("IMG");
    for (int i = 0; i < nodeList.getLength(); i++) {
        com.google.gwt.dom.client.ImageElement img = (ImageElement) nodeList.getItem(i);
        DOM.sinkEvents((Element) img.cast(), Event.ONLOAD);
    }
}

From source file:com.vaadin.terminal.gwt.client.ui.VEmbedded.java

License:Open Source License

public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
    if (client.updateComponent(this, uidl, true)) {
        return;/*from w ww.ja va2 s  . co  m*/
    }
    this.client = client;

    boolean clearBrowserElement = true;

    clickEventHandler.handleEventHandlerRegistration(client);

    if (uidl.hasAttribute("type")) {
        type = uidl.getStringAttribute("type");
        if (type.equals("image")) {
            addStyleName(CLASSNAME + "-image");
            Element el = null;
            boolean created = false;
            NodeList<Node> nodes = getElement().getChildNodes();
            if (nodes != null && nodes.getLength() == 1) {
                Node n = nodes.getItem(0);
                if (n.getNodeType() == Node.ELEMENT_NODE) {
                    Element e = (Element) n;
                    if (e.getTagName().equals("IMG")) {
                        el = e;
                    }
                }
            }
            if (el == null) {
                setHTML("");
                el = DOM.createImg();
                created = true;
                DOM.sinkEvents(el, Event.ONLOAD);
            }

            // Set attributes
            Style style = el.getStyle();
            String w = uidl.getStringAttribute("width");
            if (w != null) {
                style.setProperty("width", w);
            } else {
                style.setProperty("width", "");
            }
            String h = uidl.getStringAttribute("height");
            if (h != null) {
                style.setProperty("height", h);
            } else {
                style.setProperty("height", "");
            }
            DOM.setElementProperty(el, "src", getSrc(uidl, client));

            if (created) {
                // insert in dom late
                getElement().appendChild(el);
            }

            /*
             * Sink tooltip events so tooltip is displayed when hovering the
             * image.
             */
            sinkEvents(VTooltip.TOOLTIP_EVENTS);

        } else if (type.equals("browser")) {
            addStyleName(CLASSNAME + "-browser");
            if (browserElement == null) {
                setHTML("<iframe width=\"100%\" height=\"100%\" frameborder=\"0\""
                        + " allowTransparency=\"true\" src=\"\"" + " name=\"" + uidl.getId() + "\"></iframe>");
                browserElement = DOM.getFirstChild(getElement());
            }
            DOM.setElementAttribute(browserElement, "src", getSrc(uidl, client));
            clearBrowserElement = false;
        } else {
            VConsole.log("Unknown Embedded type '" + type + "'");
        }
    } else if (uidl.hasAttribute("mimetype")) {
        final String mime = uidl.getStringAttribute("mimetype");
        if (mime.equals("application/x-shockwave-flash")) {
            // Handle embedding of Flash
            addStyleName(CLASSNAME + "-flash");
            setHTML(createFlashEmbed(uidl));

        } else if (mime.equals("image/svg+xml")) {
            addStyleName(CLASSNAME + "-svg");
            String data;
            Map<String, String> parameters = getParameters(uidl);
            if (parameters.get("data") == null) {
                data = getSrc(uidl, client);
            } else {
                data = "data:image/svg+xml," + parameters.get("data");
            }
            setHTML("");
            ObjectElement obj = Document.get().createObjectElement();
            obj.setType(mime);
            obj.setData(data);
            if (width != null) {
                obj.getStyle().setProperty("width", "100%");
            }
            if (height != null) {
                obj.getStyle().setProperty("height", "100%");
            }
            if (uidl.hasAttribute("classid")) {
                obj.setAttribute("classid", uidl.getStringAttribute("classid"));
            }
            if (uidl.hasAttribute("codebase")) {
                obj.setAttribute("codebase", uidl.getStringAttribute("codebase"));
            }
            if (uidl.hasAttribute("codetype")) {
                obj.setAttribute("codetype", uidl.getStringAttribute("codetype"));
            }
            if (uidl.hasAttribute("archive")) {
                obj.setAttribute("archive", uidl.getStringAttribute("archive"));
            }
            if (uidl.hasAttribute("standby")) {
                obj.setAttribute("standby", uidl.getStringAttribute("standby"));
            }
            getElement().appendChild(obj);

        } else {
            VConsole.log("Unknown Embedded mimetype '" + mime + "'");
        }
    } else {
        VConsole.log("Unknown Embedded; no type or mimetype attribute");
    }

    if (clearBrowserElement) {
        browserElement = null;
    }
}