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.rstudio.core.client.dom.DomUtils.java

License:Open Source License

private static int countLinesInternal(Element elementNode, boolean pre) {
    if (elementNode.getTagName().equalsIgnoreCase("br"))
        return 1;

    int result = 0;
    NodeList<Node> children = elementNode.getChildNodes();
    for (int i = 0; i < children.getLength(); i++)
        result += countLines(children.getItem(i), pre);
    return result;
}

From source file:org.rstudio.core.client.dom.impl.NodeRelativePosition.java

License:Open Source License

private static boolean toOffsetHelper(Node here, NodeRelativePosition target, int[] counter) {
    if (target.node.equals(here)) {
        switch (here.getNodeType()) {
        case Node.TEXT_NODE:
            counter[0] += target.offset;
            return true;
        case Node.ELEMENT_NODE:
            NodeList<Node> children = here.getChildNodes();
            for (int i = 0; i < target.offset; i++)
                toOffsetHelper(children.getItem(i), target, counter);
            return true;
        default:/*  w ww  . j a  v a2 s. c o m*/
            Debug.log("Unexpected node type for selection offset: " + here.getNodeType());
            return false;
        }
    } else {
        if (here.getNodeType() == Node.TEXT_NODE) {
            counter[0] += ((Text) here).getLength();
            return false;
        } else if (here.getNodeType() == Node.ELEMENT_NODE) {
            Element el = (Element) here;
            String tag = el.getTagName().toLowerCase();
            if (tag.equals("br")) {
                counter[0] += 1;
                return false;
            }
            if (tag.equals("script") || tag.equals("style"))
                return false;

            // Otherwise continue to iteration code below
        }

        NodeList<Node> children = here.getChildNodes();
        for (int i = 0; i < children.getLength(); i++)
            if (toOffsetHelper(children.getItem(i), target, counter))
                return true;

        return false;
    }
}

From source file:org.rstudio.core.client.dom.impl.NodeRelativePosition.java

License:Open Source License

private static NodeRelativePosition toPositionHelper(Node here, int[] counter) {
    switch (here.getNodeType()) {
    case Node.TEXT_NODE:
        Text text = (Text) here;
        if (counter[0] <= text.getLength())
            return new NodeRelativePosition(here, counter[0]);
        counter[0] -= text.getLength();//from   www  .ja v  a2  s . c o m
        return null;
    case Node.ELEMENT_NODE:
        Element el = (Element) here;
        String tagName = el.getTagName().toLowerCase();
        if (tagName.equals("br")) {
            if (counter[0] <= 0)
                return new NodeRelativePosition(here, 0);
            counter[0] -= 1;
            return null;
        } else if (tagName.equals("script") || tagName.equals("style"))
            return null;
        break;
    }

    NodeList<Node> children = here.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        NodeRelativePosition result = toPositionHelper(children.getItem(i), counter);
        if (result != null)
            return result;
    }

    return null;
}

From source file:org.rstudio.core.client.widget.FastSelectTable.java

License:Open Source License

public void removeTopRows(int rowCount) {
    if (rowCount <= 0)
        return;//from  ww w. j  a  v  a  2s  . c  o  m

    NodeList<TableSectionElement> tBodies = table_.getTBodies();
    for (int i = 0; i < tBodies.getLength(); i++) {
        rowCount = removeTopRows(tBodies.getItem(i), rowCount);
        if (rowCount == 0)
            return;
    }
}

From source file:org.rstudio.core.client.widget.FastSelectTable.java

License:Open Source License

public boolean moveSelectionDown() {
    if (selectedRows_.size() == 0)
        return false;

    sortSelectedRows();/*from www. ja  v a2  s.  c  o m*/
    int bottom = selectedRows_.get(selectedRows_.size() - 1).getRowIndex();

    NodeList<TableRowElement> rows = table_.getRows();
    TableRowElement rowToSelect = null;
    while (++bottom < rows.getLength()) {
        TableRowElement row = rows.getItem(bottom);
        if (codec_.isValueRow(row)) {
            rowToSelect = row;
            break;
        }
    }
    if (rowToSelect == null)
        return false;

    clearSelection();
    setSelected(rowToSelect, true);
    return true;
}

From source file:org.rstudio.core.client.widget.HeaderBreaksItemCodec.java

License:Open Source License

