Example usage for com.google.gwt.aria.client Roles getTreeitemRole

List of usage examples for com.google.gwt.aria.client Roles getTreeitemRole

Introduction

In this page you can find the example usage for com.google.gwt.aria.client Roles getTreeitemRole.

Prototype

public static TreeitemRole getTreeitemRole() 

Source Link

Usage

From source file:com.vaadin.client.ui.SuperTreeConnector.java

License:Apache License

private void handleUpdate(UIDL uidl) {
    final SuperTreeWidget.TreeNode rootNode = getWidget().getNodeByKey(uidl.getStringAttribute("rootKey"));
    if (rootNode != null) {
        if (!rootNode.getState()) {
            // expanding node happened server side
            rootNode.setState(true, false);
        }// www .ja  v  a  2s . c o m
        String levelPropertyString = Roles.getTreeitemRole().getAriaLevelProperty(rootNode.getElement());
        int levelProperty;
        try {
            levelProperty = Integer.valueOf(levelPropertyString);
        } catch (NumberFormatException e) {
            levelProperty = 1;
            VConsole.error(e);
        }

        renderChildNodes(rootNode, (Iterator) uidl.getChildIterator(), levelProperty + 1);
    }
}

From source file:com.vaadin.client.ui.SuperTreeConnector.java

License:Apache License

public void updateNodeFromUIDL(SuperTreeWidget.TreeNode treeNode, UIDL uidl, int level) {
    Roles.getTreeitemRole().setAriaLevelProperty(treeNode.getElement(), level);

    String nodeKey = uidl.getStringAttribute("key");
    treeNode.setText(uidl.getStringAttribute(TreeConstants.ATTRIBUTE_NODE_CAPTION));
    treeNode.key = nodeKey;//from ww w . j a  va  2 s . co  m

    getWidget().registerNode(treeNode);

    if (uidl.hasAttribute("al")) {
        treeNode.actionKeys = uidl.getStringArrayAttribute("al");
    }

    if (uidl.getTag().equals("node")) {
        if (uidl.getChildCount() == 0) {
            treeNode.childNodeContainer.setVisible(false);
        } else {
            renderChildNodes(treeNode, (Iterator) uidl.getChildIterator(), level + 1);
            treeNode.childrenLoaded = true;
        }
    } else {
        treeNode.addStyleName(SuperTreeWidget.TreeNode.CLASSNAME + "-leaf");
    }
    if (uidl.hasAttribute(TreeConstants.ATTRIBUTE_NODE_STYLE)) {
        treeNode.setNodeStyleName(uidl.getStringAttribute(TreeConstants.ATTRIBUTE_NODE_STYLE));
    }

    String description = uidl.getStringAttribute("descr");
    if (description != null) {
        tooltipMap.put(treeNode, new TooltipInfo(description));
    }

    if (uidl.getBooleanAttribute("expanded") && !treeNode.getState()) {
        treeNode.setState(true, false);
    }

    if (uidl.getBooleanAttribute("selected")) {
        treeNode.setSelected(true);
        // ensure that identifier is in selectedIds array (this may be a
        // partial update)
        getWidget().selectedIds.add(nodeKey);
    }

    String iconUrl = uidl.getStringAttribute(TreeConstants.ATTRIBUTE_NODE_ICON);
    String iconAltText = uidl.getStringAttribute(TreeConstants.ATTRIBUTE_NODE_ICON_ALT);
    treeNode.setIcon(iconUrl, iconAltText);
}

From source file:com.vaadin.client.ui.SuperTreeWidget.java

License:Apache License

/**
 * Sets the node currently in focus/*from  w  w  w. j av a  2  s. c  om*/
 *
 * @param node
 *            The node to focus or null to remove the focus completely
 * @param scrollIntoView
 *            Scroll the node into view
 */
public void setFocusedNode(TreeNode node, boolean scrollIntoView) {
    // Unfocus previously focused node
    if (focusedNode != null) {
        focusedNode.setFocused(false);

        Roles.getTreeRole().removeAriaActivedescendantProperty(focusedNode.getElement());
    }

    if (node != null) {
        node.setFocused(true);
        Roles.getTreeitemRole().setAriaSelectedState(node.getElement(), SelectedValue.TRUE);

        /*
         * FIXME: This code needs to be changed when the keyboard navigation
         * doesn't immediately trigger a selection change anymore.
         * 
         * Right now this function is called before and after the Tree is
         * rebuilt when up/down arrow keys are pressed. This leads to the
         * problem, that the newly selected item is announced too often with
         * a screen reader.
         * 
         * Behaviour is different when using the Tree with and without
         * screen reader.
         */
        if (node.key.equals(lastNodeKey)) {
            Roles.getTreeRole().setAriaActivedescendantProperty(getFocusElement(), Id.of(node.getElement()));
        } else {
            lastNodeKey = node.key;
        }
    }

    focusedNode = node;

    if (node != null && scrollIntoView) {
        /*
         * Delay scrolling the focused node into view if we are still
         * rendering. #5396
         */
        if (!rendering) {
            node.scrollIntoView();
        } else {
            Scheduler.get().scheduleDeferred(new Command() {
                @Override
                public void execute() {
                    focusedNode.scrollIntoView();
                }
            });
        }
    }
}

