public class TaskMonitor extends AbstractBean
TaskMonitor
provides an overview of all
the ApplicationContext's Tasks, as well as the state of a single
foreground
Task.
The value of getTasks()
is a list of all of the
Tasks
whose state is not DONE
for all of the
ApplicationContext's TaskServices
. In other words: all of
the ApplicationContext's background tasks that haven't finished
executing. Each time a new TaskService Task is executed it's added
to the list; when the Task finishes it's removed. Each time the
list changes PropertyChangeListeners
are fired.
Applications that wish to create a detailed visualization of all
Tasks should monitor the TaskMonitor "tasks"
property.
Users are often only interested in the status of a single
foreground task, typically the one associated with GUI
element they're working with, or with the most recent command
they've issued. The TaskMonitor's PropertyChangeListener is
notified each time a property of the foregroundTask
changes. Additionally the TaskMonitor fires
synthetic PropertyChangeEvents for properties named "pending",
"started", and "done" when the corresponding Task state
property changes occur.
TaskMonitor manages a queue of new Tasks. The
foregroundTask is automatically set to the first new Task, and when
that Task finishes, the next Task in the queue, and so on.
Applications can set the foregroundTask explicitly, to better
reflect what the user is doing. For example, a tabbed browsing GUI
that launched one Task per tab might set the foreground Task each
time the user selected a tab. To prevent the foregroundTask
property from (ever) being reset automatically, one must set autoUpdateForegroundTask
to false.
This class is not thread-safe. All of its methods must be called on the event dispatching thread (EDT) and all of its listeners will run on the EDT.
ApplicationContext.getTaskServices()
,
TaskService.getTasks()
,
TaskService.execute(org.jdesktop.application.Task)
Modifier and Type | Field and Description |
---|---|
static String |
PROP_FOREGROUND_TASK |
Constructor and Description |
---|
TaskMonitor(ApplicationContext context)
Construct a TaskMonitor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
getAutoUpdateForegroundTask()
True if the
foregroundTask property should be automatically
reset to the oldest Task in the queue when it finishes running. |
Task |
getForegroundTask()
Indicates the
Task whose status the ApplicationContext's GUI wants
to be displayed, typically in the main window's status bar. |
List<Task> |
getTasks()
All of the Application Tasks whose
state is not DONE . |
void |
setAutoUpdateForegroundTask(boolean autoUpdateForegroundTask)
True if the
foregroundTask property should be automatically
reset to the oldest Task in the queue when it finishes running. |
void |
setForegroundTask(Task foregroundTask)
The TaskMonitor's PropertyChangeListeners are fired each time
any property of the the
foregroundTask changes. |
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
public static final String PROP_FOREGROUND_TASK
public TaskMonitor(ApplicationContext context)
context
- public void setForegroundTask(Task foregroundTask)
foregroundTask
changes. By
default this property is set to the first Task to be executed
and then, when that Task finishes, reset to the next most
recently executed Task. If the autoUpdateForegroundTask
is false, then the foregroundTask
property is not reset automatically.foregroundTask
- the task whose properties are reflected by this classsetAutoUpdateForegroundTask(boolean)
,
getForegroundTask()
public Task getForegroundTask()
Task
whose status the ApplicationContext's GUI wants
to be displayed, typically in the main window's status bar.setForegroundTask(org.jdesktop.application.Task)
public boolean getAutoUpdateForegroundTask()
foregroundTask
property should be automatically
reset to the oldest Task in the queue when it finishes running.
This property is true by default.
setAutoUpdateForegroundTask(boolean)
,
setForegroundTask(org.jdesktop.application.Task)
public void setAutoUpdateForegroundTask(boolean autoUpdateForegroundTask)
foregroundTask
property should be automatically
reset to the oldest Task in the queue when it finishes running. An
application that wants explicit control over the Task being monitored
can set this property to false.
This property is true by default.
autoUpdateForegroundTask
- true if the foregroundTask should be set automaticallygetAutoUpdateForegroundTask()
public List<Task> getTasks()
state
is not DONE
.
Each time the list of Tasks changes, a PropertyChangeEvent for the property named "tasks" is fired. Applications that want to monitor all background Tasks should monitor the tasks property.
DONE
Copyright © 2009–2019. All rights reserved.