public static int getSelectionCount(@NotNull ChangesTree tree) {
    TreePath[] paths = tree.getSelectionModel().getSelectionPaths();

    List<ChangesBrowserNode<?>> parents = new ArrayList<>();
    for (TreePath path : paths) {
      ChangesBrowserNode<?> node = (ChangesBrowserNode<?>)path.getLastPathComponent();
      if (!node.isLeaf()) {
        parents.add(node);
      }
    }

    int count = 0;

    outer:
    for (TreePath path : paths) {
      ChangesBrowserNode<?> node = (ChangesBrowserNode<?>)path.getLastPathComponent();
      for (ChangesBrowserNode<?> parent : parents) {
        if (isChildNode(parent, node)) continue outer;
      }

      count += node.getFileCount();
    }
    return count;
  }
public static int getSelectionCount(@NotNull ChangesTree tree)