コード例 #1
0
  /** Sent to completely rebuild the visible tree. All nodes are collapsed. */
  private void rebuild(boolean clearSelection) {
    Object rootUO;

    treePathMapping.clear();
    if (treeModel != null && (rootUO = treeModel.getRoot()) != null) {
      root = createNodeForValue(rootUO, 0);
      root.path = new TreePath(rootUO);
      addMapping(root);
      if (isRootVisible()) {
        rowCount = 1;
        root.row = 0;
      } else {
        rowCount = 0;
        root.row = -1;
      }
      root.expand();
    } else {
      root = null;
      rowCount = 0;
    }
    if (clearSelection && treeSelectionModel != null) {
      treeSelectionModel.clearSelection();
    }
    this.visibleNodesChanged();
  }
コード例 #2
0
    /**
     * Creates a new node to represent <code>userObject</code>. This does NOT check to ensure there
     * isn't already a child node to manage <code>userObject</code>.
     */
    protected FHTreeStateNode createChildFor(Object userObject) {
      int newChildIndex = treeModel.getIndexOfChild(getUserObject(), userObject);

      if (newChildIndex < 0) return null;

      FHTreeStateNode aNode;
      FHTreeStateNode child = createNodeForValue(userObject, newChildIndex);
      int childRow;

      if (isVisible()) {
        childRow = getRowToModelIndex(newChildIndex);
      } else {
        childRow = -1;
      }
      child.row = childRow;
      for (int counter = 0, maxCounter = getChildCount(); counter < maxCounter; counter++) {
        aNode = (FHTreeStateNode) getChildAt(counter);
        if (aNode.childIndex > newChildIndex) {
          insert(child, counter);
          return child;
        }
      }
      add(child);
      return child;
    }
コード例 #3
0
    /**
     * 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;
    }
コード例 #4
0
    // 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;
      }
    }