protected VirtualFile[] getSelectedFiles() {
    final Change[] changes = getSelectedChanges();
    Collection<VirtualFile> files = new HashSet<VirtualFile>();
    for (Change change : changes) {
      final ContentRevision afterRevision = change.getAfterRevision();
      if (afterRevision != null) {
        final VirtualFile file = afterRevision.getFile().getVirtualFile();
        if (file != null && file.isValid()) {
          files.add(file);
        }
      }
    }

    files.addAll(getSelectedVirtualFiles(null));

    return VfsUtilCore.toVirtualFileArray(files);
  }
 private void captureUsagesExpandState(TreePath pathFrom, final Collection<UsageState> states) {
   if (!myTree.isExpanded(pathFrom)) {
     return;
   }
   final DefaultMutableTreeNode node = (DefaultMutableTreeNode) pathFrom.getLastPathComponent();
   final int childCount = node.getChildCount();
   for (int idx = 0; idx < childCount; idx++) {
     final TreeNode child = node.getChildAt(idx);
     if (child instanceof UsageNode) {
       final Usage usage = ((UsageNode) child).getUsage();
       states.add(
           new UsageState(
               usage,
               myTree.getSelectionModel().isPathSelected(pathFrom.pathByAddingChild(child))));
     } else {
       captureUsagesExpandState(pathFrom.pathByAddingChild(child), states);
     }
   }
 }
Exemplo n.º 3
0
  private static boolean collectExpandedPathsImpl(
      final JTree tree, final Collection<TreePath> paths, final TreePath path) {
    final TreeModel model = tree.getModel();
    final Object lastPathComponent = path.getLastPathComponent();
    if (model.isLeaf(lastPathComponent)) {
      return false;
    }

    boolean hasExpandedChildren = false;

    for (int i = model.getChildCount(lastPathComponent) - 1; i >= 0; i--) {
      hasExpandedChildren |=
          collectExpandedPathsImpl(
              tree, paths, path.pathByAddingChild(model.getChild(lastPathComponent, i)));
    }

    if (!hasExpandedChildren) {
      paths.add(path);
      return true;
    } else {
      return false;
    }
  }