void (@NotNull JTree tree, @NotNull DefaultMutableTreeNode root, @NotNull List<Object> pathsToExpand, @NotNull List<Object> selectionPaths, boolean storeElementsOnly) { TreePath path = new TreePath(root.getPath()); if (tree.isPathSelected(path)){ selectionPaths.add(storeElementsOnly ? ((NodeDescriptor<?>)root.getUserObject()).getElement() : path); } if (tree.isExpanded(path) || root.getChildCount() == 0){ pathsToExpand.add(storeElementsOnly ? ((NodeDescriptor<?>)root.getUserObject()).getElement() : path); _storePaths(tree, root, pathsToExpand, selectionPaths, storeElementsOnly); } }