public void onRowsChanged(TableSectionElement tbody) {
    if (!hasNonValueRows())
        return;//w w w.ja v a2  s. com

    TableRowElement lastRow = null;

    Node previousSibling = tbody.getPreviousSibling();
    if (previousSibling != null && previousSibling.getNodeType() == Node.ELEMENT_NODE
            && ((Element) previousSibling).getTagName().equalsIgnoreCase("tbody")) {
        TableSectionElement prevbody = (TableSectionElement) previousSibling;
        NodeList<TableRowElement> prevrows = prevbody.getRows();
        if (prevrows.getLength() > 0) {
            TableRowElement lastRowEl = prevrows.getItem(prevrows.getLength() - 1);
            if (isValueRow(lastRowEl)) {
                lastRow = lastRowEl;
            }
        }
    }

    int totalExtraRows = 0;
    final NodeList<TableRowElement> rows = tbody.getRows();
    for (int i = 0; i < rows.getLength(); i++) {
        TableRowElement row = rows.getItem(i);
        if (needsBreak(lastRow, row)) {
            int extraRows = addBreak(row);
            i += extraRows;
            totalExtraRows += extraRows;
        }

        lastRow = row;
    }

    tbody.setPropertyInt(EXTRA_ROWS, totalExtraRows);
}

From source file:org.rstudio.core.client.widget.HeaderBreaksItemCodec.java

License:Open Source License

public Integer logicalOffsetToPhysicalOffset(TableElement table, int offset) {
    if (!hasNonValueRows())
        return offset;

    NodeList<TableSectionElement> bodies = table.getTBodies();
    int skew = 0;
    int pos = 0;/*w w  w  .j ava2s . c om*/
    for (int i = 0; i < bodies.getLength(); i++) {
        TableSectionElement body = bodies.getItem(i);
        NodeList<TableRowElement> rows = body.getRows();
        int rowCount = rows.getLength();
        int extraRows = body.getPropertyInt(EXTRA_ROWS);
        int max = (pos - skew) + (rowCount - extraRows);
        if (max <= offset) {
            // It's safe to skip this whole tbody. These are not the
            // rows we're looking for.
            pos += rowCount;
            skew += extraRows;
        } else {
            NodeList<TableRowElement> allRows = table.getRows();
            for (; pos < allRows.getLength(); pos++) {
                TableRowElement row = allRows.getItem(pos);
                if (!isValueRow(row))
                    skew++;
                else if (offset == (pos - skew))
                    return pos;
            }
        }
    }

    if (pos - skew == offset)
        return pos;
    else
        return null;
}

From source file:org.rstudio.core.client.widget.HeaderBreaksItemCodec.java

License:Open Source License

public Integer physicalOffsetToLogicalOffset(TableElement table, int offset) {
    if (!hasNonValueRows())
        return offset;

    if (offset >= table.getRows().getLength())
        return null;

    NodeList<TableSectionElement> bodies = table.getTBodies();
    int logicalOffset = 0;
    for (int i = 0; offset > 0 && i < bodies.getLength(); i++) {
        TableSectionElement body = bodies.getItem(i);
        NodeList<TableRowElement> rows = body.getRows();
        int rowCount = rows.getLength();
        int extraRows = body.getPropertyInt(EXTRA_ROWS);
        if (rowCount < offset) {
            logicalOffset += rowCount - extraRows;
            offset -= rowCount;//w ww  .  ja va 2  s. com
        } else {
            // It's in here
            for (int j = 0; offset > 0 && j < rows.getLength(); j++) {
                offset--;
                if (isValueRow(rows.getItem(j)))
                    logicalOffset++;
            }
        }
    }

    return logicalOffset;
}

From source file:org.rstudio.core.client.widget.HeaderBreaksItemCodec.java

License:Open Source License

public int getLogicalRowCount(TableElement table) {
    if (!hasNonValueRows())
        return table.getRows().getLength();

    NodeList<TableSectionElement> bodies = table.getTBodies();
    int logicalOffset = 0;
    for (int i = 0; i < bodies.getLength(); i++) {
        TableSectionElement body = bodies.getItem(i);
        NodeList<TableRowElement> rows = body.getRows();
        int rowCount = rows.getLength();
        int extraRows = body.getPropertyInt(EXTRA_ROWS);
        logicalOffset += rowCount - extraRows;
    }//from   www .  ja v a2  s. c  o m
    return logicalOffset;
}

From source file:org.rstudio.studio.client.application.ApplicationCsrfToken.java

License:Open Source License

public static String getCsrfToken() {
    NodeList<Element> metas = Document.get().getElementsByTagName("meta");
    for (int i = 0; i < metas.getLength(); i++) {
        Element meta = metas.getItem(i);
        if (StringUtil.equals(meta.getAttribute("name"), "csrf-token")) {
            return meta.getAttribute("content");
        }// w  w w.j  a  v  a 2 s  .c o  m
    }
    return "";
}