Package org.jdesktop.application

# Class TaskMonitor

java.lang.Object
org.jdesktop.application.AbstractBean
org.jdesktop.application.TaskMonitor

public class TaskMonitor extends AbstractBean
This class is intended to serve as the model for GUI components, like status bars, that display the state of an application's background tasks. `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.

Author:
  Hans Muller (Hans.Muller@Sun.COM)
See Also:
  - `ApplicationContext.getTaskServices()`
  - `TaskService.getTasks()`
  - `TaskService.execute(org.jdesktop.application.Task)`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`PROP_FOREGROUND_TASK`

## Constructor Summary

Constructors
Constructor
Description
`TaskMonitor(ApplicationContext context)`
Construct a TaskMonitor.

## Method Summary

Modifier and Type
Method
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.

### Methods inherited from class org.jdesktop.application.AbstractBean

`addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### PROP_FOREGROUND_TASK

public static final String PROP_FOREGROUND_TASK

See Also:
  - Constant Field Values

## Constructor Details

### TaskMonitor

public TaskMonitor(ApplicationContext context)
Construct a TaskMonitor.

Parameters:
  `context` -

## Method Details

### setForegroundTask

public void setForegroundTask(Task foregroundTask)
The TaskMonitor's PropertyChangeListeners are fired each time any property of the the `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.

Parameters:
  `foregroundTask` - the task whose properties are reflected by this class
See Also:
  - `setAutoUpdateForegroundTask(boolean)`
  - `getForegroundTask()`

### getForegroundTask

public Task getForegroundTask()
Indicates the `Task` whose status the ApplicationContext's GUI wants to be displayed, typically in the main window's status bar.

Returns:
  the value of the foregroundTask property.
See Also:
  - `setForegroundTask(org.jdesktop.application.Task)`

### getAutoUpdateForegroundTask

public boolean getAutoUpdateForegroundTask()
True if the `foregroundTask` property should be automatically reset to the oldest Task in the queue when it finishes running.

This property is true by default.

Returns:
  true if the foregroundTask should be set automatically.
See Also:
  - `setAutoUpdateForegroundTask(boolean)`
  - `setForegroundTask(org.jdesktop.application.Task)`

### setAutoUpdateForegroundTask

public void setAutoUpdateForegroundTask(boolean autoUpdateForegroundTask)
True if the `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.

Parameters:
  `autoUpdateForegroundTask` - true if the foregroundTask should be set automatically
See Also:
  - `getAutoUpdateForegroundTask()`

### getTasks

public List<Task> getTasks()
All of the Application Tasks whose `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.

Returns:
  a list of all Tasks that aren't `DONE`