private static void selectParent(@NotNull MoveType type, @NotNull JTree tree, boolean canCollapse) {
    TreePath lead = tree.getLeadSelectionPath();
    int row = tree.getRowForPath(lead);
    if (lead == null || row < 0) {
      selectFirst(type, tree);
    }
    else if (canCollapse && tree.isExpanded(lead)) {
      tree.collapsePath(lead);
    }
    else {
      TreePath parent = lead.getParentPath();
      if (parent != null) {
        if (tree.isRootVisible() || null != parent.getParentPath()) {
          select(type, tree, parent);
        }
        else if (row > 0) {
          TreePath path = TreeUtil.previousVisiblePath(tree, row, false, tree::isExpanded);
          select(type, tree, path != null ? path : tree.getPathForRow(0), path == null ? 0 : tree.getRowForPath(path));
        }
      }
    }
  }
private static void selectParent(@NotNull MoveType type, @NotNull JTree tree, boolean canCollapse)