Class ContextTreeTableModel

java.lang.Object
org.jdesktop.swingx.treetable.AbstractTreeTableModel
uno.anahata.asi.swing.agi.context.ContextTreeTableModel
All Implemented Interfaces:
TreeModel, org.jdesktop.swingx.treetable.TreeTableModel

public class ContextTreeTableModel extends org.jdesktop.swingx.treetable.AbstractTreeTableModel
A TreeTableModel that provides a hierarchical, JNDI-style view of the entire AI context using unified AbstractContextNodes.

This model is designed for high performance and UI stability. It preserves node identity across refreshes, ensuring that the tree view remains stable (no jumping or collapsing) when the underlying context changes.

It uses a single ContextManagerNode as the root of the hierarchy.

Author:
anahata
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final AgiPanel
    The parent agi panel.

    Fields inherited from class org.jdesktop.swingx.treetable.AbstractTreeTableModel

    modelSupport, root
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new ContextTreeTableModel.
  • Method Summary

    Modifier and Type
    Method
    Description
    getChild(Object parent, int index)
    Implementation details: Delegates to the parent node's getChildren() method.
    int
    Implementation details: Delegates to the parent node's getChildren().size().
    getColumnClass(int column)
    int
    getColumnName(int column)
    int
    getIndexOfChild(Object parent, Object child)
    Implementation details: Performs a standard indexOf search in the child list.
    getValueAt(Object node, int column)
    Implementation details: Delegates value retrieval to the AbstractContextNode based on the column index.
    boolean
    isLeaf(Object node)
    Implementation details: A node is a leaf if its getChildren() list is empty.
    final void
    Refreshes the model's data from the ContextManager and notifies the view of the change.
    void
    Triggers an asynchronous recalculation of token counts for all nodes in the tree.

    Methods inherited from class org.jdesktop.swingx.treetable.AbstractTreeTableModel

    addTreeModelListener, getHierarchicalColumn, getRoot, getTreeModelListeners, isCellEditable, removeTreeModelListener, setValueAt, valueForPathChanged

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • agiPanel

      private final AgiPanel agiPanel
      The parent agi panel.
  • Constructor Details

    • ContextTreeTableModel

      public ContextTreeTableModel(AgiPanel agiPanel)
      Constructs a new ContextTreeTableModel.
      Parameters:
      agiPanel - The parent agi panel.
  • Method Details

    • refresh

      public final void refresh()
      Refreshes the model's data from the ContextManager and notifies the view of the change.

      Implementation details: It preserves the root node instance if it already exists, triggering a recursive refresh of the node hierarchy.

      To prevent the 'jumping' behavior, it uses identity-preserving nodes and fires a structure change event on the root.

    • refreshTokens

      public void refreshTokens(Runnable onDone)
      Triggers an asynchronous recalculation of token counts for all nodes in the tree. Uses SwingTask to run the calculation pass on a background thread.
      Parameters:
      onDone - An optional callback to run on the EDT after the refresh is complete.
    • getColumnCount

      public int getColumnCount()
    • getColumnName

      public String getColumnName(int column)
      Specified by:
      getColumnName in interface org.jdesktop.swingx.treetable.TreeTableModel
      Overrides:
      getColumnName in class org.jdesktop.swingx.treetable.AbstractTreeTableModel
    • getColumnClass

      public Class<?> getColumnClass(int column)
      Specified by:
      getColumnClass in interface org.jdesktop.swingx.treetable.TreeTableModel
      Overrides:
      getColumnClass in class org.jdesktop.swingx.treetable.AbstractTreeTableModel
    • getValueAt

      public Object getValueAt(Object node, int column)
      Implementation details: Delegates value retrieval to the AbstractContextNode based on the column index.
    • getChild

      public Object getChild(Object parent, int index)
      Implementation details: Delegates to the parent node's getChildren() method.
    • getChildCount

      public int getChildCount(Object parent)
      Implementation details: Delegates to the parent node's getChildren().size().
    • getIndexOfChild

      public int getIndexOfChild(Object parent, Object child)
      Implementation details: Performs a standard indexOf search in the child list.
    • isLeaf

      public boolean isLeaf(Object node)
      Implementation details: A node is a leaf if its getChildren() list is empty.
      Specified by:
      isLeaf in interface TreeModel
      Overrides:
      isLeaf in class org.jdesktop.swingx.treetable.AbstractTreeTableModel