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:org.activityinfo.ui.client.widget.CellTableHeaderWidthApplier.java

License:Open Source License

public void saveHeaderWidthInformation() {
    headerWidth = table.getTableHeadElement().getOffsetWidth();
    final NodeList<TableRowElement> headerRows = table.getTableHeadElement().getRows();
    for (int i = 0; i < headerRows.getLength(); i++) {
        final TableRowElement row = headerRows.getItem(i);
        headerRowToWidthMap.put(i, row.getOffsetWidth());

        final NodeList<TableCellElement> cells = row.getCells();
        for (int j = 0; j < cells.getLength(); j++) {
            final TableCellElement cell = cells.getItem(j);
            headerCellToWidthMap.put(new Pair<>(i, j), cell.getOffsetWidth());
        }/*from   w w w .  j av  a  2  s  .co  m*/
    }
}

From source file:org.adamtacy.client.ui.effects.impl.Resize.java

License:Apache License

private void createInternalEffectsPerElement(Element currEl) {

    NodeList<Node> nodes = currEl.getChildNodes();
    if (nodes != null) {
        for (int i = 0; i < nodes.getLength(); i++) {
            Node n = nodes.getItem(i);
            if (n.getNodeType() == Node.ELEMENT_NODE) {
                createInternalEffectsPerElement((Element) nodes.getItem(i));
            }/*from   w w  w  .  j ava2s.  c om*/
        }
    }

    Vector<ChangeInterface> temp = new Vector<ChangeInterface>();

    String name = currEl.getNodeName();
    if (triggerDOM.contains(name)) {
        GWT.log("Resize Effect is Processing: " + name, null);

        int startVal;
        int endVal;
        // Deal with Widths
        startVal = getStartWidth(currEl);
        endVal = getEndWidth(currEl);
        if (startVal != endVal) {
            NChangeScalarAction theWidthChange = new NChangeScalarAction(startVal + "px", endVal + "px");
            temp.add(theWidthChange);
            theWidthChange.setUp(currEl, "width", 0);
        }

        // Deal with Heights
        startVal = getStartHeight(currEl);
        endVal = getEndHeight(currEl);
        if (startVal != endVal) {
            NChangeScalarAction theHeightChange = new NChangeScalarAction(startVal + "px", endVal + "px");
            temp.add(theHeightChange);
            theHeightChange.setUp(currEl, "height", 0);
        }

        // Deal with Fonts
        String res = StyleImplementation.getComputedStyle(currEl, "fontSize");

        if (res != null) {
            // We have a font to play with
            String unit = StyleImplementation.getUnits(res);
            double value = -1;
            if (unit == null || unit.equals("")) {
                // Assume we're dealing with a named font-size, as there are no units
                // so, find where this name is in our vector of font size names
                int scale = fontSizes.indexOf(res);
                // If we found it, calculate the font size
                if (scale > -1) {
                    value = (double) Math
                            .round(Math.pow(fontSizeScalingFactor, (scale - standardIndex)) * standardFontSize);
                    unit = standardFontUnit;
                }
            } else {
                // Not a named font-size, so get the value
                value = (new Double(StyleImplementation.getValue(res, unit))).doubleValue();
            }
            if (value > -1) {
                NChangeScalarAction theFontChange = new NChangeScalarAction((int) (value * startXRatio) + unit,
                        (int) (value * endXRatio) + unit);
                theFontChange.setUp(currEl, "fontSize", 0);
                temp.add(theFontChange);
            } else {
                GWT.log("Don't know what to do with this font-size definition: " + res, null);
            }
        }

        // Do we need to manage bounding box aspects, e.g. margin etc?
        if (managesMargin)
            temp.addAll(getBoxChanges("margin", currEl));
        if (managesBorder)
            temp.addAll(getBoxChanges("border", currEl));
        if (managesPadding)
            temp.addAll(getBoxChanges("padding", currEl));

        // Put all ChangeInterfaces together into the determinedEffects object for future management
        determinedEffects.put(currEl, temp);

    } else {
        GWT.log("Resize Effect is Not Processing: " + name, null);
    }
    temp = null;
}

From source file:org.artificer.ui.client.local.util.DOMUtil.java

License:Apache License

/**
 * Gets an element from the given parent element by ID.
 * @param context/*from w  w w.  j a v  a 2s .  c o m*/
 * @param id
 */
public static Element findElementById(Element context, String id) {
    NodeList<Node> nodes = context.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.getItem(i);
        if (((node.getNodeType() == Node.ELEMENT_NODE))) {
            if (id.equals(((Element) node).getAttribute("id"))) {
                return (Element) node;
            } else {
                Element elem = findElementById((Element) node, id);
                if (elem != null) {
                    return elem;
                }
            }
        }
    }
    return null;
}