From source file:com.vaadin.client.ui.tree.TreeConnector.java

License:Apache License

private void handleUpdate(UIDL uidl) {
    final TreeNode rootNode = getWidget().getNodeByKey(uidl.getStringAttribute("rootKey"));
    if (rootNode != null) {
        if (!rootNode.getState()) {
            // expanding node happened server side
            rootNode.setState(true, false);
        }//from   ww  w  .  java 2 s .  c o  m
        String levelPropertyString = Roles.getTreeitemRole().getAriaLevelProperty(rootNode.getElement());
        int levelProperty;
        try {
            levelProperty = Integer.valueOf(levelPropertyString);
        } catch (NumberFormatException e) {
            levelProperty = 1;
            VConsole.error(e);
        }

        renderChildNodes(rootNode, (Iterator) uidl.getChildIterator(), levelProperty + 1);
    }
}

From source file:com.vaadin.client.ui.tree.TreeConnector.java

License:Apache License

public void updateNodeFromUIDL(TreeNode treeNode, UIDL uidl, int level) {
    Roles.getTreeitemRole().setAriaLevelProperty(treeNode.getElement(), level);

    String nodeKey = uidl.getStringAttribute("key");
    String caption = uidl.getStringAttribute(TreeConstants.ATTRIBUTE_NODE_CAPTION);
    if (getWidget().isHtmlContentAllowed) {
        treeNode.setHtml(caption);/*from ww  w.  j  av  a  2  s.co m*/
    } else {
        treeNode.setText(caption);
    }
    treeNode.key = nodeKey;

    getWidget().registerNode(treeNode);

    if (uidl.hasAttribute("al")) {
        treeNode.actionKeys = uidl.getStringArrayAttribute("al");
    }

    if (uidl.getTag().equals("node")) {
        if (uidl.getChildCount() == 0) {
            treeNode.childNodeContainer.setVisible(false);
        } else {
            renderChildNodes(treeNode, (Iterator) uidl.getChildIterator(), level + 1);
            treeNode.childrenLoaded = true;
        }
    } else {
        treeNode.addStyleName(TreeNode.CLASSNAME + "-leaf");
    }
    if (uidl.hasAttribute(TreeConstants.ATTRIBUTE_NODE_STYLE)) {
        treeNode.setNodeStyleName(uidl.getStringAttribute(TreeConstants.ATTRIBUTE_NODE_STYLE));
    }

    String description = uidl.getStringAttribute("descr");
    if (description != null) {
        tooltipMap.put(treeNode, new TooltipInfo(description, null, treeNode));
    }

    if (uidl.getBooleanAttribute("expanded") && !treeNode.getState()) {
        treeNode.setState(true, false);
    }

    if (uidl.getBooleanAttribute("selected")) {
        treeNode.setSelected(true);
        // ensure that identifier is in selectedIds array (this may be a
        // partial update)
        getWidget().selectedIds.add(nodeKey);
    }

    String iconUrl = uidl.getStringAttribute(TreeConstants.ATTRIBUTE_NODE_ICON);
    String iconAltText = uidl.getStringAttribute(TreeConstants.ATTRIBUTE_NODE_ICON_ALT);
    treeNode.setIcon(iconUrl, iconAltText);
}

From source file:com.vaadin.v7.client.ui.VTree.java

License:Apache License

/**
 * Sets the node currently in focus//from ww  w . j  av a  2 s .c o  m
 *
 * @param node
 *            The node to focus or null to remove the focus completely
 * @param scrollIntoView
 *            Scroll the node into view
 */
public void setFocusedNode(TreeNode node, boolean scrollIntoView) {
    // Unfocus previously focused node
    if (focusedNode != null) {
        focusedNode.setFocused(false);

        Roles.getTreeRole().removeAriaActivedescendantProperty(focusedNode.getElement());
    }

    if (node != null) {
        node.setFocused(true);
        Roles.getTreeitemRole().setAriaSelectedState(node.getElement(), SelectedValue.TRUE);

        /*
         * FIXME: This code needs to be changed when the keyboard navigation
         * doesn't immediately trigger a selection change anymore.
         *
         * Right now this function is called before and after the Tree is
         * rebuilt when up/down arrow keys are pressed. This leads to the
         * problem, that the newly selected item is announced too often with
         * a screen reader.
         *
         * Behaviour is different when using the Tree with and without
         * screen reader.
         */
        if (node.key.equals(lastNodeKey)) {
            Roles.getTreeRole().setAriaActivedescendantProperty(getFocusElement(), Id.of(node.getElement()));
        } else {
            lastNodeKey = node.key;
        }
    }

    focusedNode = node;

    if (node != null && scrollIntoView) {
        /*
         * Delay scrolling the focused node into view if we are still
         * rendering. #5396
         */
        if (!rendering) {
            node.scrollIntoView();
        } else {
            Scheduler.get().scheduleDeferred(new Command() {
                @Override
                public void execute() {
                    focusedNode.scrollIntoView();
                }
            });
        }
    }
}