|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.pietschy.command.Command
com.pietschy.command.ActionCommand
com.pietschy.command.worker.SwingWorkerCommand<T,V>
public abstract class SwingWorkerCommand<T,V>
This is an action command implementation that performs the operation on a background thread
using a SwingWorker. This implementation provides a number of enhancements
for controling the state of buttons and activating the glass pane. By default, the
command will disable for the duration of the background task, see setDisableWhileWorking(boolean)
and setActivateGlassPane(boolean) for more details.
Unlike SwingWorker, this command provides a basic implementation of done() that
calls get() and then invokes either finished(T), failed(java.lang.Exception) or
cancelled(java.lang.Exception) accordingly.
SwingWorkerCommand command = new SwingWorkerCommand<Result, Chunck>()
{
public boolean beforeStarting()
{
// check any preconditions on the EDT
return true;
}
public Result doInBackground()
{
// do some work..
while (...)
{
// optionally update the progress
// and publish a chunck
setProgress(progress);
publish(chunck);
}
// and return the result..
return result;
}
public finished(Result result)
{
// update the UI.
}
public failed(ExecutionException e)
{
// handle the error.
}
public void process(Chunck chunck)
{
// update the UI with chuncks as they
// are published
}
}
setActivateGlassPane(boolean) is set to true
the CommandContainer hierarchy is searched for a GlassPaneStrategy and if found
it's activated for the duration of the task.
The GlassPaneStrategy is passed this command instance so it is able to
monitor and display the progress and/or chunk information to the user.
doInBackground(),
(),
failed(Exception),
cancelled(Exception),
setDisableWhileWorking(boolean),
setActivateGlassPane(boolean),
isWorking(),
CommandContainer.setGlassPaneStrategy(GlassPaneStrategy)| Nested Class Summary | |
|---|---|
static class |
SwingWorkerCommand.WorkingMode
Deprecated. since 2.1, use setDisableWhileWorking(boolean)
and setActivateGlassPane(boolean) instead. |
| Field Summary | |
|---|---|
static SwingWorkerCommand.WorkingMode |
ACTIVATE_GLASS_PANE
Deprecated. since 2.1, use setActivateGlassPane(boolean) and setDisableWhileWorking(boolean) instead. |
static SwingWorkerCommand.WorkingMode |
DISABLE
Deprecated. since 2.1, use setActivateGlassPane(boolean) and setDisableWhileWorking(boolean) instead. |
static SwingWorkerCommand.WorkingMode |
DISABLE_AND_ACTIVATE_GLASS_PANE
Deprecated. since 2.1, use setActivateGlassPane(boolean) and setDisableWhileWorking(boolean) instead. |
static SwingWorkerCommand.WorkingMode |
DO_NOTHING
Deprecated. since 2.1, use setActivateGlassPane(boolean) and setDisableWhileWorking(boolean) instead. |
static java.lang.String |
PROGRESS_PROPERTY
|
static java.lang.String |
STATE_PROPERTY
|
static java.lang.String |
WORKING_PROPERTY
|
| Fields inherited from class com.pietschy.command.ActionCommand |
|---|
PARAMETER_ACTION_EVENT, PARAMETER_INVOKER, PARAMETER_INVOKER_WINDOW, PARAMETER_MODIFIERS |
| Fields inherited from class com.pietschy.command.Command |
|---|
internalLog, PROPERTY_ENABLED, PROPERTY_VISIBLE |
| Constructor Summary | |
|---|---|
SwingWorkerCommand()
Creates a new anonymous instance. |
|
SwingWorkerCommand(boolean disableWhileWorking,
boolean activateGlassPane)
Creaets a new anonymous instance that disables and activates the glass pane as specified. |
|
SwingWorkerCommand(java.lang.String id)
Creates a new instance with the specified id. |
|
SwingWorkerCommand(java.lang.String id,
boolean disableWhileWorking,
boolean activateGlassPane)
Creates a new instance that disables and activates the glass pane as specified. |
|
SwingWorkerCommand(java.lang.String id,
SwingWorkerCommand.WorkingMode mode)
Deprecated. since 2.1, use SwingWorkerCommand(boolean, boolean) instead. |
|
SwingWorkerCommand(SwingWorkerCommand.WorkingMode mode)
Deprecated. since 2.1, use SwingWorkerCommand(boolean, boolean) instead. |
|
| Method Summary | |
|---|---|
protected boolean |
beforeStarting()
Called on the EDT prior to the swing worker being started. |
boolean |
cancel(boolean mayInterruptIfRunning)
Delegates to SwingWorker.cancel(boolean). |
protected void |
cancelled(java.lang.Exception e)
Invoked on the EDT if the worker was cancelled. |
protected abstract T |
doInBackground()
Invoked by to perform the commands work on a background thread. |
protected void |
done()
Invoked on the EDT when doInBackground() has completed or thrown an
exception. |
protected void |
failed(java.lang.Exception e)
Invoked on the EDT if doInBackground() throws an exception. |
protected void |
finished(T result)
Invoked on the EDT when doInBackground() completes successfully. |
(package private) void |
finishedWorking()
Called by the worker when it has completed, either normally or due to an exception. |
T |
get()
Delegates to SwingWorker.get(). |
T |
get(long timeout,
java.util.concurrent.TimeUnit timeUnit)
Delegates to SwingWorker.get(long, TimeUnit). |
protected GlassPaneStrategy |
getGlassPaneStrategy()
Searches the CommandContainer hierarchy to find the GlassPaneStrategy to
use. |
int |
getProgress()
Gets the progress of the background task. |
org.jdesktop.swingworker.SwingWorker.StateValue |
getState()
Delegates to SwingWorker.getState(). |
SwingWorkerCommand.WorkingMode |
getWorkingMode()
Deprecated. since 2.1, see isActivateGlassPane() and isDisableWhileWorking(). |
protected void |
handleExecute()
Invokes beforeStarting() and if true is returned starts an
swingworker instance that invokes doInBackground(). |
boolean |
isActivateGlassPane()
Checks if this command will automatically activate the glass pane while working. |
boolean |
isCancelled()
Delegates to SwingWorker.isCancelled(). |
boolean |
isDisableWhileWorking()
Checks if this command will automatically disable while working. |
boolean |
isDone()
Delegates to SwingWorker.isDone(). |
boolean |
isEnabled()
Checks if this command is enabled. |
boolean |
isWorking()
Bound property the indicates that the command is current running a background task. |
protected void |
postExecute()
This method is called after ActionCommand.handleExecute() has been called. |
protected void |
process(java.util.List<V> chunks)
Invoked on the EDT to handle chucks published using #publish(V...). |
protected void |
publish(V... chunks)
Delegates to SwingWorker#publish(V...). |
void |
setActivateGlassPane(boolean activateGlassPane)
Configures the command to automatically activate the glass pane while the background process is in progress. |
void |
setDisableWhileWorking(boolean disableWhileWorking)
Configures the command to automatically disable while the background process is in progress. |
void |
setProgress(int progress)
Delegates to SwingWorker.setProgress(int). |
void |
setWorkingMode(SwingWorkerCommand.WorkingMode workingMode)
Deprecated. since 2.1. Use setDisableWhileWorking(boolean) and setActivateGlassPane(boolean)
instead. |
(package private) void |
startWorker()
Starts a new worker, updates the working state and performs the actions specified by the current SwingWorkerCommand.WorkingMode. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.pietschy.command.ActionCommandExecutor |
|---|
addPropertyChangeListener, addPropertyChangeListener, removePropertyChangeListener, removePropertyChangeListener |
| Methods inherited from interface com.pietschy.command.Identifiable |
|---|
getId |
| Field Detail |
|---|
public static final java.lang.String PROGRESS_PROPERTY
public static final java.lang.String STATE_PROPERTY
public static final java.lang.String WORKING_PROPERTY
public static final SwingWorkerCommand.WorkingMode DO_NOTHING
setActivateGlassPane(boolean) and setDisableWhileWorking(boolean) instead.
public static final SwingWorkerCommand.WorkingMode DISABLE
setActivateGlassPane(boolean) and setDisableWhileWorking(boolean) instead.
public static final SwingWorkerCommand.WorkingMode ACTIVATE_GLASS_PANE
setActivateGlassPane(boolean) and setDisableWhileWorking(boolean) instead.
public static final SwingWorkerCommand.WorkingMode DISABLE_AND_ACTIVATE_GLASS_PANE
setActivateGlassPane(boolean) and setDisableWhileWorking(boolean) instead.
| Constructor Detail |
|---|
public SwingWorkerCommand()
public SwingWorkerCommand(java.lang.String id)
id - the command id.public SwingWorkerCommand(SwingWorkerCommand.WorkingMode mode)
SwingWorkerCommand(boolean, boolean) instead.
SwingWorkerCommand.WorkingMode. The available modes
are DISABLE, ACTIVATE_GLASS_PANE and DISABLE_AND_ACTIVATE_GLASS_PANE.
mode - the busy mode.
public SwingWorkerCommand(boolean disableWhileWorking,
boolean activateGlassPane)
disableWhileWorking - true to automatically disable the command while working.activateGlassPane - true to automatically activate the glass pane while working.
public SwingWorkerCommand(java.lang.String id,
SwingWorkerCommand.WorkingMode mode)
SwingWorkerCommand(boolean, boolean) instead.
DISABLE, ACTIVATE_GLASS_PANE and DISABLE_AND_ACTIVATE_GLASS_PANE.
id - the command id.mode - the busy mode.
public SwingWorkerCommand(java.lang.String id,
boolean disableWhileWorking,
boolean activateGlassPane)
id - the command id.disableWhileWorking - true to automatically disable the command while working.activateGlassPane - true to automatically activate the glass pane while working.| Method Detail |
|---|
public void setWorkingMode(SwingWorkerCommand.WorkingMode workingMode)
setDisableWhileWorking(boolean) and setActivateGlassPane(boolean)
instead.
DISABLE, ACTIVATE_GLASS_PANE and DISABLE_AND_ACTIVATE_GLASS_PANE and
the default mode is DISABLE.
workingMode - the busy mode of this command.public boolean isDisableWhileWorking()
true.
true if the command will automatically disable while in progress,
false if it will remain enabled.public void setDisableWhileWorking(boolean disableWhileWorking)
true.
disableWhileWorking - true to automatically disable the command while working,
false to leave it enabled.public boolean isActivateGlassPane()
false.
true if the command will automatically activate the glass pane while in progress,
false if it will remain enabled.public void setActivateGlassPane(boolean activateGlassPane)
false.
The glass pane will only be activated if there is a GlassPaneStrategy configured within
the commands container hierarchy. See CommandContainer.setGlassPaneStrategy(GlassPaneStrategy).
activateGlassPane - true to automatically activate the glass pane while the command
while working, false otherwise.CommandContainer.setGlassPaneStrategy(GlassPaneStrategy)public SwingWorkerCommand.WorkingMode getWorkingMode()
isActivateGlassPane() and isDisableWhileWorking().
setWorkingMode(WorkingMode)protected GlassPaneStrategy getGlassPaneStrategy()
CommandContainer hierarchy to find the GlassPaneStrategy to
use.
GlassPaneStrategy or null if none found.protected final void handleExecute()
beforeStarting() and if true is returned starts an
swingworker instance that invokes doInBackground().
handleExecute in class ActionCommandprotected boolean beforeStarting()
true.
true to proceed with the worker or false to
terminate immediately. The default implemetation always returns true.protected final void postExecute()
ActionCommandActionCommand.handleExecute() has been called. It invokes
all the ActionCommandInterceptors and notifies all the
ActionCommandListeners.
postExecute in class ActionCommandfinal void startWorker()
SwingWorkerCommand.WorkingMode.
final void finishedWorking()
SwingWorkerCommand.WorkingMode.
public boolean isWorking()
true if the command is currently running a background task, false
otherwise.public boolean isEnabled()
busy mode.
isEnabled in interface ActionCommandExecutorisEnabled in class Commandfalse if this command is disbled or the command is working and
the busy operation is either DISABLE or DISABLE_AND_ACTIVATE_GLASS_PANE,
otherwise true.public int getProgress()
public void setProgress(int progress)
SwingWorker.setProgress(int).
progress - the progress.public boolean cancel(boolean mayInterruptIfRunning)
SwingWorker.cancel(boolean).
public boolean isCancelled()
SwingWorker.isCancelled().
public boolean isDone()
SwingWorker.isDone().
public T get()
throws java.lang.InterruptedException,
java.util.concurrent.ExecutionException
SwingWorker.get().
java.lang.InterruptedException
java.util.concurrent.ExecutionException
public T get(long timeout,
java.util.concurrent.TimeUnit timeUnit)
throws java.lang.InterruptedException,
java.util.concurrent.ExecutionException,
java.util.concurrent.TimeoutException
SwingWorker.get(long, TimeUnit).
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
protected abstract T doInBackground()
throws java.lang.Exception
java.lang.Exception - if an error occurs. This exception will be
propegated by get().protected void done()
doInBackground() has completed or thrown an
exception. This method in turn invokes either the #finished(T), failed(Exception)
or cancelled(Exception) methods depending on the outcome of
doInBackground().
#finished(T),
failed(Exception),
cancelled(Exception)protected void finished(T result)
doInBackground() completes successfully. Subclasses
can override to perform post task gui updates.
result - the object returned by doInBackground().failed(Exception),
cancelled(Exception)protected void failed(java.lang.Exception e)
doInBackground() throws an exception. Subclasses
can override to handle any errors.
#finished(T),
cancelled(Exception)protected void cancelled(java.lang.Exception e)
cancel(boolean) or because the doInBackground() thread was interrupated.
Subclasses can override to handle.
e - the exception that was thrown by get().#finished(T),
failed(Exception)protected final void publish(V... chunks)
SwingWorker#publish(V...). The published chunks will
be processed by #process(List) .
chunks - the data to be published.protected void process(java.util.List<V> chunks)
#publish(V...).
chunks - the chunk published by the assicated #publish(V... method.public org.jdesktop.swingworker.SwingWorker.StateValue getState()
SwingWorker.getState(). This property is bound.
SwingWorker.getState().
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||