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.rstudio.core.client.widget.HeaderBreaksItemCodec.java

License:Open Source License

public void onRowsChanged(TableSectionElement tbody) {
    if (!hasNonValueRows())
        return;//from  w  ww . j  av  a2s.c om

    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  a  v  a  2 s.c o m
    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;/*from ww  w .  ja v  a2s.  c o  m*/
        } 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  w  w  w. j a  va 2s . c om*/
    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");
        }/*from   ww  w  . j a v a2 s.  c o  m*/
    }
    return "";
}

From source file:org.rstudio.studio.client.workbench.exportplot.clipboard.CopyPlotToClipboardDesktopDialog.java

License:Open Source License

protected void copyAsBitmap(final Operation onCompleted) {
    final ExportPlotSizeEditor sizeEditor = getSizeEditor();

    sizeEditor.prepareForExport(new Command() {

        @Override//from   ww  w. j a v  a 2  s .  c  o m
        public void execute() {
            if (BrowseCap.isCocoaDesktop()) {
                clipboard_.copyPlotToCocoaPasteboard(sizeEditor.getImageWidth(), sizeEditor.getImageHeight(),
                        new Command() {
                            @Override
                            public void execute() {
                                onCompleted.execute();
                            }
                        });
            } else {
                WindowEx win = sizeEditor.getPreviewIFrame().getContentWindow();
                Document doc = win.getDocument();
                NodeList<Element> images = doc.getElementsByTagName("img");
                if (images.getLength() > 0) {
                    ElementEx img = images.getItem(0).cast();
                    DesktopFrame frame = Desktop.getFrame();
                    frame.copyImageToClipboard(img.getClientLeft(), img.getClientTop(), img.getClientWidth(),
                            img.getClientHeight());
                }

                onCompleted.execute();
            }
        }

    });
}

From source file:org.rstudio.studio.client.workbench.views.console.shell.impl.PlainTextEditorImplFirefox.java

License:Open Source License

private void stripZwsp(Node node) {
    if (node.getNodeType() == Node.TEXT_NODE) {
        while (true) {
            String text = node.getNodeValue();
            int index = text.indexOf('\u200B');
            if (index >= 0)
                DomUtils.deleteTextData((Text) node, index, 1);
            else//  ww  w . j  av a2 s  .co m
                break;
        }
    } else if (node.getNodeType() == Node.ELEMENT_NODE) {
        NodeList<Node> nodes = node.getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++)
            stripZwsp(nodes.getItem(i));
    }
}

From source file:org.rstudio.studio.client.workbench.views.help.HelpPane.java

License:Open Source License

private void helpNavigated(Document doc) {
    NodeList<Element> elements = doc.getElementsByTagName("a");
    for (int i = 0; i < elements.getLength(); i++) {
        ElementEx a = (ElementEx) elements.getItem(i);
        String href = a.getAttribute("href", 2);
        if (href == null)
            continue;

        if (href.contains(":") || href.endsWith(".pdf")) {
            // external links
            AnchorElement aElement = a.cast();
            aElement.setTarget("_blank");
        } else {//from w  ww. j ava 2  s  . c  o m
            // Internal links need to be handled in JavaScript so that
            // they can participate in virtual session history. This
            // won't have any effect for right-click > Show in New Window
            // but that's a good thing.

            a.setAttribute("onclick",
                    "window.parent.helpNavigate(this.href, "
                            + (BrowseCap.isLinuxDesktop() || BrowseCap.isWindowsDesktop() ? "true" : "false")
                            + "); return false");
        }
    }

    String effectiveTitle = getDocTitle(doc);
    title_.setText(effectiveTitle);
    this.fireEvent(new HelpNavigateEvent(doc.getURL(), effectiveTitle));
}

From source file:org.rstudio.studio.client.workbench.views.help.model.HelpInfo.java

License:Open Source License

public final ParsedInfo parse(String defaultSignature) {
    HashMap<String, String> values = new HashMap<String, String>();
    HashMap<String, String> args = new HashMap<String, String>();
    HashMap<String, String> slots = new HashMap<String, String>();

    String html = getHTML();/*from  www  .  j a v  a 2 s .c  om*/
    if (html != null) {
        DivElement div = Document.get().createDivElement();
        div.setInnerHTML(html);

        // disable all links
        NodeList<Element> anchors = div.getElementsByTagName("a");
        for (int i = 0; i < anchors.getLength(); i++) {
            Element anchor = anchors.getItem(i);
            Element parent = anchor.getParentElement();
            Node child = anchor.getFirstChild();
            while (child != null) {
                parent.insertBefore(child, anchor);
                child = child.getNextSibling();
            }
        }

        // parse all description lists
        NodeList<Element> descriptionLists = div.getElementsByTagName("dl");
        for (int i = 0; i < descriptionLists.getLength(); i++)
            parseDescriptionList(args, descriptionLists.getItem(i));

        // get all h2 and h3 headings
        NodeList<Element> h2headings = div.getElementsByTagName("h2");
        NodeList<Element> h3headings = div.getElementsByTagName("h3");
        ArrayList<Element> headings = new ArrayList<Element>();
        for (int i = 0; i < h2headings.getLength(); i++)
            headings.add(h2headings.getItem(i));
        for (int i = 0; i < h3headings.getLength(); i++)
            headings.add(h3headings.getItem(i));

        // the first h2 heading is the title -- handle that specially
        if (headings.size() > 0) {
            Element titleElement = headings.get(0);
            String title = titleElement.getInnerText();
            values.put("Title", title);
        }

        // iterate through them
        for (int i = 1; i < headings.size(); i++) {
            Element heading = headings.get(i);
            String name = heading.getInnerText();
            if (name.equals("Arguments")) {
                parseArguments(args, heading);
            }
            if (name.equals("Slots")) {
                parseDescriptionList(slots, heading);
            }
            StringBuffer value = new StringBuffer();
            Node sibling = heading.getNextSibling();
            while (sibling != null && !sibling.getNodeName().toLowerCase().equals("h2")
                    && !sibling.getNodeName().toLowerCase().equals("h3")) {
                value.append(DomUtils.getHtml(sibling));
                sibling = sibling.getNextSibling();
            }
            values.put(name, value.toString());
        }
    }

    String signature = getSignature();
    if (signature == null)
        signature = defaultSignature;
    return new ParsedInfo(getPackageName(), signature, values, args, slots);
}

From source file:org.rstudio.studio.client.workbench.views.help.model.HelpInfo.java

License:Open Source License

private void parseDescriptionList(HashMap<String, String> args, Element heading) {
    Element table = (Element) DomUtils.findNode(heading, true, true, new NodePredicate() {

        public boolean test(Node n) {
            if (n.getNodeType() != Node.ELEMENT_NODE)
                return false;

            Element el = (Element) n;

            return el.getTagName().toUpperCase().equals("DL");
        }/*from w  w  w .j  av a 2  s .  com*/
    });

    if (table == null) {
        assert false : "Unexpected slots format: no <dl> entry found";
        return;
    }

    NodeList<Node> children = table.getChildNodes();
    int nChildren = children.getLength();
    for (int i = 0; i < nChildren; i++) {
        Element child = (Element) children.getItem(i);
        if (child.getNodeName().toUpperCase().equals("DT")) {
            String argName = child.getInnerText().replaceAll(":", "");
            Element nextChild = (Element) children.getItem(i + 1);
            if (nextChild.getNodeName().toUpperCase().equals("DD")) {
                String value = nextChild.getInnerHTML();
                args.put(argName, value);
            }
        }
    }
}