private void getChildNodes(List<E> all, E parent) { for (int i = 0, j = getChildNodeCount(parent); i < j; i++) { E child = getChild(parent, i); if (child != null) { all.add(child); getChildNodes(all, child); } } }
private int getChildNodeCount(E node) { int c = getChildCount(node); int count = c; for (int i = 0; i < c; i++) { E child = getChild(node, i); if (isPathOpened(getPath(child))) { count += getChildNodeCount(child); } } return count; }
/** A utility that the deriving class can call to save the states * before sorting the model. * <p>Default: saves the selection and open states. * <p>For example, {@link DefaultTreeModel#sort} invokes it to preserve * the selection to the same objects (rather than the same paths). * @since 6.0.0 */ protected Object beforeSort() { final States<E> states = new States<E>(); for (final Path path : _selection) states.selection.add(getChild(path.path)); for (final Path path : _opens) states.opens.add(getChild(path.path)); return states; }
public Set<E> getSelection() { final Set<E> selected = new LinkedHashSet<E>(); int[][] paths = getSelectionPaths(); if (paths != null) for (int i = 0; i < paths.length; i++) selected.add(getChild(paths[i])); return selected; }
public Set<E> getOpenObjects() { final Set<E> opened = new LinkedHashSet<E>(); int[][] paths = getOpenPaths(); if (paths != null) for (int i = 0; i < paths.length; i++) opened.add(getChild(paths[i])); return opened; }
private boolean dfSearch(List<Integer> path, E node, E target) { if (node.equals(target)) return true; for (int i = 0, size = _childCount(node); i < size; i++) if (dfSearch(path, getChild(node, i), target)) { path.add(0, new Integer(i)); return true; } return false; }
public E getChild(int[] path) { E node = getRoot(); for (int childCount = 0, i = 0; i < path.length && node != null; i++) { if (path[i] < 0 || path[i] > (childCount = _childCount(node))) return null; node = getChild(node, path[i]); } return node; }
/** * Returns the index of child in parent. If either parent or child is null, * returns -1. If either parent or child don't belong to this tree model, * returns -1. * <p> * The default implementation iterates through all children of * <code>parent</code> by invoking, and check if <code>child</code> is part * of them. You could override it if you have a better algorithm. * {@link #getChild} * * @param parent * a node in the tree, obtained from this data source * @param child * the node we are interested in * @return the index of the child in the parent, or -1 if either child or * parent are null or don't belong to this tree model * @since 5.0.6 */ public int getIndexOfChild(E parent, E child) { final int cnt = _childCount(parent); for (int j = 0; j < cnt; ++j) if (Objects.equals(child, getChild(parent, j))) return j; return -1; }