/** * Sets the receivers row to <code>nextRow</code> and recursively updates all the children of * the receivers rows. The index the next row is to be placed as is returned. */ protected int setRowAndChildren(int nextRow) { row = nextRow; if (!isExpanded()) return row + 1; int lastRow = row + 1; int lastModelIndex = 0; FHTreeStateNode child; int maxCounter = getChildCount(); for (int counter = 0; counter < maxCounter; counter++) { child = (FHTreeStateNode) getChildAt(counter); lastRow += (child.childIndex - lastModelIndex); lastModelIndex = child.childIndex + 1; if (child.isExpanded) { lastRow = child.setRowAndChildren(lastRow); } else { child.row = lastRow++; } } return lastRow + childCount - lastModelIndex; }
// This can be rather expensive, but is needed for the collapse // case this is resulting from a remove (although I could fix // that by having instances of FHTreeStateNode hold a ref to // the number of children). I prefer this though, making determing // the row of a particular node fast is very nice! protected void resetChildrenRowsFrom(int newRow, int childIndex, int modelIndex) { int lastRow = newRow; int lastModelIndex = modelIndex; FHTreeStateNode node; int maxCounter = getChildCount(); for (int counter = childIndex; counter < maxCounter; counter++) { node = (FHTreeStateNode) getChildAt(counter); lastRow += (node.childIndex - lastModelIndex); lastModelIndex = node.childIndex + 1; if (node.isExpanded) { lastRow = node.setRowAndChildren(lastRow); } else { node.row = lastRow++; } } lastRow += childCount - lastModelIndex; node = (FHTreeStateNode) getParent(); if (node != null) { node.resetChildrenRowsFrom(lastRow, node.getIndex(this) + 1, this.childIndex + 1); } else { // This is the root, reset total ROWCOUNT! rowCount = lastRow; } }