Class 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.

    See Also:
    ApplicationContext.getTaskServices(), TaskService.getTasks(), TaskService.execute(org.jdesktop.application.Task)
    • Constructor Detail

      • TaskMonitor

        public TaskMonitor​(ApplicationContext context)
        Construct a TaskMonitor.
    • Method Detail

      • 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)
      • 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 java.util.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