Package org.praxislive.ide.core.api
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
A base implementation of a Task.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA base implementation of a task with a result.Nested classes/interfaces inherited from interface org.praxislive.ide.core.api.Task
Task.State -
Field Summary
Fields inherited from interface org.praxislive.ide.core.api.Task
PROP_STATE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAdd a property change listener.final booleancancel()final Task.Stateexecute()Initiate execution of the task.final Task.StategetState()Query the current task state.protected booleanIf the task is cancellable, this method should be overridden and handle any necessary steps, returningtrueif the task has been cancelled.protected abstract voidHandle a call to execution.final voidRemove a property change listener.protected final voidupdateState(Task.State newState) Update the task state.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.praxislive.ide.core.api.Task
description, log
-
Constructor Details
-
AbstractTask
protected AbstractTask()
-
-
Method Details
-
execute
Description copied from interface:TaskInitiate execution of the task. This method returnsTask.State.RUNNINGwhen 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
IllegalStateExceptionif the task state is notTask.State.NEW. -
getState
Description copied from interface:TaskQuery the current task state. -
addPropertyChangeListener
Description copied from interface:TaskAdd a property change listener.- Specified by:
addPropertyChangeListenerin interfaceTask- Parameters:
listener- property change listener
-
removePropertyChangeListener
Description copied from interface:TaskRemove a property change listener.- Specified by:
removePropertyChangeListenerin interfaceTask- Parameters:
listener- property change listener
-
cancel
public final boolean cancel()- Specified by:
cancelin interfaceorg.openide.util.Cancellable
-
updateState
Update the task state.- Parameters:
newState- new state- Throws:
IllegalStateException- if new state is not valid
-
handleExecute
Handle a call to execution. The state will have been updated toTask.State.RUNNINGprior to this method. This method should callupdateState(org.praxislive.ide.core.api.Task.State)to change the state returned fromexecute(), or update the state at a later point. If this method throws an exception, the task will be set to theTask.State.ERRORstate.- 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, returningtrueif the task has been cancelled. The state will be updated automatically.- Returns:
- true to have task marked as cancelled
-