@Nullable private List<UsageInfo> getSelectedUsageInfos() { TreePath[] paths = myTree.getSelectionPaths(); if (paths == null) return null; final ArrayList<UsageInfo> result = new ArrayList<UsageInfo>(); for (TreePath path : paths) { SliceNode sliceNode = fromPath(path); if (sliceNode != null) { result.add(sliceNode.getValue().getUsageInfo()); } } if (result.isEmpty()) return null; return result; }
@Nullable private Node[] getSelectedNodes() { TreePath[] leadSelectionPath = myTree.getSelectionPaths(); if (leadSelectionPath == null || leadSelectionPath.length == 0) return null; final List<Node> result = new ArrayList<Node>(); for (TreePath comp : leadSelectionPath) { final Object lastPathComponent = comp.getLastPathComponent(); if (lastPathComponent instanceof Node) { final Node node = (Node) lastPathComponent; result.add(node); } } return result.isEmpty() ? null : result.toArray(new Node[result.size()]); }
@Override @Nullable public Set<Usage> getSelectedUsages() { TreePath[] selectionPaths = myTree.getSelectionPaths(); if (selectionPaths == null) { return null; } Set<Usage> usages = new THashSet<Usage>(); for (TreePath selectionPath : selectionPaths) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath.getLastPathComponent(); collectUsages(node, usages); } return usages; }
@NotNull private List<Navigatable> getNavigatables() { TreePath[] paths = myTree.getSelectionPaths(); if (paths == null) return Collections.emptyList(); final ArrayList<Navigatable> navigatables = new ArrayList<Navigatable>(); for (TreePath path : paths) { Object lastPathComponent = path.getLastPathComponent(); if (lastPathComponent instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastPathComponent; Object userObject = node.getUserObject(); if (userObject instanceof Navigatable) { navigatables.add((Navigatable) userObject); } else if (node instanceof Navigatable) { navigatables.add((Navigatable) node); } } } return navigatables; }
@Nullable private UsageTarget[] getSelectedUsageTargets() { TreePath[] selectionPaths = myTree.getSelectionPaths(); if (selectionPaths == null) return null; Set<UsageTarget> targets = new THashSet<UsageTarget>(); for (TreePath selectionPath : selectionPaths) { Object lastPathComponent = selectionPath.getLastPathComponent(); if (lastPathComponent instanceof UsageTargetNode) { UsageTargetNode usageTargetNode = (UsageTargetNode) lastPathComponent; UsageTarget target = usageTargetNode.getTarget(); if (target != null && target.isValid()) { targets.add(target); } } } return targets.isEmpty() ? null : targets.toArray(new UsageTarget[targets.size()]); }