edu.rice.cs.util.swing
Class AsyncTaskLauncher

java.lang.Object
  extended by edu.rice.cs.util.swing.AsyncTaskLauncher

public abstract class AsyncTaskLauncher
extends Object

The base class of the component that launches an AsyncTask. It manages the multi-threading and ensures that the correct methods of the task are performed on the correct thread.

Author:
jlugo

Constructor Summary
AsyncTaskLauncher()
           
 
Method Summary
protected abstract  IAsyncProgress createProgressMonitor(String description, int min, int max)
          Creates a progress monitor that can be used to provide feedback to the user during the asynchronous task.
<P,R> void
executeTask(AsyncTask<P,R> task, P param, boolean showProgress, boolean lockUI)
          Executes the AsyncTask in its own thread after performing any needed steps to prepare the UI for its execution.
protected abstract  void setParentContainerEnabled(boolean enabled)
          Sets the enabled state of the parent component.
protected abstract  boolean shouldSetEnabled()
          Returns whether the launcher should call setParentContainerEnabled both to disable and to re-enable the parent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncTaskLauncher

public AsyncTaskLauncher()
Method Detail

shouldSetEnabled

protected abstract boolean shouldSetEnabled()
Returns whether the launcher should call setParentContainerEnabled both to disable and to re-enable the parent. This facility gives launchers more control over the view in case dissabling or re-enabling the view produces inconsistent behavior.

In some cases, this method should always return true, e.g., when for each call to lock the UI, you must call the unlock method an equal number of times to actually unlock the frame. If this were dissabling a normal swing component, where can only be on/off, you wouldn't want to re-enable the component if it was already disabled.

Returns:
whether the launcher should call setParentContainerEnabled

setParentContainerEnabled

protected abstract void setParentContainerEnabled(boolean enabled)
Sets the enabled state of the parent component. When the parent component is dissabled, the user cannot invoke any operations via mouse clicks or key strokes. Note: this method only runs in the event thread.

Parameters:
enabled - Whether the parent container should be enabled

createProgressMonitor

protected abstract IAsyncProgress createProgressMonitor(String description,
                                                        int min,
                                                        int max)
Creates a progress monitor that can be used to provide feedback to the user during the asynchronous task. This progress monitor can also be used to allow the user to request the task to be canceled.

This method only executes in the event-handling thread.

Returns:
The progress monitor used to provide feedback.

executeTask

public <P,R> void executeTask(AsyncTask<P,R> task,
                              P param,
                              boolean showProgress,
                              boolean lockUI)
Executes the AsyncTask in its own thread after performing any needed steps to prepare the UI for its execution.

Type Parameters:
R - The type of result to pass from runAsync to complete
Parameters:
task - The task to execute on its own worker thread
showProgress - Whether the progress monitor should be displayed to the user. If it is false, the user will not be able to make any cancelation requests to the task.
lockUI - Whether the user should be able to interact with the rest of the UI while the task is in progress.