Class AbstractContextNode<T>

java.lang.Object
uno.anahata.asi.swing.agi.context.AbstractContextNode<T>
Type Parameters:
T - The type of the underlying domain object wrapped by this node.
Direct Known Subclasses:
ContextManagerNode, ContextProviderNode, HistoryNode, MessageNode, PartNode, ResourceNode, ResourcesNode, ToolkitNode, ToolManagerNode, ToolNode, ToolsNode

public abstract class AbstractContextNode<T> extends Object
The base class for all nodes in the hierarchical context tree.

This class provides a unified interface for the ContextTreeTableModel to interact with different types of domain objects (Providers, Toolkits, Tools) while maintaining a consistent JNDI-style view.

It implements a hierarchical token aggregation system and an identity-preserving child synchronization mechanism to ensure UI stability during refreshes.

Author:
anahata
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final AgiPanel
    The parent agi panel.
    The cached list of child nodes.
    protected int
    Cached declaration token count (including children).
    protected int
    Cached history token count (including children).
    protected int
    Cached instruction token count (including children).
    protected int
    Cached RAG token count (including children).
    protected String
    Cached status string.
    protected final T
    The underlying domain object.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract void
    Calculates the token counts for this node's own content (excluding children).
    protected abstract AbstractContextNode<?>
    createChildNode(Object userObject)
    Creates a new child node for the given domain object.
    boolean
    Equality is based on the underlying userObject and the node class.
    protected abstract List<?>
    Fetches the current list of domain objects that should be represented as children of this node.
    Gets the parent agi session.
    Gets the list of child nodes for this node.
    abstract String
    Gets a detailed description of the node's purpose or content.
    Gets an optional icon for this node by delegating to the IconProvider configured in the agi session.
    abstract String
    Gets the human-readable display name for this node.
    int
    abstract boolean
    Checks if the underlying domain object is currently active in the context.
    final void
    Refreshes the node's state, including its child list and token counts.
    final void
    Recursively recalculates token counts and status for this node and its descendants.
    final void
    Deprecated.
    Use refresh() instead for a unified update.
    Returns the display name of the node.
    protected abstract void
    Updates the status string for this node.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • agiPanel

      protected final AgiPanel agiPanel
      The parent agi panel.
    • userObject

      protected final T userObject
      The underlying domain object.
    • children

      protected List<AbstractContextNode<?>> children
      The cached list of child nodes.
    • instructionsTokens

      protected int instructionsTokens
      Cached instruction token count (including children).
    • declarationsTokens

      protected int declarationsTokens
      Cached declaration token count (including children).
    • historyTokens

      protected int historyTokens
      Cached history token count (including children).
    • ragTokens

      protected int ragTokens
      Cached RAG token count (including children).
    • status

      protected String status
      Cached status string.
  • Constructor Details

    • AbstractContextNode

      public AbstractContextNode()
  • Method Details

    • getAgi

      public Agi getAgi()
      Gets the parent agi session.
      Returns:
      The agi session.
    • getName

      public abstract String getName()
      Gets the human-readable display name for this node.
      Returns:
      The name to be displayed in the tree.
    • getDescription

      public abstract String getDescription()
      Gets a detailed description of the node's purpose or content.
      Returns:
      The description string.
    • getChildren

      public final List<AbstractContextNode<?>> getChildren()
      Gets the list of child nodes for this node. Implementation details: Returns the cached child list, initializing it via refresh() if necessary.
      Returns:
      A list of child AbstractContextNodes.
    • refresh

      public final void refresh()
      Refreshes the node's state, including its child list and token counts.

      This method implements an identity-preserving synchronization logic: it updates the child list by reusing existing node instances for domain objects that are still present.

    • refreshData

      public final void refreshData()
      Recursively recalculates token counts and status for this node and its descendants. This method is designed to be called from a background thread via SwingTask.
    • fetchChildObjects

      protected abstract List<?> fetchChildObjects()
      Fetches the current list of domain objects that should be represented as children of this node.
      Returns:
      A list of domain objects.
    • createChildNode

      protected abstract AbstractContextNode<?> createChildNode(Object userObject)
      Creates a new child node for the given domain object.
      Parameters:
      userObject - The domain object to wrap.
      Returns:
      A new AbstractContextNode, or null if the object type is not supported.
    • refreshTokens

      @Deprecated public final void refreshTokens()
      Deprecated.
      Use refresh() instead for a unified update.
      Recalculates and caches the token counts and status for this node and all its descendants.
    • calculateLocalTokens

      protected abstract void calculateLocalTokens()
      Calculates the token counts for this node's own content (excluding children).
    • updateStatus

      protected abstract void updateStatus()
      Updates the status string for this node.
    • getIcon

      public Icon getIcon()
      Gets an optional icon for this node by delegating to the IconProvider configured in the agi session.
      Returns:
      The icon, or null if no specialized icon is available.
    • isActive

      public abstract boolean isActive()
      Checks if the underlying domain object is currently active in the context.

      Subclasses override this method to define their specific active-state policy, allowing for clean, polymorphic evaluation without dirty instanceof chains.

      Returns:
      true if active, false otherwise.
    • equals

      public boolean equals(Object o)
      Equality is based on the underlying userObject and the node class.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Returns the display name of the node.
      Overrides:
      toString in class Object