Package net.sf.jguiraffe.gui.cmd
Class CommandBase
- java.lang.Object
-
- net.sf.jguiraffe.gui.cmd.CommandBase
-
- All Implemented Interfaces:
Command
- Direct Known Subclasses:
OpenWindowCommand
public abstract class CommandBase extends Object implements Command
An abstract base class for implementations of the
Commandinterface.This abstract class provides some simple base implementations for methods required by the
Commandinterface. 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. ForonFinally()an empty dummy implementation is provided. GUI updates can be performed in theperformGUIUpdate()method. This method will be executed by aRunnableobject in the application's event handler thread if theUpdateGUIproperty is set to true.- Version:
- $Id: CommandBase.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedCommandBase()Creates a new instance ofCommandBase.protectedCommandBase(boolean updateGUI)Creates a new instance ofCommandBaseand sets theUpdateGUIproperty.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ThrowablegetException()Returns an exception that was thrown during the execution of this command.RunnablegetGUIUpdater()Returns aRunnableobject for updating the GUI.protected org.apache.commons.logging.LoggetLog()Returns the logger used by this object.booleanisUpdateGUI()Returns the value of theUpdateGUIproperty.voidonException(Throwable t)This method is called if an exception occurs.voidonFinally()This method is called after each command execution.protected voidperformGUIUpdate()Performs GUI updates.voidsetException(Throwable exception)Sets an exception that was thrown during the execution of this command.
-
-
-
Constructor Detail
-
CommandBase
protected CommandBase()
Creates a new instance ofCommandBase. TheUpdateGUIproperty is set to true.
-
CommandBase
protected CommandBase(boolean updateGUI)
Creates a new instance ofCommandBaseand sets theUpdateGUIproperty.- Parameters:
updateGUI- a flag if GUI updates are to be performed
-
-
Method Detail
-
onException
public void onException(Throwable t)
This method is called if an exception occurs. This implementation callssetException(Throwable)to store the exception.- Specified by:
onExceptionin interfaceCommand- Parameters:
t- the exception
-
onFinally
public void onFinally()
This method is called after each command execution. This is an empty dummy implementation.
-
getGUIUpdater
public Runnable getGUIUpdater()
Returns aRunnableobject for updating the GUI. This implementation returns either null or aRunnableobject that invokes theperformGUIUpdate()method, depending on the value of theUpdateGUIproperty.- Specified by:
getGUIUpdaterin interfaceCommand- Returns:
- an object for updating the GUI
-
isUpdateGUI
public boolean isUpdateGUI()
Returns the value of theUpdateGUIproperty. This flag can be set in the constructor. If set to true, theperformGUIUpdate()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.- Returns:
- the
UpdateGUIproperty
-
getException
public Throwable getException()
Returns an exception that was thrown during the execution of this command. Result can be null, which means that no exception was thrown.- Returns:
- an exception thrown during the execution of this command
-
setException
public void setException(Throwable exception)
Sets an exception that was thrown during the execution of this command. TheonException(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()orperformGUIUpdate()) to find out whether the command's execution was successful.- Parameters:
exception- an exception
-
getLog
protected org.apache.commons.logging.Log getLog()
Returns the logger used by this object.- Returns:
- the logger
-
performGUIUpdate
protected void performGUIUpdate()
Performs GUI updates. Here the code for thread safe GUI updates can be placed. If theUpdateGUIproperty 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 thegetException()method). This base implementation is empty.
-
-