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; }
public void setOpenObjects(Collection<? extends E> opened) { clearOpen(); for (final E node : opened) addOpenObject(node); }
public boolean addOpenObject(E child) { final int[] path = getPath(child); if (path != null && path.length > 0) return addOpenPath(path); return false; }
public void setSelection(Collection<? extends E> selection) { if (isSelectionChanged(selection)) { clearSelection(); for (final E node : selection) addToSelection(node); } }
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 boolean addSelectionPaths(int[][] paths) { boolean added = false; final int len = paths != null ? paths.length : 0; final boolean multiple = isMultiple(); for (int j = 0; j < len; ++j) if (paths[j] != null) { final Path path = new Path(paths[j]); if (multiple) { if (_selection.add(path)) { added = true; fireSelectionChanged(path.path); } } else { if (!_selection.contains(path)) { added = true; clearSelection(); _selection.add(path); fireSelectionChanged(path.path); } break; //done } } return added; }
public boolean addToSelection(E child) { final int[] path = getPath(child); if (path != null && path.length > 0) return addSelectionPath(path); return false; }
/** * 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; }
public boolean addOpenPath(int[] path) { if (path != null && path.length > 0) { final int[][] paths = new int[1][path.length]; paths[0] = path; return addOpenPaths(paths); } return false; }
public boolean addSelectionPath(int[] path) { if (path != null && path.length > 0) { final int[][] paths = new int[1][path.length]; paths[0] = path; return addSelectionPaths(paths); } return false; }
/** * Creates a {@link AbstractTreeModel}. * * @param root * root of tree */ public AbstractTreeModel(E root) { _root = root; //ZK-2611: only for TreeDataEvent.INTERVAL_REMOVED and INTERVAL_ADDED: addTreeDataListener(new TreeDataListener() { public void onChange(TreeDataEvent event) { updatePath(event); invalidatePageCount(); } }); _ctrl = new DefaultSelectionControl(this); }