Class AbstractTask

java.lang.Object
org.praxislive.ide.core.api.AbstractTask
All Implemented Interfaces:
org.openide.util.Cancellable, Task
Direct Known Subclasses:
AbstractTask.WithResult, SerialTasks

public abstract class AbstractTask extends Object implements Task
A base implementation of a Task.
  • Constructor Details

    • AbstractTask

      protected AbstractTask()
  • Method Details

    • execute

      public final Task.State execute()
      Description copied from interface: Task
      Initiate execution of the task. This method returns Task.State.RUNNING when the task is running asynchronous operations. The caller may add a property listener if it needs to know when and how those operations complete.

      A task can only be executed once. This method will throw an IllegalStateException if the task state is not Task.State.NEW.

      Specified by:
      execute in interface Task
      Returns:
      task state
    • getState

      public final Task.State getState()
      Description copied from interface: Task
      Query the current task state.
      Specified by:
      getState in interface Task
      Returns:
      task state
    • addPropertyChangeListener

      public final void addPropertyChangeListener(PropertyChangeListener listener)
      Description copied from interface: Task
      Add a property change listener.
      Specified by:
      addPropertyChangeListener in interface Task
      Parameters:
      listener - property change listener
    • removePropertyChangeListener

      public final void removePropertyChangeListener(PropertyChangeListener listener)
      Description copied from interface: Task
      Remove a property change listener.
      Specified by:
      removePropertyChangeListener in interface Task
      Parameters:
      listener - property change listener
    • cancel

      public final boolean cancel()
      Specified by:
      cancel in interface org.openide.util.Cancellable
    • updateState

      protected final void updateState(Task.State newState)
      Update the task state.
      Parameters:
      newState - new state
      Throws:
      IllegalStateException - if new state is not valid
    • handleExecute

      protected abstract void handleExecute() throws Exception
      Handle a call to execution. The state will have been updated to Task.State.RUNNING prior to this method. This method should call updateState(org.praxislive.ide.core.api.Task.State) to change the state returned from execute(), or update the state at a later point. If this method throws an exception, the task will be set to the Task.State.ERROR state.
      Throws:
      Exception - if the task cannot be executed
    • handleCancel

      protected boolean handleCancel()
      If the task is cancellable, this method should be overridden and handle any necessary steps, returning true if the task has been cancelled. The state will be updated automatically.
      Returns:
      true to have task marked as cancelled