Package ghidra.util.task
Class Task
- java.lang.Object
-
- ghidra.util.task.Task
-
- All Implemented Interfaces:
MonitoredRunnable
- Direct Known Subclasses:
AbstractFileExtractorTask
,CalculateLayoutLocationsTask
,ClassSearchTask
,CompoundTask
,CopyTask
,DeleteProjectFilesTask
,GetVersionedObjectTask
,GFileSystemLoadKernelTask
,ImportBatchTask
,InvokeInSwingTask
,MemSearcherTask
,OpenProgramTask
,PasteFileTask
,ProgramTask
,ProjectDataDeleteTask
,VersionControlTask
public abstract class Task extends java.lang.Object implements MonitoredRunnable
Base class for Tasks to be run in separate threads
-
-
Field Summary
Fields Modifier and Type Field Description protected TaskMonitor
taskMonitor
protected boolean
waitForTaskCompleted
-
Constructor Summary
Constructors Constructor Description Task(java.lang.String title)
Creates new Task.Task(java.lang.String title, boolean canCancel, boolean hasProgress, boolean isModal)
Construct a new Task.Task(java.lang.String title, boolean canCancel, boolean hasProgress, boolean isModal, boolean waitForTaskCompleted)
Construct a new Task.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addTaskListener(TaskListener listener)
Sets the task listener on this task.boolean
canCancel()
Returns true if the task can be canceled.void
cancel()
int
getStatusTextAlignment()
Returns the alignment of the text displayed in the modal dialog.java.lang.String
getTaskTitle()
Get the title associated with the taskboolean
hasProgress()
Return true if the task has a progress indicator.boolean
isModal()
Returns true if the dialog associated with the task is modal.void
monitoredRun(TaskMonitor monitor)
When an object implementing interfaceRunnable
is used to create a thread, starting the thread causes the object'srun
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 workvoid
setHasProgress(boolean b)
Sets this task to have progress or not.
-
-
-
Field Detail
-
waitForTaskCompleted
protected boolean waitForTaskCompleted
-
taskMonitor
protected TaskMonitor taskMonitor
-
-
Constructor Detail
-
Task
public Task(java.lang.String title)
Creates new Task.- Parameters:
title
- the title associated with the task
-
Task
public Task(java.lang.String title, boolean canCancel, boolean hasProgress, boolean isModal)
Construct a new Task.- Parameters:
title
- title the title associated with the taskcanCancel
- true means that the user can cancel the taskhasProgress
- true means that the dialog should show a progress indicatorisModal
- 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(java.lang.String title, boolean canCancel, boolean hasProgress, boolean isModal, boolean waitForTaskCompleted)
Construct a new Task.- Parameters:
title
- title the title associated with the taskcanCancel
- true means that the user can cancel the taskhasProgress
- true means that the dialog should show a progress indicatorisModal
- true means that the dialog is modal and the task has to complete or be canceled before any other action can occurwaitForTaskCompleted
- 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 Detail
-
getTaskTitle
public final java.lang.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 isSwingConstants.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 ofSwingConstants
CENTER, LEADING or TRAILING.- Returns:
- the alignment of the text displayed
-
monitoredRun
public final void monitoredRun(TaskMonitor monitor)
When an object implementing interfaceRunnable
is used to create a thread, starting the thread causes the object'srun
method to be called in that separately executing thread.- Specified by:
monitoredRun
in interfaceMonitoredRunnable
- Parameters:
monitor
- the task monitor
-
cancel
public void cancel()
-
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 workNote: 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
SystemUtilities.runSwingLater(Runnable)
orSystemUtilities.runSwingNow(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 callingTaskMonitor.checkCanceled()
. 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
-
-