summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authormichaelvogt <michael@vaadin.com>2013-03-21 10:40:45 +0200
committerVaadin Code Review <review@vaadin.com>2013-04-04 16:15:00 +0000
commitf980667fdfef13bcb3bfcd7e86910bed39f39bb2 (patch)
treebddca5db6884e3a01c6d4455d9aff481d1b18e5c /server
parent3ee3b4926b1af4409b32196ef290baf017b63379 (diff)
downloadvaadin-framework-f980667fdfef13bcb3bfcd7e86910bed39f39bb2.tar.gz
vaadin-framework-f980667fdfef13bcb3bfcd7e86910bed39f39bb2.zip
WAI-ARIA functions for Tree (#11389)
All to navigate the tree with an assisitve device Change-Id: I531cefc95d7a720caf69aca579549e5a497ad586
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/ui/Tree.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/Tree.java b/server/src/com/vaadin/ui/Tree.java
index 34cfbaf61b..700195cd4b 100644
--- a/server/src/com/vaadin/ui/Tree.java
+++ b/server/src/com/vaadin/ui/Tree.java
@@ -73,6 +73,11 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
/* Private members */
/**
+ * Item icons alt texts.
+ */
+ private final HashMap<Object, String> itemIconAlts = new HashMap<Object, String>();
+
+ /**
* Set of expanded nodes.
*/
private HashSet<Object> expanded = new HashSet<Object>();
@@ -163,6 +168,50 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
super(caption, dataSource);
}
+ @Override
+ public void setItemIcon(Object itemId, Resource icon) {
+ setItemIcon(itemId, icon, "");
+ }
+
+ /**
+ * Sets the icon for an item.
+ *
+ * @param itemId
+ * the id of the item to be assigned an icon.
+ * @param icon
+ * the icon to use or null.
+ *
+ * @param altText
+ * String with the alternative text for the icon
+ */
+ public void setItemIcon(Object itemId, Resource icon, String altText) {
+ if (itemId != null) {
+ super.setItemIcon(itemId, icon);
+
+ if (icon == null) {
+ itemIconAlts.remove(itemId);
+ } else if (altText == null) {
+ throw new IllegalArgumentException(
+ "Parameter 'altText' needs to be non null");
+ } else {
+ itemIconAlts.put(itemId, altText);
+ }
+ markAsDirty();
+ }
+ }
+
+ /**
+ * Return the alternate text of an icon in a tree item.
+ *
+ * @param itemId
+ * Object with the ID of the item
+ * @return String with the alternate text of the icon, or null when no icon
+ * was set
+ */
+ public String getItemIconAlternateText(Object itemId) {
+ return itemIconAlts.get(itemId);
+ }
+
/* Expanding and collapsing */
/**
@@ -638,6 +687,8 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
if (icon != null) {
target.addAttribute(TreeConstants.ATTRIBUTE_NODE_ICON,
getItemIcon(itemId));
+ target.addAttribute(TreeConstants.ATTRIBUTE_NODE_ICON_ALT,
+ getItemIconAlternateText(itemId));
}
final String key = itemIdMapper.key(itemId);
target.addAttribute("key", key);