/** {@inheritDoc} */ public Object getChild(Object parent, int index) { if(parent == treeRoot) { return treeList.getRoots().get(index); } else { TreeList.Node<E> node = (TreeList.Node<E>)parent; return node.getChildren().get(index); } }
userObject = ((TreeList.Node) value).getElement();
/** * Remove the node at the specified index, firing all the required * notifications. */ private void deleteAndDetachNode(int sourceIndex, List<Node<E>> nodesToVerify) { Node<E> node = data.get(sourceIndex, REAL_NODES).get(); // if it has children, replace it with a virtual copy and schedule that for verification if(!node.isLeaf()) { Node<E> replacement = new Node<E>(node.virtual, new ArrayList<E>(node.path())); replaceNode(node, replacement, true); nodesToVerify.add(replacement); // otherwise delete it directly } else { Node<E> follower = node.next(); deleteNode(node); // remove the parent if necessary in the next iteration nodesToVerify.add(node.parent); // also remove the follower - it may have become redundant as well if(follower != null && follower.virtual) nodesToVerify.add(follower); } }
if(toExpand.isVisible()) { int visibleIndex = data.indexOfNode(toExpand.element, VISIBLE_NODES); updates.addUpdate(visibleIndex); if(shouldBeVisible == descendent.isVisible()) continue; setVisible(descendent, true); int insertIndex = data.indexOfNode(descendent.element, VISIBLE_NODES); updates.elementInserted(insertIndex, descendent.getElement()); updates.elementDeleted(deleteIndex, descendent.getElement()); setVisible(descendent, false);
if(toExpand.isVisible()) { int visibleIndex = data.indexOfNode(toExpand.element, VISIBLE_NODES); updates.addUpdate(visibleIndex); if(shouldBeVisible == descendent.isVisible()) continue; setVisible(descendent, true); int insertIndex = data.indexOfNode(descendent.element, VISIBLE_NODES); updates.elementInserted(insertIndex, descendent.getElement()); updates.elementDeleted(deleteIndex, descendent.getElement()); setVisible(descendent, false);
if(toExpand.isVisible()) { int visibleIndex = data.indexOfNode(toExpand.element, VISIBLE_NODES); updates.addUpdate(visibleIndex); if(shouldBeVisible == descendent.isVisible()) continue; setVisible(descendent, true); int insertIndex = data.indexOfNode(descendent.element, VISIBLE_NODES); updates.elementInserted(insertIndex, descendent.getElement()); updates.elementDeleted(deleteIndex, descendent.getElement()); setVisible(descendent, false);
/** * Delete all virtual parents that no longer have child nodes attached. * This method does not depend upon child nodes being properly configured. */ private void deleteObsoleteVirtualLeaves(List<Node<E>> nodesToVerify) { deleteObsoleteLeaves: for(Iterator<Node<E>> i = nodesToVerify.iterator(); i.hasNext(); ) { Node<E> node = i.next(); // walk up the tree, deleting nodes while(node != null) { // we've reached a real parent, don't delete it! if(!node.virtual) continue deleteObsoleteLeaves; // we've already deleted this parent, we're done if(node.element == null) continue deleteObsoleteLeaves; // this node now has children, don't delete it if(!node.isLeaf()) continue deleteObsoleteLeaves; // if this virtual node has no children, then it's obsolete and // we can delete it right away. Afterwards, we might need to // delete that node's parent deleteNode(node); node = node.parent; } } }
/** * Delete all virtual parents that no longer have child nodes attached. * This method does not depend upon child nodes being properly configured. */ private void deleteObsoleteVirtualLeaves(List<Node<E>> nodesToVerify) { deleteObsoleteLeaves: for(Iterator<Node<E>> i = nodesToVerify.iterator(); i.hasNext(); ) { Node<E> node = i.next(); // walk up the tree, deleting nodes while(node != null) { // we've reached a real parent, don't delete it! if(!node.virtual) continue deleteObsoleteLeaves; // we've already deleted this parent, we're done if(node.element == null) continue deleteObsoleteLeaves; // this node now has children, don't delete it if(!node.isLeaf()) continue deleteObsoleteLeaves; // if this virtual node has no children, then it's obsolete and // we can delete it right away. Afterwards, we might need to // delete that node's parent deleteNode(node); node = node.parent; } } }
/** * Delete all virtual parents that no longer have child nodes attached. * This method does not depend upon child nodes being properly configured. */ private void deleteObsoleteVirtualLeaves(List<Node<E>> nodesToVerify) { deleteObsoleteLeaves: for(Iterator<Node<E>> i = nodesToVerify.iterator(); i.hasNext(); ) { Node<E> node = i.next(); // walk up the tree, deleting nodes while(node != null) { // we've reached a real parent, don't delete it! if(!node.virtual) continue deleteObsoleteLeaves; // we've already deleted this parent, we're done if(node.element == null) continue deleteObsoleteLeaves; // this node now has children, don't delete it if(!node.isLeaf()) continue deleteObsoleteLeaves; // if this virtual node has no children, then it's obsolete and // we can delete it right away. Afterwards, we might need to // delete that node's parent deleteNode(node); node = node.parent; } } }
/** * Lookup the ancestor of this node whose path length is the length * specified. For example, the ancestor of path length 2 of the node * <code>/Users/jessewilson/Desktop/yarbo.mp4</code> is the node * <code>/Users/jessewilson</code>. * * <p>If the ancestor path length is the same as this node's path length, * then this node will be returned. */ private Node<E> ancestorWithPathLength(int ancestorPathLength) { assert(pathLength() >= ancestorPathLength); Node<E> ancestor = this; while(ancestor.pathLength() > ancestorPathLength) { ancestor = ancestor.parent; if(ancestor == null) { throw new IllegalStateException(); } } return ancestor; }
/** master Constructor */ private TreeList(InitializationData<E> initializationData) { super(initializationData.getSource()); this.format = initializationData.format; this.nodeComparator = initializationData.nodeComparator; this.expansionModel = initializationData.expansionModel; this.initializationData = initializationData; // insert the new elements like they were adds NodeAttacher nodeAttacher = new NodeAttacher(false); for(int i = 0; i < super.source.size(); i++) { Node<E> node = super.source.get(i); node.expanded = expansionModel.isExpanded(node.getElement(), node.path); addNode(node, HIDDEN_REAL, i); nodeAttacher.nodesToAttach.queueNewNodeForInserting(node); } // attach siblings and parent nodes nodeAttacher.attachAll(); assert(isValid()); source.addListEventListener(this); }
/** * Lookup the ancestor of this node whose path length is the length * specified. For example, the ancestor of path length 2 of the node * <code>/Users/jessewilson/Desktop/yarbo.mp4</code> is the node * <code>/Users/jessewilson</code>. * * <p>If the ancestor path length is the same as this node's path length, * then this node will be returned. */ private Node<E> ancestorWithPathLength(int ancestorPathLength) { assert(pathLength() >= ancestorPathLength); Node<E> ancestor = this; while(ancestor.pathLength() > ancestorPathLength) { ancestor = ancestor.parent; if(ancestor == null) { throw new IllegalStateException(); } } return ancestor; }
/** master Constructor */ private TreeList(InitializationData<E> initializationData) { super(initializationData.getSource()); this.format = initializationData.format; this.nodeComparator = initializationData.nodeComparator; this.expansionModel = initializationData.expansionModel; this.initializationData = initializationData; // insert the new elements like they were adds NodeAttacher nodeAttacher = new NodeAttacher(false); for(int i = 0; i < super.source.size(); i++) { Node<E> node = super.source.get(i); node.expanded = expansionModel.isExpanded(node.getElement(), node.path); addNode(node, HIDDEN_REAL, i); nodeAttacher.nodesToAttach.queueNewNodeForInserting(node); } // attach siblings and parent nodes nodeAttacher.attachAll(); assert(isValid()); source.addListEventListener(this); }
/** * Remove the node at the specified index, firing all the required * notifications. */ private void deleteAndDetachNode(int sourceIndex, List<Node<E>> nodesToVerify) { Node<E> node = data.get(sourceIndex, REAL_NODES).get(); // if it has children, replace it with a virtual copy and schedule that for verification if(!node.isLeaf()) { Node<E> replacement = new Node<E>(node.virtual, new ArrayList<E>(node.path())); replaceNode(node, replacement, true); nodesToVerify.add(replacement); // otherwise delete it directly } else { Node<E> follower = node.next(); deleteNode(node); // remove the parent if necessary in the next iteration nodesToVerify.add(node.parent); // also remove the follower - it may have become redundant as well if(follower != null && follower.virtual) nodesToVerify.add(follower); } }
/** master Constructor */ private TreeList(InitializationData<E> initializationData) { super(initializationData.getSource()); this.format = initializationData.format; this.nodeComparator = initializationData.nodeComparator; this.expansionModel = initializationData.expansionModel; this.initializationData = initializationData; // insert the new elements like they were adds NodeAttacher nodeAttacher = new NodeAttacher(false); for(int i = 0; i < super.source.size(); i++) { Node<E> node = super.source.get(i); node.expanded = expansionModel.isExpanded(node.getElement(), node.path); addNode(node, HIDDEN_REAL, i); nodeAttacher.nodesToAttach.queueNewNodeForInserting(node); } // attach siblings and parent nodes nodeAttacher.attachAll(); assert(isValid()); source.addListEventListener(this); }
/** * Lookup the ancestor of this node whose path length is the length * specified. For example, the ancestor of path length 2 of the node * <code>/Users/jessewilson/Desktop/yarbo.mp4</code> is the node * <code>/Users/jessewilson</code>. * * <p>If the ancestor path length is the same as this node's path length, * then this node will be returned. */ private Node<E> ancestorWithPathLength(int ancestorPathLength) { assert(pathLength() >= ancestorPathLength); Node<E> ancestor = this; while(ancestor.pathLength() > ancestorPathLength) { ancestor = ancestor.parent; if(ancestor == null) { throw new IllegalStateException(); } } return ancestor; }
/** * Remove the node at the specified index, firing all the required * notifications. */ private void deleteAndDetachNode(int sourceIndex, List<Node<E>> nodesToVerify) { Node<E> node = data.get(sourceIndex, REAL_NODES).get(); // if it has children, replace it with a virtual copy and schedule that for verification if(!node.isLeaf()) { Node<E> replacement = new Node<E>(node.virtual, new ArrayList<E>(node.path())); replaceNode(node, replacement, true); nodesToVerify.add(replacement); // otherwise delete it directly } else { Node<E> follower = node.next(); deleteNode(node); // remove the parent if necessary in the next iteration nodesToVerify.add(node.parent); // also remove the follower - it may have become redundant as well if(follower != null && follower.virtual) nodesToVerify.add(follower); } }
private void expandAll() { if (jTree.getRowCount() > 0) { //Always expand root jTree.expandRow(0); } for (int i = 0; i < jTree.getRowCount(); i++) { //Expand everything TreePath path = jTree.getPathForRow(i); Object object = path.getLastPathComponent(); if (object instanceof TreeList.Node) { TreeList.Node<?> node = (TreeList.Node) object; if (node.getChildren().size() > 5000) { //Ignore nodes with more that 5000 children continue; } } jTree.expandPath(path); } }
/** * Delete the actual node, without unlinking children or unlinking siblings, * which must be handled externally. */ private void deleteNode(Node<E> node) { // remove links to this node from siblings node.detachSiblings(); boolean visible = node.isVisible(); if(visible) { int viewIndex = data.indexOfNode(node.element, VISIBLE_NODES); updates.elementDeleted(viewIndex, node.getElement()); } data.remove(node.element); node.element = null; // null out the element }
/** * Delete the actual node, without unlinking children or unlinking siblings, * which must be handled externally. */ private void deleteNode(Node<E> node) { // remove links to this node from siblings node.detachSiblings(); boolean visible = node.isVisible(); if(visible) { int viewIndex = data.indexOfNode(node.element, VISIBLE_NODES); updates.elementDeleted(viewIndex, node.getElement()); } data.remove(node.element); node.element = null; // null out the element }