Package ghidra.util.task
Class Task
java.lang.Object
ghidra.util.task.Task
- All Implemented Interfaces:
MonitoredRunnable
- Direct Known Subclasses:
AbstractFileExtractorTask
,CalculateLayoutLocationsTask
,CompoundTask
,CopyTask
,DeleteProjectFilesTask
,GetDomainObjectTask
,GhidraURLQueryTask
,ImportBatchTask
,MemSearcherTask
,OpenProgramTask
,PasteFileTask
,ProgramTask
,ProjectDataDeleteTask
,SpecExtensionPanel.ChangeExtensionTask
,VersionControlTask
Base class for Tasks to be run in separate threads
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addTaskListener
(TaskListener listener) Sets the task listener on this task.boolean
Returns true if the task can be canceled.void
cancel()
int
Returns the alignment of the text displayed in the modal dialog.final String
Get the title associated with the taskboolean
Returns the value of the 'wait for completed task' boolean that was passed into this classboolean
Return true if the task has a progress indicator.boolean
boolean
isModal()
Returns true if the dialog associated with the task is modal.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.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 Details
-
waitForTaskCompleted
protected boolean waitForTaskCompleted -
taskMonitor
-
-
Constructor Details
-
Task
Creates new Task.- Parameters:
title
- the title associated with the task
-
Task
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(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 Details
-
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
-
getWaitForTaskCompleted
public boolean getWaitForTaskCompleted()Returns the value of the 'wait for completed task' boolean that was passed into this class- Returns:
- the value
-
monitoredRun
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() -
isCancelled
public boolean isCancelled() -
notifyTaskListeners
protected void notifyTaskListeners(boolean wasCancelled) -
run
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
Swing.runLater(Runnable)
orSwing.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 callingTaskMonitor.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
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
-