From source file:org.atmosphere.gwt.client.impl.IFrameCometTransport.java

License:Apache License

private void collect() {
    if (body != null) {
        NodeList<Node> childNodes = body.getChildNodes();
        if (childNodes.getLength() > 1) {
            body.removeChild(childNodes.getItem(0));
        }/*  w w w .j a va 2  s. c  o m*/
    }
}

From source file:org.bonitasoft.console.client.mvp.TemplateRepeat.java

License:Open Source License

@Override
public boolean resetFocus(Context context, Element parent, T value) {
    final NodeList<Element> elements = parent.getElementsByTagName("input");
    if (elements.getLength() > 0) {
        InputElement.as(elements.getItem(0)).focus();
        return true;
    }//from  ww w.j  a va 2s  .c  om
    return false;
}

From source file:org.bonitasoft.forms.client.view.common.DOMUtils.java

License:Open Source License

/**
 * To make script in scriptElements work , need to add script elements in the currentElement to parentElement
 *
 * @param currentElement//from   w  w w  .ja va  2 s . c o  m
 * @param parentElement
 */
public void addScriptElementToDOM(final Element currentElement, final Element parentElement) {
    final List<Element> list = new ArrayList<Element>();
    final NodeList<com.google.gwt.dom.client.Element> scripts = currentElement.getElementsByTagName("script");
    for (int i = 0; i < scripts.getLength(); i++) {
        list.add((Element) scripts.getItem(i));
    }

    for (int i = 0; i < list.size(); i++) {
        final Element e = list.get(i);
        e.removeFromParent();
        final Element scriptElement = DOM.createElement("script");
        final String type = e.getAttribute("type");
        if (!isEmpty(type)) {
            scriptElement.setAttribute("type", type);
        }
        final String language = e.getAttribute("language");
        if (!isEmpty(language)) {
            scriptElement.setAttribute("language", language);
        }
        final String src = e.getAttribute("src");
        if (!isEmpty(src)) {
            scriptElement.setAttribute("src", src);
        }
        scriptElement.setInnerText(e.getInnerText());
        parentElement.appendChild(scriptElement);
    }
}

From source file:org.bonitasoft.forms.client.view.widget.ElementAttributeSupport.java

License:Open Source License

