void (@NotNull AnActionEvent e) { TreePath[] selectionPaths = tree.getSelectionPaths(); if (selectionPaths == null || selectionPaths.length == 0) return; TaintNode[] roots = tree.getSelectedNodes(TaintNode.class, null); Deque<TaintNode> nodes = new ArrayDeque<>(Arrays.asList(roots)); boolean enable = false; while (!nodes.isEmpty()) { TaintNode node = nodes.poll(); if (node.myTaintValue == TaintValue.TAINTED) { e.getPresentation().setEnabled(false); return; } enable |= node.isExcluded() != myExclude; List<TaintNode> children = node.myCachedChildren; if (children != null) nodes.addAll(children); } e.getPresentation().setEnabled(enable); }