@Override public void changeVariables(Object source, Map<String, Object> variables) { super.changeVariables(source, variables); if (variables.containsKey("toggleCollapsed")) { String object = (String) variables.get("toggleCollapsed"); Object itemId = itemIdMapper.get(object); toggledItemId = itemId; toggleChildVisibility(itemId, false); if (variables.containsKey("selectCollapsed")) { // ensure collapsed is selected unless opened with selection // head if (isSelectable()) { select(itemId); } } } else if (variables.containsKey("focusParent")) { String key = (String) variables.get("focusParent"); Object refId = itemIdMapper.get(key); Object itemId = getParent(refId); focusParent(itemId); } }
@Test public void valueListenerDoesntPropagateNullInSelection() throws Exception { // GIVEN/WHEN // listener will be called 3 times: // 1. with ROOT_0 (but we don't care, it's just for producing 2.) // 2. via #focusParent, triggering the set containing null // 3. we select ROOT_0 again and expect single selection (not multiple with null + ROOT_O) produceTableValueContainingNull(tree); tree.select(ROOT_0); ArgumentCaptor<Set> itemsCaptor = ArgumentCaptor.forClass(Set.class); verify(listener, times(3)).onItemSelection(itemsCaptor.capture()); verifyNoMoreInteractions(listener); // THEN (2) Set<Object> items = itemsCaptor.getAllValues().get(1); assertThat(items, not(hasItem(nullValue()))); // THEN (3) items = itemsCaptor.getAllValues().get(2); assertThat(items, allOf(hasSize(1), contains(ROOT_0))); }
private void produceTableValueContainingNull(TreeTable tree) { tree.select(ROOT_0); assertThat((Set<?>) tree.getValue(), contains(ROOT_0)); focusParent(tree, ROOT_0); // using a random rowKey, doesn't matter here }