void () { LinkedHashSet<CheckedTreeNode> checkedNodes = StreamEx.of(getSelectedTreeNodes()) .map(n -> n instanceof CommitNode ? n.getParent() : n) .select(CheckedTreeNode.class) .filter(CheckedTreeNode::isEnabled) .toCollection(LinkedHashSet::new); if (checkedNodes.isEmpty()) return; // use new state from first lead node; boolean newState = !checkedNodes.iterator().next().isChecked(); checkedNodes.forEach(n -> myTree.setNodeState(n, newState)); }