protected void addHtmlAttribute(Widget fieldWidget, final String htmlAttributeName,
        final String htmlAttributeValue) {
    //Working for bug 4991: the "Html Attributes" of date widget
    if (fieldWidget instanceof DateBox) {
        fieldWidget = ((DateBox) fieldWidget).getTextBox();
    }//from ww w. j  ava 2 s  .  c  om
    try {
        final SUPPORTED_EVENT event = SUPPORTED_EVENT.valueOf(htmlAttributeName.toLowerCase());
        switch (event) {
        case onclick:
            ((HasClickHandlers) fieldWidget).addClickHandler(new ClickHandler() {

                public void onClick(final ClickEvent event) {
                    DOMUtils.getInstance().javascriptEval(htmlAttributeValue);
                }
            });
            break;
        case ondbclick:
            ((HasDoubleClickHandlers) fieldWidget).addDoubleClickHandler(new DoubleClickHandler() {

                public void onDoubleClick(final DoubleClickEvent event) {
                    DOMUtils.getInstance().javascriptEval(htmlAttributeValue);
                }
            });
            break;
        case onblur:
            ((HasBlurHandlers) fieldWidget).addBlurHandler(new BlurHandler() {

                public void onBlur(final BlurEvent event) {
                    DOMUtils.getInstance().javascriptEval(htmlAttributeValue);
                }
            });
            break;
        case onchange:
            if (fieldWidget instanceof HasChangeHandlers) {
                ((HasChangeHandlers) fieldWidget).addChangeHandler(new ChangeHandler() {

                    public void onChange(final ChangeEvent event) {
                        DOMUtils.getInstance().javascriptEval(htmlAttributeValue);
                    }
                });
            } else if (fieldWidget instanceof HasValueChangeHandlers<?>) {
                final HasValueChangeHandlers<Serializable> widget = (HasValueChangeHandlers<Serializable>) fieldWidget;
                widget.addValueChangeHandler(new ValueChangeHandler<Serializable>() {

                    public void onValueChange(final ValueChangeEvent<Serializable> event) {
                        DOMUtils.getInstance().javascriptEval(htmlAttributeValue);
                    }
                });
            }
            break;
        case onfocus:
            ((HasFocusHandlers) fieldWidget).addFocusHandler(new FocusHandler() {

                public void onFocus(final FocusEvent event) {
                    DOMUtils.getInstance().javascriptEval(htmlAttributeValue);
                }
            });
            break;
        case onkeydown:
            ((HasKeyDownHandlers) fieldWidget).addKeyDownHandler(new KeyDownHandler() {

                public void onKeyDown(final KeyDownEvent event) {
                    DOMUtils.getInstance().javascriptEval(htmlAttributeValue);
                }
            });
            break;
        case onkeyup:
            ((HasKeyUpHandlers) fieldWidget).addKeyUpHandler(new KeyUpHandler() {

                public void onKeyUp(final KeyUpEvent event) {
                    DOMUtils.getInstance().javascriptEval(htmlAttributeValue);
                }
            });
            break;
        case onkeypress:
            ((HasKeyUpHandlers) fieldWidget).addKeyUpHandler(new KeyUpHandler() {

                public void onKeyUp(final KeyUpEvent event) {
                    DOMUtils.getInstance().javascriptEval(htmlAttributeValue);
                }
            });
            break;
        case onmousedown:
            ((HasMouseDownHandlers) fieldWidget).addMouseDownHandler(new MouseDownHandler() {

                public void onMouseDown(final MouseDownEvent event) {
                    DOMUtils.getInstance().javascriptEval(htmlAttributeValue);
                }
            });
            break;
        case onmouseup:
            ((HasMouseUpHandlers) fieldWidget).addMouseUpHandler(new MouseUpHandler() {

                public void onMouseUp(final MouseUpEvent event) {
                    DOMUtils.getInstance().javascriptEval(htmlAttributeValue);
                }
            });
            break;
        case onmouseover:
            ((HasMouseOverHandlers) fieldWidget).addMouseOverHandler(new MouseOverHandler() {

                public void onMouseOver(final MouseOverEvent event) {
                    DOMUtils.getInstance().javascriptEval(htmlAttributeValue);
                }
            });
            break;
        case onmouseout:
            ((HasMouseOutHandlers) fieldWidget).addMouseOutHandler(new MouseOutHandler() {

                public void onMouseOut(final MouseOutEvent event) {
                    DOMUtils.getInstance().javascriptEval(htmlAttributeValue);
                }
            });
            break;
        case onmousemove:
            ((HasMouseMoveHandlers) fieldWidget).addMouseMoveHandler(new MouseMoveHandler() {

                public void onMouseMove(final MouseMoveEvent event) {
                    DOMUtils.getInstance().javascriptEval(htmlAttributeValue);
                }
            });
            break;
        default:
            break;
        }
    } catch (final Exception e) {
        if (fieldWidget instanceof CheckBox || fieldWidget instanceof CheckboxGroupWidget
                || fieldWidget instanceof RadioButtonGroupWidget || fieldWidget instanceof FileUploadWidget
                || fieldWidget instanceof SuggestBox || fieldWidget instanceof AsyncSuggestBoxWidget
                || fieldWidget instanceof DateBox) {
            final NodeList<Element> inputs = fieldWidget.getElement().getElementsByTagName("input");
            if (inputs != null) {
                for (int i = 0; i < inputs.getLength(); i++) {
                    inputs.getItem(i).setAttribute(htmlAttributeName, htmlAttributeValue);
                }
            }
        } else if (fieldWidget instanceof DurationWidget) {
            final NodeList<Element> selects = fieldWidget.getElement().getElementsByTagName("select");
            if (selects != null) {
                for (int i = 0; i < selects.getLength(); i++) {
                    selects.getItem(i).setAttribute(htmlAttributeName, htmlAttributeValue);
                }
            }
        } else if (fieldWidget instanceof ImageWidget) {
            final NodeList<Element> images = fieldWidget.getElement().getElementsByTagName("img");
            if (images != null) {
                for (int i = 0; i < images.getLength(); i++) {
                    images.getItem(i).setAttribute(htmlAttributeName, htmlAttributeValue);
                }
            }
        } else if (fieldWidget instanceof FileDownloadWidget) {
            final NodeList<Element> links = fieldWidget.getElement().getElementsByTagName("a");
            if (links != null) {
                for (int i = 0; i < links.getLength(); i++) {
                    links.getItem(i).setAttribute(htmlAttributeName, htmlAttributeValue);
                }
            }
        } else if (fieldWidget instanceof TableWidget || fieldWidget instanceof EditableGridWidget) {
            final NodeList<Element> tables = fieldWidget.getElement().getElementsByTagName("table");
            if (tables != null) {
                for (int i = 0; i < tables.getLength(); i++) {
                    tables.getItem(i).setAttribute(htmlAttributeName, htmlAttributeValue);
                }
            }
        } else if (fieldWidget instanceof RichTextWidget) {
            final NodeList<Element> iframes = fieldWidget.getElement().getElementsByTagName("iframe");
            if (iframes != null) {
                for (int i = 0; i < iframes.getLength(); i++) {
                    iframes.getItem(i).setAttribute(htmlAttributeName, htmlAttributeValue);
                }
            }
        } else {
            fieldWidget.getElement().setAttribute(htmlAttributeName, htmlAttributeValue);
        }
    }
}

