List of usage examples for com.google.gwt.aria.client Roles getTreeRole
public static TreeRole getTreeRole()
From source file:com.vaadin.client.ui.SuperTreeConnector.java
License:Apache License
@Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { if (!isRealUpdate(uidl)) { return;//from w w w .ja va 2s. c o m } getWidget().rendering = true; getWidget().client = client; if (uidl.hasAttribute("partialUpdate")) { handleUpdate(uidl); getWidget().rendering = false; return; } getWidget().paintableId = uidl.getId(); getWidget().immediate = getState().immediate; getWidget().disabled = !isEnabled(); getWidget().readonly = isReadOnly(); getWidget().dragMode = uidl.hasAttribute("dragMode") ? uidl.getIntAttribute("dragMode") : 0; getWidget().isNullSelectionAllowed = uidl.getBooleanAttribute("nullselect"); if (uidl.hasAttribute("alb")) { getWidget().bodyActionKeys = uidl.getStringArrayAttribute("alb"); } // Context menu selection if (contextMenuSelection) { getWidget().rendering = false; contextMenuSelection = false; return; } getWidget().body.clear(); // clear out any references to nodes that no longer are attached getWidget().clearNodeToKeyMap(); tooltipMap.clear(); SuperTreeWidget.TreeNode childTree = null; UIDL childUidl = null; for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) { childUidl = (UIDL) i.next(); if ("actions".equals(childUidl.getTag())) { updateActionMap(childUidl); continue; } else if ("-ac".equals(childUidl.getTag())) { getWidget().updateDropHandler(childUidl); continue; } childTree = getWidget().new TreeNode(); getConnection().getVTooltip().connectHandlersToWidget(childTree); updateNodeFromUIDL(childTree, childUidl, 1); getWidget().body.add(childTree); childTree.addStyleDependentName("root"); childTree.childNodeContainer.addStyleDependentName("root"); } if (childTree != null && childUidl != null) { boolean leaf = !childUidl.getTag().equals("node"); childTree.addStyleDependentName(leaf ? "leaf-last" : "last"); childTree.childNodeContainer.addStyleDependentName("last"); } final String selectMode = uidl.getStringAttribute("selectmode"); getWidget().selectable = !"none".equals(selectMode); getWidget().isMultiselect = "multi".equals(selectMode); if (getWidget().isMultiselect) { Roles.getTreeRole().setAriaMultiselectableProperty(getWidget().getElement(), true); if (BrowserInfo.get().isTouchDevice()) { // Always use the simple mode for touch devices that do not have // shift/ctrl keys (#8595) getWidget().multiSelectMode = MultiSelectMode.SIMPLE; } else { getWidget().multiSelectMode = MultiSelectMode.valueOf(uidl.getStringAttribute("multiselectmode")); } } else { Roles.getTreeRole().setAriaMultiselectableProperty(getWidget().getElement(), false); } getWidget().selectedIds = uidl.getStringArrayVariableAsSet("selected"); // Update lastSelection and focusedNode to point to *actual* nodes again // after the old ones have been cleared from the body. This fixes focus // and keyboard navigation issues as described in #7057 and other // tickets. if (getWidget().lastSelection != null) { getWidget().lastSelection = getWidget().getNodeByKey(getWidget().lastSelection.key); } if (getWidget().focusedNode != null) { Set<String> selectedIds = getWidget().selectedIds; // If the focused node is not between the selected nodes, we need to // refresh the focused node to prevent an undesired scroll. #12618. if (!selectedIds.isEmpty() && !selectedIds.contains(getWidget().focusedNode.key)) { String keySelectedId = selectedIds.iterator().next(); SuperTreeWidget.TreeNode nodeToSelect = getWidget().getNodeByKey(keySelectedId); getWidget().setFocusedNode(nodeToSelect); } else { getWidget().setFocusedNode(getWidget().getNodeByKey(getWidget().focusedNode.key)); } } if (getWidget().lastSelection == null && getWidget().focusedNode == null && !getWidget().selectedIds.isEmpty()) { getWidget().setFocusedNode(getWidget().getNodeByKey(getWidget().selectedIds.iterator().next())); getWidget().focusedNode.setFocused(false); } // IE8 needs a hack to measure the tree again after update Util.forceIE8Redraw(getWidget().getElement()); getWidget().rendering = false; }
From source file:com.vaadin.client.ui.SuperTreeWidget.java
License:Apache License
public SuperTreeWidget() { super();/*w w w. j a va 2 s.c o m*/ setStyleName(CLASSNAME); Roles.getTreeRole().set(body.getElement()); add(body); addFocusHandler(this); addBlurHandler(this); /* * Listen to context menu events on the empty space in the tree */ sinkEvents(Event.ONCONTEXTMENU); addDomHandler(new ContextMenuHandler() { @Override public void onContextMenu(ContextMenuEvent event) { handleBodyContextMenu(event); } }, ContextMenuEvent.getType()); /* * Firefox auto-repeat works correctly only if we use a key press * handler, other browsers handle it correctly when using a key down * handler */ if (BrowserInfo.get().isGecko()) { addKeyPressHandler(this); } else { addKeyDownHandler(this); } /* * We need to use the sinkEvents method to catch the keyUp events so we * can cache a single shift. KeyUpHandler cannot do this. At the same * time we catch the mouse down and up events so we can apply the text * selection patch in IE */ sinkEvents(Event.ONMOUSEDOWN | Event.ONMOUSEUP | Event.ONKEYUP); /* * Re-set the tab index to make sure that the FocusElementPanel's * (super) focus element gets the tab index and not the element * containing the tree. */ setTabIndex(0); }
From source file:com.vaadin.client.ui.SuperTreeWidget.java
License:Apache License
/** * Sets the node currently in focus/*w w w .j ava 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(); } }); } } }
From source file:com.vaadin.client.ui.tree.TreeConnector.java
License:Apache License
@Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { if (!isRealUpdate(uidl)) { return;/*from ww w. j a v a2 s . c om*/ } getWidget().rendering = true; getWidget().client = client; if (uidl.hasAttribute("partialUpdate")) { handleUpdate(uidl); // IE8 needs a hack to measure the tree again after update WidgetUtil.forceIE8Redraw(getWidget().getElement()); getWidget().rendering = false; return; } getWidget().paintableId = uidl.getId(); getWidget().immediate = getState().immediate; getWidget().disabled = !isEnabled(); getWidget().readonly = isReadOnly(); getWidget().dragMode = uidl.hasAttribute("dragMode") ? uidl.getIntAttribute("dragMode") : 0; getWidget().isNullSelectionAllowed = uidl.getBooleanAttribute("nullselect"); getWidget().isHtmlContentAllowed = uidl.getBooleanAttribute(TreeConstants.ATTRIBUTE_HTML_ALLOWED); if (uidl.hasAttribute("alb")) { getWidget().bodyActionKeys = uidl.getStringArrayAttribute("alb"); } getWidget().body.clear(); // clear out any references to nodes that no longer are attached getWidget().clearNodeToKeyMap(); tooltipMap.clear(); TreeNode childTree = null; UIDL childUidl = null; for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) { childUidl = (UIDL) i.next(); if ("actions".equals(childUidl.getTag())) { updateActionMap(childUidl); continue; } else if ("-ac".equals(childUidl.getTag())) { getWidget().updateDropHandler(childUidl); continue; } childTree = getWidget().new TreeNode(); getConnection().getVTooltip().connectHandlersToWidget(childTree); updateNodeFromUIDL(childTree, childUidl, 1); getWidget().body.add(childTree); childTree.addStyleDependentName("root"); childTree.childNodeContainer.addStyleDependentName("root"); } if (childTree != null && childUidl != null) { boolean leaf = !childUidl.getTag().equals("node"); childTree.addStyleDependentName(leaf ? "leaf-last" : "last"); childTree.childNodeContainer.addStyleDependentName("last"); } final String selectMode = uidl.getStringAttribute("selectmode"); getWidget().selectable = !"none".equals(selectMode); getWidget().isMultiselect = "multi".equals(selectMode); if (getWidget().isMultiselect) { Roles.getTreeRole().setAriaMultiselectableProperty(getWidget().getElement(), true); if (BrowserInfo.get().isTouchDevice()) { // Always use the simple mode for touch devices that do not have // shift/ctrl keys (#8595) getWidget().multiSelectMode = MultiSelectMode.SIMPLE; } else { getWidget().multiSelectMode = MultiSelectMode.valueOf(uidl.getStringAttribute("multiselectmode")); } } else { Roles.getTreeRole().setAriaMultiselectableProperty(getWidget().getElement(), false); } getWidget().selectedIds = uidl.getStringArrayVariableAsSet("selected"); // Update lastSelection and focusedNode to point to *actual* nodes again // after the old ones have been cleared from the body. This fixes focus // and keyboard navigation issues as described in #7057 and other // tickets. if (getWidget().lastSelection != null) { getWidget().lastSelection = getWidget().getNodeByKey(getWidget().lastSelection.key); } if (getWidget().focusedNode != null) { Set<String> selectedIds = getWidget().selectedIds; // If the focused node is not between the selected nodes, we need to // refresh the focused node to prevent an undesired scroll. #12618. if (!selectedIds.isEmpty() && !selectedIds.contains(getWidget().focusedNode.key)) { String keySelectedId = selectedIds.iterator().next(); TreeNode nodeToSelect = getWidget().getNodeByKey(keySelectedId); getWidget().setFocusedNode(nodeToSelect); } else { getWidget().setFocusedNode(getWidget().getNodeByKey(getWidget().focusedNode.key)); } } if (getWidget().lastSelection == null && getWidget().focusedNode == null && !getWidget().selectedIds.isEmpty()) { getWidget().setFocusedNode(getWidget().getNodeByKey(getWidget().selectedIds.iterator().next())); getWidget().focusedNode.setFocused(false); } // IE8 needs a hack to measure the tree again after update WidgetUtil.forceIE8Redraw(getWidget().getElement()); getWidget().rendering = false; }
From source file:com.vaadin.client.ui.VTree.java
License:Apache License
public VTree() { super();//from www. j a va 2 s .c o m setStyleName(CLASSNAME); Roles.getTreeRole().set(body.getElement()); add(body); addFocusHandler(this); addBlurHandler(this); /* * Listen to context menu events on the empty space in the tree */ sinkEvents(Event.ONCONTEXTMENU); addDomHandler(new ContextMenuHandler() { @Override public void onContextMenu(ContextMenuEvent event) { handleBodyContextMenu(event); } }, ContextMenuEvent.getType()); /* * Firefox auto-repeat works correctly only if we use a key press * handler, other browsers handle it correctly when using a key down * handler */ if (BrowserInfo.get().isGecko()) { addKeyPressHandler(this); } else { addKeyDownHandler(this); } /* * We need to use the sinkEvents method to catch the keyUp events so we * can cache a single shift. KeyUpHandler cannot do this. At the same * time we catch the mouse down and up events so we can apply the text * selection patch in IE */ sinkEvents(Event.ONMOUSEDOWN | Event.ONMOUSEUP | Event.ONKEYUP); /* * Re-set the tab index to make sure that the FocusElementPanel's * (super) focus element gets the tab index and not the element * containing the tree. */ setTabIndex(0); }
From source file:com.vaadin.v7.client.ui.tree.TreeConnector.java
License:Apache License
@Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { if (!isRealUpdate(uidl)) { return;//from ww w .jav a 2 s .co m } getWidget().rendering = true; getWidget().client = client; if (uidl.hasAttribute("partialUpdate")) { handleUpdate(uidl); getWidget().rendering = false; return; } getWidget().paintableId = uidl.getId(); getWidget().immediate = getState().immediate; getWidget().disabled = !isEnabled(); getWidget().readonly = isReadOnly(); getWidget().dragMode = uidl.hasAttribute("dragMode") ? uidl.getIntAttribute("dragMode") : 0; getWidget().isNullSelectionAllowed = uidl.getBooleanAttribute("nullselect"); getWidget().isHtmlContentAllowed = uidl.getBooleanAttribute(TreeConstants.ATTRIBUTE_HTML_ALLOWED); if (uidl.hasAttribute("alb")) { getWidget().bodyActionKeys = uidl.getStringArrayAttribute("alb"); } getWidget().body.clear(); // clear out any references to nodes that no longer are attached getWidget().clearNodeToKeyMap(); tooltipMap.clear(); TreeNode childTree = null; UIDL childUidl = null; for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) { childUidl = (UIDL) i.next(); if ("actions".equals(childUidl.getTag())) { updateActionMap(childUidl); continue; } else if ("-ac".equals(childUidl.getTag())) { getWidget().updateDropHandler(childUidl); continue; } childTree = getWidget().new TreeNode(); getConnection().getVTooltip().connectHandlersToWidget(childTree); updateNodeFromUIDL(childTree, childUidl, 1); getWidget().body.add(childTree); childTree.addStyleDependentName("root"); childTree.childNodeContainer.addStyleDependentName("root"); } if (childTree != null && childUidl != null) { boolean leaf = !childUidl.getTag().equals("node"); childTree.addStyleDependentName(leaf ? "leaf-last" : "last"); childTree.childNodeContainer.addStyleDependentName("last"); } final String selectMode = uidl.getStringAttribute("selectmode"); getWidget().selectable = !"none".equals(selectMode); getWidget().isMultiselect = "multi".equals(selectMode); if (getWidget().isMultiselect) { Roles.getTreeRole().setAriaMultiselectableProperty(getWidget().getElement(), true); if (BrowserInfo.get().isTouchDevice()) { // Always use the simple mode for touch devices that do not have // shift/ctrl keys (#8595) getWidget().multiSelectMode = MultiSelectMode.SIMPLE; } else { getWidget().multiSelectMode = MultiSelectMode.valueOf(uidl.getStringAttribute("multiselectmode")); } } else { Roles.getTreeRole().setAriaMultiselectableProperty(getWidget().getElement(), false); } getWidget().selectedIds = uidl.getStringArrayVariableAsSet("selected"); // Update lastSelection and focusedNode to point to *actual* nodes again // after the old ones have been cleared from the body. This fixes focus // and keyboard navigation issues as described in #7057 and other // tickets. if (getWidget().lastSelection != null) { getWidget().lastSelection = getWidget().getNodeByKey(getWidget().lastSelection.key); } if (getWidget().focusedNode != null) { Set<String> selectedIds = getWidget().selectedIds; // If the focused node is not between the selected nodes, we need to // refresh the focused node to prevent an undesired scroll. #12618. if (!selectedIds.isEmpty() && !selectedIds.contains(getWidget().focusedNode.key)) { String keySelectedId = selectedIds.iterator().next(); TreeNode nodeToSelect = getWidget().getNodeByKey(keySelectedId); getWidget().setFocusedNode(nodeToSelect); } else { getWidget().setFocusedNode(getWidget().getNodeByKey(getWidget().focusedNode.key)); } } if (getWidget().lastSelection == null && getWidget().focusedNode == null && !getWidget().selectedIds.isEmpty()) { getWidget().setFocusedNode(getWidget().getNodeByKey(getWidget().selectedIds.iterator().next())); getWidget().focusedNode.setFocused(false); } getWidget().rendering = false; }
From source file:com.vaadin.v7.client.ui.VTree.java
License:Apache License
/** * Sets the node currently in focus//from w w w.jav a2 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:org.rest.client.ui.desktop.MenuViewImpl.java
License:Apache License
public MenuViewImpl() { initWidget(uiBinder.createAndBindUi(this)); sinkEvents(Event.ONMOUSEDOWN | Event.ONCLICK | Event.KEYEVENTS); Roles.getTreeRole().set(getElement()); }