public abstract class CommandBase extends Object implements Command
An abstract base class for implementations of the Command
interface.
This abstract class provides some simple base implementations for methods
required by the Command
interface. It also defines some
utility methods that are useful in GUI applications.
The main execution method of course must be implemented in concrete sub
classes. The onException()
method passes the exception to a
logger. For onFinally()
an empty dummy implementation is
provided. GUI updates can be performed in the performGUIUpdate()
method. This method will be executed by a Runnable
object in
the application's event handler thread if the UpdateGUI
property is set to true.
Modifier | Constructor and Description |
---|---|
protected |
CommandBase()
Creates a new instance of
CommandBase . |
protected |
CommandBase(boolean updateGUI)
Creates a new instance of
CommandBase and sets the
UpdateGUI property. |
Modifier and Type | Method and Description |
---|---|
Throwable |
getException()
Returns an exception that was thrown during the execution of this
command.
|
Runnable |
getGUIUpdater()
Returns a
Runnable object for updating the GUI. |
protected org.apache.commons.logging.Log |
getLog()
Returns the logger used by this object.
|
boolean |
isUpdateGUI()
Returns the value of the
UpdateGUI property. |
void |
onException(Throwable t)
This method is called if an exception occurs.
|
void |
onFinally()
This method is called after each command execution.
|
protected void |
performGUIUpdate()
Performs GUI updates.
|
void |
setException(Throwable exception)
Sets an exception that was thrown during the execution of this command.
|
protected CommandBase()
CommandBase
. The UpdateGUI
property is set to true.protected CommandBase(boolean updateGUI)
CommandBase
and sets the
UpdateGUI
property.updateGUI
- a flag if GUI updates are to be performedpublic void onException(Throwable t)
setException(Throwable)
to store the exception.onException
in interface Command
t
- the exceptionpublic void onFinally()
public Runnable getGUIUpdater()
Runnable
object for updating the GUI. This
implementation returns either null or a Runnable
object that invokes the performGUIUpdate()
method,
depending on the value of the UpdateGUI
property.getGUIUpdater
in interface Command
public boolean isUpdateGUI()
UpdateGUI
property. This flag can be set
in the constructor. If set to true, the performGUIUpdate()
method will be invoked on the event dispatch thread after the command was
executed. If a derived class needs a more complex logic that can be
implemented using a final flag, it can override this method to return a
value that is computed based on arbitrary criteria.UpdateGUI
propertypublic Throwable getException()
public void setException(Throwable exception)
onException(Throwable)
implementation invokes this method to
store the exception passed to this method. It can then be queried by the
methods invoked later in the command's life-cycle (e.g. onFinally()
or performGUIUpdate()
) to find out whether the
command's execution was successful.exception
- an exceptionprotected org.apache.commons.logging.Log getLog()
protected void performGUIUpdate()
UpdateGUI
property is set, this method will
automatically be invoked in the event dispatch thread after the command
has been executed (also if an exception was thrown - in this case the
exception can be queried using the getException()
method). This
base implementation is empty.Copyright © 2016 The JGUIraffe Team. All rights reserved.