From source file:org.broadleafcommerce.openadmin.client.view.dynamic.form.RichTextHTMLPane.java

License:Apache License

public Node findIFrame(NodeList<Node> childNodes) {
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node item = childNodes.getItem(i);
        if (item instanceof Element && "IFRAME".equals(((Element) item).getTagName())) {
            return item;
        } else {/*from   w w w .  j a  va2 s . co  m*/
            Node childIFrame = findIFrame(item.getChildNodes());
            if (childIFrame != null) {
                return childIFrame;
            }
        }
    }
    return null;
}

From source file:org.chromium.distiller.ContentExtractor.java

License:Open Source License

/**
 * Get the element of the main article, if any.
 * @return An element of article (not necessarily the html5 article element).
 */// ww w  .ja v  a  2 s  . c o m
private Element getArticleElement(Element root) {
    NodeList<Element> allArticles = root.getElementsByTagName("ARTICLE");
    // Having multiple article elements usually indicates a bad case for this shortcut.
    // TODO(wychen): some sites exclude things like title and author in article element.
    if (allArticles.getLength() == 1) {
        return allArticles.getItem(0);
    }
    // Note that the CSS property matching is case sensitive, and "Article" is the correct
    // capitalization.
    String query = "[itemscope][itemtype*=\"Article\"],[itemscope][itemtype*=\"Post\"]";
    allArticles = DomUtil.querySelectorAll(root, query);
    // It is commonly seen that the article is wrapped separately or in multiple layers.
    if (allArticles.getLength() > 0) {
        return Element.as(DomUtil.getNearestCommonAncestor(allArticles));
    }
    return null;
}

From source file:org.chromium.distiller.DocumentTitleGetter.java

License:Open Source License

/**
 * @return The title of the distilled document.
 *///from   ww  w  . jav a  2 s. co  m
public static String getDocumentTitle(Object objTitle, Element root) {
    String currTitle = "", origTitle = "";

    if (objTitle.getClass() == currTitle.getClass()) { // If objTitle is of String type.
        currTitle = origTitle = objTitle.toString();
    } else if (root != null) { // Otherwise, use text of first TITLE element.
        NodeList<Element> titles = root.getElementsByTagName("TITLE");
        if (titles.getLength() > 0) {
            // Use javascript textContent instead of javascript innerText; the latter only returns
            // visible text, but <title> tags are invisible.
            currTitle = origTitle = DomUtil.javascriptTextContent(titles.getItem(0));
        }
    }
    if (currTitle == "")
        return "";

    if (StringUtil.match(currTitle, " [\\|\\-] ")) { // Title has '|' and/or '-'.
        // Get part before last '|' or '-'.
        currTitle = StringUtil.findAndReplace(origTitle, "(.*)[\\|\\-] .*", "$1");
        if (StringUtil.countWords(currTitle) < 3) { // Part has < 3 words.
            // Get part after first '|' or '-'.
            currTitle = StringUtil.findAndReplace(origTitle, "[^\\|\\-]*[\\|\\-](.*)", "$1");
        }
    } else if (currTitle.indexOf(": ") != -1) { // Title has ':'.
        // Get part after last ':'.
        currTitle = StringUtil.findAndReplace(origTitle, ".*:(.*)", "$1");
        if (StringUtil.countWords(currTitle) < 3) { // Part has < 3 words.
            // Get part after first ':'.
            currTitle = StringUtil.findAndReplace(origTitle, "[^:]*[:](.*)", "$1");
        }
    } else if (root != null && (currTitle.length() > 150 || currTitle.length() < 15)) {
        // Get plain text from the only H1 element.
        // TODO(kuan): this is what readability does, but this block may make more sense as an
        // if rather than else-if, e.g. currently this else-if block is used when original title
        // is "foo" but not when it is "foo |" or "foo:".
        currTitle = findFirstH1(root);
        if (currTitle.isEmpty())
            currTitle = origTitle;
    }

    currTitle = StringUtil.jsTrim(currTitle);

    if (StringUtil.countWords(currTitle) <= 4)
        currTitle = origTitle;

    return currTitle;
}