From f980667fdfef13bcb3bfcd7e86910bed39f39bb2 Mon Sep 17 00:00:00 2001 From: michaelvogt Date: Thu, 21 Mar 2013 10:40:45 +0200 Subject: WAI-ARIA functions for Tree (#11389) All to navigate the tree with an assisitve device Change-Id: I531cefc95d7a720caf69aca579549e5a497ad586 --- server/src/com/vaadin/ui/Tree.java | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'server') 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 @@ -72,6 +72,11 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, /* Private members */ + /** + * Item icons alt texts. + */ + private final HashMap itemIconAlts = new HashMap(); + /** * Set of expanded nodes. */ @@ -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); -- cgit v1.2.3