Class DesktopToolContext

java.lang.Object
uno.anahata.asi.agi.tool.ToolContext
uno.anahata.asi.swing.toolkit.DesktopToolContext
Direct Known Subclasses:
DesktopAgiTool

public class DesktopToolContext extends ToolContext
An advanced execution context that bridges the gap between background tool execution and the Swing Event Dispatch Thread (EDT) or the JavaFX Application Thread.

This class provides the critical infrastructure for Context Propagation. Since the AI toolchain relies on ThreadLocal state for logging and attachments, moving execution to the EDT would normally break these links. DesktopToolContext solves this by capturing the state and re-applying it within the EDT task scope.

Author:
anahata
  • Constructor Details

    • DesktopToolContext

      public DesktopToolContext()
  • Method Details

    • getAgiPanel

      @Internal(value="Gets the Swing AgiPanel for this Agi", requiresCapturedToolContext=false) public AgiPanel getAgiPanel()
      Convenience method to get the AgiPanel for this Agi from the java tool.
      Returns:
      the AgiPanel for the current Agi.
    • runInEdt

      @Internal(value="Executes a task on the Swing EDT with automatic context propagation", requiresCapturedToolContext=false) public void runInEdt(Runnable runnable)
      Executes a task on the EDT in a non-blocking manner while maintaining full context awareness.

      This is the preferred way for tools to perform UI updates without freezing the AI execution thread.

      Parameters:
      runnable - The UI-bound task to execute.
    • runInEdtAndWait

      @Internal(value="Executes a task on the Swing EDT blocking until complete with automatic context propagation", requiresCapturedToolContext=false) public void runInEdtAndWait(Runnable runnable) throws InterruptedException, InvocationTargetException
      Executes a task on the EDT and blocks the current thread until the task is complete, maintaining full context awareness throughout.

      Use this method when subsequent tool logic depends on the UI having reached a specific state (e.g., waiting for a dialog to close or a component to render).

      Parameters:
      runnable - The UI-bound task to execute.
      Throws:
      InterruptedException - if the background thread is interrupted during wait.
      InvocationTargetException - if the EDT task throws an unhandled exception.