Class Task

java.lang.Object
ghidra.util.task.Task
All Implemented Interfaces:
MonitoredRunnable
Direct Known Subclasses:
AbstractFileExtractorTask, CalculateLayoutLocationsTask, CompoundTask, CopyTask, DeleteProjectFilesTask, GetDomainObjectTask, GFileSystemLoadKernelTask, GhidraURLQueryTask, ImportBatchTask, MemSearcherTask, OpenProgramTask, PasteFileTask, ProgramTask, ProjectDataDeleteTask, SpecExtensionPanel.ChangeExtensionTask, VersionControlTask

public abstract class Task extends Object implements MonitoredRunnable
Base class for Tasks to be run in separate threads
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected TaskMonitor
     
    protected boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Task(String title)
    Creates new Task.
    Task(String title, boolean canCancel, boolean hasProgress, boolean isModal)
    Construct a new Task.
    Task(String title, boolean canCancel, boolean hasProgress, boolean isModal, boolean waitForTaskCompleted)
    Construct a new Task.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Sets the task listener on this task.
    boolean
    Returns true if the task can be canceled.
    void
     
    int
    Returns the alignment of the text displayed in the modal dialog.
    final String
    Get the title associated with the task
    boolean
    Returns the value of the 'wait for completed task' boolean that was passed into this class
    boolean
    Return true if the task has a progress indicator.
    boolean
     
    boolean
    Returns true if the dialog associated with the task is modal.
    final void
    When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.
    protected void
    notifyTaskListeners(boolean wasCancelled)
     
    abstract void
    run(TaskMonitor monitor)
    This is the method that will be called to do the work
    void
    setHasProgress(boolean b)
    Sets this task to have progress or not.

    Methods inherited from class java.lang.Object

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

    • waitForTaskCompleted

      protected boolean waitForTaskCompleted
    • taskMonitor

      protected TaskMonitor taskMonitor
  • Constructor Details

    • Task

      public Task(String title)
      Creates new Task.
      Parameters:
      title - the title associated with the task
    • Task

      public Task(String title, boolean canCancel, boolean hasProgress, boolean isModal)
      Construct a new Task.
      Parameters:
      title - title the title associated with the task
      canCancel - true means that the user can cancel the task
      hasProgress - true means that the dialog should show a progress indicator
      isModal - true means that the dialog is modal and the task has to complete or be canceled before any other action can occur
    • Task

      public Task(String title, boolean canCancel, boolean hasProgress, boolean isModal, boolean waitForTaskCompleted)
      Construct a new Task.
      Parameters:
      title - title the title associated with the task
      canCancel - true means that the user can cancel the task
      hasProgress - true means that the dialog should show a progress indicator
      isModal - true means that the dialog is modal and the task has to complete or be canceled before any other action can occur
      waitForTaskCompleted - true causes the running thread to block until the finish or cancelled callback has completed on the swing thread. Note: passing true only makes sense if the task is modal.
  • Method Details

    • getTaskTitle

      public final String getTaskTitle()
      Get the title associated with the task
      Returns:
      String title shown in the dialog
    • getStatusTextAlignment

      public int getStatusTextAlignment()
      Returns the alignment of the text displayed in the modal dialog. The default is SwingConstants.CENTER. For status updates where the initial portion of the text does not change, SwingConstants.LEADING is recommended. To change the default value, simply override this method and return one of SwingConstants CENTER, LEADING or TRAILING.
      Returns:
      the alignment of the text displayed
    • getWaitForTaskCompleted

      public boolean getWaitForTaskCompleted()
      Returns the value of the 'wait for completed task' boolean that was passed into this class
      Returns:
      the value
    • monitoredRun

      public final void monitoredRun(TaskMonitor monitor)
      When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.
      Specified by:
      monitoredRun in interface MonitoredRunnable
      Parameters:
      monitor - the task monitor
    • cancel

      public void cancel()
    • isCancelled

      public boolean isCancelled()
    • notifyTaskListeners

      protected void notifyTaskListeners(boolean wasCancelled)
    • run

      public abstract void run(TaskMonitor monitor) throws CancelledException
      This is the method that will be called to do the work

      Note: The run(TaskMonitor) method should not make any calls directly on Swing components, as these calls are not thread safe. Place Swing calls in a Runnable, then call Swing.runLater(Runnable) or Swing.runNow(Runnable)to schedule the Runnable inside of the AWT Event Thread.

      Parameters:
      monitor - The TaskMonitor that will monitor the executing Task
      Throws:
      CancelledException - if the task is cancelled. Subclasses can trigger this exception by calling TaskMonitor.checkCancelled(). This allows them to break out of the current work stack.
    • hasProgress

      public boolean hasProgress()
      Return true if the task has a progress indicator.
      Returns:
      boolean true if the task shows progress
    • setHasProgress

      public void setHasProgress(boolean b)
      Sets this task to have progress or not. Note: changing this value after launching the task will have no effect.
      Parameters:
      b - true to show progress, false otherwise.
    • canCancel

      public boolean canCancel()
      Returns true if the task can be canceled.
      Returns:
      boolean true if the user can cancel the task
    • isModal

      public boolean isModal()
      Returns true if the dialog associated with the task is modal.
      Returns:
      boolean true if the associated dialog is modal
    • addTaskListener

      public void addTaskListener(TaskListener listener)
      Sets the task listener on this task. It is a programming error to call this method more than once or to call this method if a listener was passed into the constructor of this class.
      Parameters:
      listener - the listener