/** * Collapses an item. * * @param itemId the item id. * @return True iff the collapse operation succeeded */ public boolean collapseItem(Object itemId) { // Succeeds if the node is already collapsed if (!isExpanded(itemId)) { return true; } // Collapse expanded.remove(itemId); markAsDirty(); fireCollapseEvent(itemId); return true; }
/* * (non-Javadoc) * * @see com.vaadin.ui.AbstractSelect#changeVariables(java.lang.Object, * java.util.Map) */ @Override public void changeVariables(Object source, Map<String, Object> variables) { if (variables.containsKey("clickedKey")) { String key = (String) variables.get("clickedKey"); Object id = itemIdMapper.get(key); MouseEventDetails details = MouseEventDetails.deSerialize((String) variables.get("clickEvent")); Item item = getItem(id); if (item != null) { fireEvent(new ItemClickEvent(this, item, id, null, details)); } } if (!isSelectable() && variables.containsKey("selected")) { // Not-selectable is a special case, AbstractSelect does not support // TODO could be optimized. variables = new HashMap<String, Object>(variables); variables.remove("selected"); } // Collapses the nodes if (variables.containsKey("collapse")) { final String[] keys = (String[]) variables.get("collapse"); for (int i = 0; i < keys.length; i++) { final Object id = itemIdMapper.get(keys[i]); if (id != null && isExpanded(id)) { expanded.remove(id); if (expandedItemId == id) { expandedItemId = null; } fireCollapseEvent(id); } } } // Expands the nodes if (variables.containsKey("expand")) { boolean sendChildTree = false; if (variables.containsKey("requestChildTree")) { sendChildTree = true; } final String[] keys = (String[]) variables.get("expand"); for (int i = 0; i < keys.length; i++) { final Object id = itemIdMapper.get(keys[i]); if (id != null) { expandItem(id, sendChildTree); } } } // AbstractSelect cannot handle multiselection so we handle // it ourself if (variables.containsKey("selected") && isMultiSelect() && multiSelectMode == MultiSelectMode.DEFAULT) { handleSelectedItems(variables); variables = new HashMap<String, Object>(variables); variables.remove("selected"); } // Selections are handled by the select component super.changeVariables(source, variables); // Actions if (variables.containsKey("action")) { final StringTokenizer st = new StringTokenizer((String) variables.get("action"), ","); if (st.countTokens() == 2) { final Object itemId = itemIdMapper.get(st.nextToken()); final Action action = actionMapper.get(st.nextToken()); if (action != null && (itemId == null || containsId(itemId)) && actionHandlers != null) { for (Handler ah : actionHandlers) { ah.handleAction(action, this, itemId); } } } } }