org.progeeks.cmd.swing
Class WorkerCommand

java.lang.Object
  extended by org.progeeks.cmd.swing.WorkerCommand
All Implemented Interfaces:
java.io.Serializable, Command, ViewCommand

public abstract class WorkerCommand
extends java.lang.Object
implements ViewCommand

Implementation of the ViewCommand interface that will first run as a background command and then redispatch itself as a foreground command. Each mode has a different abstract method that can be overridden. This command is useful in cases where a background job needs to be done and then subsequently update a UI component.

Version:
$Revision: 1.1 $
Author:
Paul Speed
See Also:
Serialized Form

Constructor Summary
protected WorkerCommand()
           
 
Method Summary
 Result execute(Environment env)
          Overridden to call the executeBackground() method when running in the background and executeForeground() when running in the foregroung.
protected abstract  Result executeBackground(Environment env)
          Called when running the background.
protected abstract  Result executeForeground(Environment env)
          Called when running the foreground on the AWT/Swing thread.
 boolean isForeground()
          Returns true if the command should be run on the swing event dispatcher thread.
 void reset()
          Resets the command to its background status so that it can be executed again.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WorkerCommand

protected WorkerCommand()
Method Detail

reset

public void reset()
Resets the command to its background status so that it can be executed again.


isForeground

public boolean isForeground()
Returns true if the command should be run on the swing event dispatcher thread.

Specified by:
isForeground in interface ViewCommand

executeForeground

protected abstract Result executeForeground(Environment env)
Called when running the foreground on the AWT/Swing thread.


executeBackground

protected abstract Result executeBackground(Environment env)
Called when running the background.


execute

public Result execute(Environment env)
Overridden to call the executeBackground() method when running in the background and executeForeground() when running in the foregroung. After calling executeBackground() the foreground flag is set to true and the command is redispatched.

Specified by:
execute in interface Command
Parameters:
env - The environment within which the command is running.
Returns:
A result container or null if the command does not return a result.


Copyright © 2002-2003 Paul Speed. All Rights Reserved.