/** * 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; } } }
private Node<E> deleteVirtualAncestryRootDown(Node<E> previous, Node<E> parent) { Node<E> replacementLastSibling = previous.ancestorWithPathLength(parent.pathLength() + 1); assert(replacementLastSibling.siblingAfter == null); Node<E> replacement = replacementLastSibling.parent; // merge expand/collapse state first if(replacement.expanded && !parent.expanded) { setExpanded(parent, true); } else if(parent.expanded && !replacement.expanded) { setExpanded(replacement, true); } // link the children of the two parents as siblings Node<E> parentFirstChild = parent.firstChild(); assert(parentFirstChild == null || parentFirstChild.siblingBefore == null); replacementLastSibling.siblingAfter = parentFirstChild; if(parentFirstChild != null) parentFirstChild.siblingBefore = replacementLastSibling; // point all children at the new parent for(Node<E> child = parentFirstChild; child != null; child = child.siblingAfter) { child.parent = replacement; } // remove the parent itself deleteNode(parent); // next up for potential deletion is the child of this parent return parentFirstChild; }
private Node<E> deleteVirtualAncestryRootDown(Node<E> previous, Node<E> parent) { Node<E> replacementLastSibling = previous.ancestorWithPathLength(parent.pathLength() + 1); assert(replacementLastSibling.siblingAfter == null); Node<E> replacement = replacementLastSibling.parent; // merge expand/collapse state first if(replacement.expanded && !parent.expanded) { setExpanded(parent, true); } else if(parent.expanded && !replacement.expanded) { setExpanded(replacement, true); } // link the children of the two parents as siblings Node<E> parentFirstChild = parent.firstChild(); assert(parentFirstChild == null || parentFirstChild.siblingBefore == null); replacementLastSibling.siblingAfter = parentFirstChild; if(parentFirstChild != null) parentFirstChild.siblingBefore = replacementLastSibling; // point all children at the new parent for(Node<E> child = parentFirstChild; child != null; child = child.siblingAfter) { child.parent = replacement; } // remove the parent itself deleteNode(parent); // next up for potential deletion is the child of this parent return parentFirstChild; }
private Node<E> deleteVirtualAncestryRootDown(Node<E> previous, Node<E> parent) { Node<E> replacementLastSibling = previous.ancestorWithPathLength(parent.pathLength() + 1); assert(replacementLastSibling.siblingAfter == null); Node<E> replacement = replacementLastSibling.parent; // merge expand/collapse state first if(replacement.expanded && !parent.expanded) { setExpanded(parent, true); } else if(parent.expanded && !replacement.expanded) { setExpanded(replacement, true); } // link the children of the two parents as siblings Node<E> parentFirstChild = parent.firstChild(); assert(parentFirstChild == null || parentFirstChild.siblingBefore == null); replacementLastSibling.siblingAfter = parentFirstChild; if(parentFirstChild != null) parentFirstChild.siblingBefore = replacementLastSibling; // point all children at the new parent for(Node<E> child = parentFirstChild; child != null; child = child.siblingAfter) { child.parent = replacement; } // remove the parent itself deleteNode(parent); // next up for potential deletion is the child of this parent return parentFirstChild; }
/** * 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); } }
/** * 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); } }
/** * 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); } }