Search in sources :

Example 1 with NodePredicate

use of org.rstudio.core.client.dom.DomUtils.NodePredicate in project rstudio by rstudio.

the class HelpInfo method parseDescriptionList.

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");
        }
    });
    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);
            }
        }
    }
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString) NodePredicate(org.rstudio.core.client.dom.DomUtils.NodePredicate)

Example 2 with NodePredicate

use of org.rstudio.core.client.dom.DomUtils.NodePredicate in project rstudio by rstudio.

the class DocTabLayoutPanel method ensureSelectedTabIsVisible.

public void ensureSelectedTabIsVisible(boolean animate) {
    if (currentAnimation_ != null) {
        currentAnimation_.cancel();
        currentAnimation_ = null;
    }
    Element selectedTab = (Element) DomUtils.findNode(getElement(), true, false, new NodePredicate() {

        public boolean test(Node n) {
            if (n.getNodeType() != Node.ELEMENT_NODE)
                return false;
            return ((Element) n).getClassName().contains("gwt-TabLayoutPanelTab-selected");
        }
    });
    if (selectedTab == null) {
        return;
    }
    selectedTab = selectedTab.getFirstChildElement().getFirstChildElement();
    Element tabBar = getTabBarElement();
    if (!isVisible() || !isAttached() || tabBar.getOffsetWidth() == 0)
        // not yet loaded
        return;
    final Element tabBarParent = tabBar.getParentElement();
    final int start = tabBarParent.getScrollLeft();
    int end = DomUtils.ensureVisibleHoriz(tabBarParent, selectedTab, padding_, padding_ + rightMargin_, true);
    // When tabs are closed, the overall width shrinks, and this can lead
    // to cases where there's too much empty space on the screen
    Node lastTab = getLastChildElement(tabBar);
    if (lastTab == null || lastTab.getNodeType() != Node.ELEMENT_NODE)
        return;
    int edge = DomUtils.getRelativePosition(tabBarParent, Element.as(lastTab)).x + Element.as(lastTab).getOffsetWidth();
    end = Math.min(end, Math.max(0, edge - (tabBarParent.getOffsetWidth() - rightMargin_)));
    if (edge <= tabBarParent.getOffsetWidth() - rightMargin_)
        end = 0;
    if (start != end) {
        if (!animate) {
            tabBarParent.setScrollLeft(end);
        } else {
            final int finalEnd = end;
            currentAnimation_ = new Animation() {

                @Override
                protected void onUpdate(double progress) {
                    double delta = (finalEnd - start) * progress;
                    tabBarParent.setScrollLeft((int) (start + delta));
                }

                @Override
                protected void onComplete() {
                    if (this == currentAnimation_) {
                        tabBarParent.setScrollLeft(finalEnd);
                        currentAnimation_ = null;
                    }
                }
            };
            currentAnimation_.run(Math.max(200, Math.min(1500, Math.abs(end - start) * 2)));
        }
    }
}
Also used : Element(com.google.gwt.dom.client.Element) Node(com.google.gwt.dom.client.Node) Animation(com.google.gwt.animation.client.Animation) Point(org.rstudio.core.client.Point) NodePredicate(org.rstudio.core.client.dom.DomUtils.NodePredicate)

Example 3 with NodePredicate

use of org.rstudio.core.client.dom.DomUtils.NodePredicate in project rstudio by rstudio.

the class HelpInfo method parseArguments.

private void parseArguments(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("TABLE") && "R argblock".equals(el.getAttribute("summary"));
        }
    });
    if (table == null) {
        assert false : "Unexpected help format, no argblock table found";
        return;
    }
    TableElement t = (TableElement) table;
    NodeList<TableRowElement> rows = t.getRows();
    for (int i = 0; i < rows.getLength(); i++) {
        TableRowElement row = rows.getItem(i);
        NodeList<TableCellElement> cells = row.getCells();
        TableCellElement argNameCell = cells.getItem(0);
        TableCellElement argValueCell = cells.getItem(1);
        String argNameText = argNameCell.getInnerText();
        String argValueHtml = argValueCell.getInnerHTML();
        // argNameCell may be multiple comma-delimited arguments;
        // split them up if necessary (duplicate the help across args)
        String[] argNameTextSplat = argNameText.split("\\s*,\\s*");
        for (int j = 0; j < argNameTextSplat.length; j++) args.put(argNameTextSplat[j], argValueHtml);
    }
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString) NodePredicate(org.rstudio.core.client.dom.DomUtils.NodePredicate)

Aggregations

NodePredicate (org.rstudio.core.client.dom.DomUtils.NodePredicate)3 JsArrayString (com.google.gwt.core.client.JsArrayString)2 Animation (com.google.gwt.animation.client.Animation)1 Element (com.google.gwt.dom.client.Element)1 Node (com.google.gwt.dom.client.Node)1 Point (org.rstudio.core.client.Point)1