Class ContextPanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class ContextPanel extends JPanel
A panel dedicated to displaying and managing the available AI context (history, tools, providers, and resources) using a hierarchical JXTreeTable.

This panel provides a JNDI-style view of the entire AI context. It uses a split-pane layout with a tree table on the left and a detail area on the right that switches panels based on the selected node type.

Author:
anahata
See Also:
  • Field Details

    • agiPanel

      private final AgiPanel agiPanel
      The parent agi panel.
    • agi

      private Agi agi
      The active agi session.
    • treeTable

      private final org.jdesktop.swingx.JXTreeTable treeTable
      The tree table component for the context hierarchy.
    • treeTableModel

      private ContextTreeTableModel treeTableModel
      The model for the tree table.
    • detailContainer

      private final JPanel detailContainer
      Container for the detail panels, using CardLayout for switching.
    • detailLayout

      private final CardLayout detailLayout
      Layout for switching between detail panels.
    • toolPanel

      private final ToolPanel toolPanel
      Panel for displaying tool details.
    • toolkitPanel

      private final ToolkitPanel toolkitPanel
      Panel for displaying toolkit details.
    • providerPanel

      private final ContextProviderPanel providerPanel
      Panel for displaying context provider details.
    • resourcePanel

      private final ResourcePanel resourcePanel
      Panel for displaying V2 resource details.
    • messagePartDetailPanel

      private final ScrollablePanel messagePartDetailPanel
      Container for dynamically created message or part panels.
    • currentSelectedDomainObject

      private Object currentSelectedDomainObject
      The currently selected domain object to prevent redundant rendering.
    • refreshing

      private boolean refreshing
      Flag indicating a refresh is in progress, used to mute selection events and flicker.
    • calculatingTokens

      private boolean calculatingTokens
      Flag indicating token calculation is currently running in the background.
    • customConfigRegistry

      private final Map<Class<?>, BiConsumer<Object,JPanel>> customConfigRegistry
      Registry for mapping domain types to custom UI configurers.
    • historyListener

      private EdtPropertyChangeListener historyListener
      Listener for history changes to trigger tree refreshes.
    • resourcesListener

      private EdtPropertyChangeListener resourcesListener
      Listener for resource changes to trigger tree refreshes.
    • initialized

      private boolean initialized
      Flag to ensure initComponents is only called once.
  • Constructor Details

    • ContextPanel

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

    • createScrollPane

      private JScrollPane createScrollPane(Component component)
      Standardizes a component within a borderless scroll pane.
      Parameters:
      component - The component to wrap.
      Returns:
      The scroll pane.
    • registerDefaultCustomConfigs

      private void registerDefaultCustomConfigs()
      Registers the default configuration UIs for core components.
    • registerCustomConfig

      public <T> void registerCustomConfig(Class<T> type, BiConsumer<T,JPanel> configurer)
      Registers a custom UI configurer for a specific domain object type.
      Type Parameters:
      T - The type of the domain object.
      Parameters:
      type - The class of the domain object.
      configurer - A consumer that populates a provided JPanel based on the object instance.
    • populateCustomConfig

      public void populateCustomConfig(Object obj, JPanel panel)
      Populates a panel with custom configuration UI for a given object, if registered.
      Parameters:
      obj - The domain object (user object of the selected node).
      panel - The target panel to populate.
    • setupListeners

      private void setupListeners()
      Sets up property change listeners for the current agi session.
    • getAgiPanel

      public AgiPanel getAgiPanel()
      Gets the parent agi panel.
      Returns:
      The agi panel.
    • getAgi

      public Agi getAgi()
      Gets the active agi session.
      Returns:
      The agi session.
    • initComponents

      public void initComponents()
      Initializes the components and layout of the panel.
    • setupInteractions

      private void setupInteractions()
      Configures the popup menu and double-click behavior for the tree table.
    • openResource

      private void openResource(Resource res)
      Delegates resource opening to the active ResourceUI strategy.
      Parameters:
      res - The resource to open.
    • applyColumnWidths

      private void applyColumnWidths()
      Authoritatively applies the standard column widths to the tree table. This method ensures the 'Name' column maintains its 400px width and token columns are correctly sized.

      It uses model-to-view conversion to ensure the correct columns are targeted even if the user has reordered or hidden them.

    • applyColumnWidth

      private void applyColumnWidth(int modelIndex, int preferredWidth, int minWidth)
      Helper method to apply width to a specific column identified by its model index.
      Parameters:
      modelIndex - The index of the column in the model.
      preferredWidth - The desired preferred width.
      minWidth - The minimum width (optional, use 0 to skip).
    • updateMessagePartDetail

      private void updateMessagePartDetail(JPanel panel)
      Updates the message/part detail area with the given panel.
      Parameters:
      panel - The panel to display.
    • reload

      public void reload()
      Reloads the panel with the new agi state.
    • refresh

      public final void refresh(boolean structural)
      Refreshes the data in the tree table while preserving expansion state and column widths.
      Parameters:
      structural - If true, the underlying model is rebuilt (e.g. on session switch).
    • getExpandedPaths

      private Set<TreePath> getExpandedPaths()
      Captures the current expansion state of the tree.
      Returns:
      A set of expanded TreePaths.
    • restoreExpandedPaths

      private void restoreExpandedPaths(Set<TreePath> expandedPaths)
      Restores the expansion state of the tree.
      Parameters:
      expandedPaths - The set of paths to expand.
    • refreshTokens

      public void refreshTokens(Runnable onDone)
      Triggers a background recalculation of token counts.
      Parameters:
      onDone - Optional callback to run after tokens are refreshed.
    • refreshTokens

      public void refreshTokens()
      Triggers a background recalculation of token counts (Convenience no-arg version).
    • addNotify

      public void addNotify()
      Triggers an initial refresh when the component is added to the UI.
      Overrides:
      addNotify in class JComponent