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.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.//  w  w w  . ja  v  a 2 s  . 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;
        {/*w  ww. j  ava 2s  .  c  o 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./* ww  w  .  j  a v  a 2s.  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  ww w. j a  v a 2s .c om*/
    }
    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;
    }
}

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

License:Open Source License

private void sinkOnloadsForContainedImgs() {
    NodeList<Element> images = getElement().getElementsByTagName("img");
    for (int i = 0; i < images.getLength(); i++) {
        Element img = images.getItem(i);
        DOM.sinkEvents((com.google.gwt.user.client.Element) img, Event.ONLOAD);
    }/*from  www . jav a 2 s . com*/

}

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

License:Open Source License

/**
 * Creates an empty tabsheet panel./*from w  w w  .j  a va  2  s  .  c  o  m*/
 */
public VTabsheetPanel() {
    setElement(DOM.createDiv());
    sinkEvents(Event.TOUCHEVENTS);
    addDomHandler(new TouchStartHandler() {
        public void onTouchStart(TouchStartEvent event) {
            /*
             * All container elements needs to be scrollable by one finger.
             * Update the scrollable element list of touch delegate on each
             * touch start.
             */
            NodeList<Node> childNodes = getElement().getChildNodes();
            Element[] elements = new Element[childNodes.getLength()];
            for (int i = 0; i < elements.length; i++) {
                elements[i] = (Element) childNodes.getItem(i);
            }
            getTouchScrollDelegate().setElements(elements);
            getTouchScrollDelegate().onTouchStart(event);
        }
    }, TouchStartEvent.getType());
}

From source file:com.vaadin.terminal.gwt.client.Util.java

License:Open Source 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((Element) imgElements.getItem(i), Event.ONLOAD);
    }//ww  w . j  a  v a  2  s  . c  om

}

From source file:com.watopi.chosen.client.ChosenImpl.java

License:Open Source License

private void setDefaultValues() {
    clickTestAction = new Function() {
        @Override/*w w  w . j a va 2 s . c o  m*/
        public boolean f(Event e) {
            return testActiveClick(e);
        }
    };

    activateAction = new Function() {
        @Override
        public boolean f(Event e) {
            return activateField(e);
        }
    };

    activeField = false;
    mouseOnContainer = false;
    resultsShowing = false;

    NodeList<OptionElement> optionsList = selectElement.getOptions();
    allowSingleDeselect = options.isAllowSingleDeselect() && optionsList.getLength() > 0
            && "".equals(optionsList.getItem(0).getText());

    choices = 0;

    if (options.getResources() != null) {
        css = options.getResources().css();
    } else {
        css = GWT.<Resources>create(Resources.class).css();
    }

    // Force the injection the first time only 
    // If you want to use different css file for different GwtChosen component
    // please register your css files (css.ensureInject()) before the first call of the plugin
    if (!cssInjected) {
        StyleInjector.inject(css.getText(), true);
        cssInjected = true;
    }

}

From source file:com.watopi.chosen.client.SelectParser.java

License:Open Source License

public JsObjectArray<SelectItem> parse(SelectElement select) {

    NodeList<Node> children = select.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node n = children.getItem(i);
        addNode(n);//from   w ww .ja  v  a  2 s  . co  m
    }

    return parsed;
}

From source file:com.watopi.chosen.client.SelectParser.java

License:Open Source License

private void addGroup(OptGroupElement group) {
    int position = parsed.length();

    GroupItem item = new GroupItem();
    item.arrayIndex = position;//from ww  w .j  a  v  a  2  s . c om
    item.label = group.getLabel();
    item.children = 0;
    item.disabled = group.isDisabled();

    parsed.add(item);

    NodeList<Node> children = group.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node n = children.getItem(i);
        if ("OPTION".equalsIgnoreCase(n.getNodeName())) {
            addOption(OptionElement.as((Element) n), position, group.isDisabled());
        }
    }

}