org.pietschy.command
Class CommandManager

java.lang.Object
  extended by org.pietschy.command.CommandManager
All Implemented Interfaces:
java.util.EventListener, CommandManagerListener

public class CommandManager
extends java.lang.Object
implements CommandManagerListener

The CommandManger is the core of the GUI Command libarary. It provides the mechanism to load command configuration files and to manage and locate ActionCommand and CommandGroup instances.

See Also:
load(java.io.File), load(java.net.URL), load(java.io.InputStream), getGroup(java.lang.String), getCommand(java.lang.String)

Field Summary
protected  java.util.HashMap registeredCommands
           
 
Constructor Summary
CommandManager()
          Constructs and initializes the command manager.
CommandManager(CommandManager parent)
          Constructs and initializes the command manager.
CommandManager(CommandManager parent, java.lang.Object context)
          Constructs and initializes the command manager.
CommandManager(java.lang.Object context)
          Constructs and initializes the command manager.
 
Method Summary
 void addCommandManagerListener(CommandManagerListener l)
           
 void addHoverListener(HoverListener l)
          Adds a HoverListener to the command manager.
 java.util.Iterator commandIterator()
           
 void commandRegistered(CommandManagerEvent event)
          Pass on events from our parent.
protected  void configure(Command command)
          Initialises the command from the current loaded set of properties.
static CommandManager defaultInstance()
          Returns an instance of the CommandManager.
 void dispose()
          This method removes any listeners from this command managers parent (if it exists).
protected  void fireCommandRegistered(Command command)
           
protected  void fireHoverEnded(HoverEvent e)
           
protected  void fireHoverStarted(HoverEvent e)
           
 ButtonFactory getButtonFactory()
          Gets the default ButtonFactory to use for buttons created by this command manager.
 java.lang.ClassLoader getClassLoader()
          Gets the class loader the library is to use.
 ActionCommand getCommand(java.lang.String commandId)
          Gets the specifed command from this container.
 CommandManagerListener[] getCommandManagerListeners()
           
 ConditionEvaluator getConditionEvaluator()
          Gets the commands managers current condition evaluator.
 java.lang.Object getContext()
          Gets the context object specified in the constructor.
static ButtonFactory getDefaultButtonFactory()
          Gets the default ButtonFactory.
static MenuFactory getDefaultMenuFactory()
          Gets the default MenuFactory.
static ToolbarFactory getDefaultToolbarFactory()
          Gets the default ToolbarFactory.
 FaceManager getFaceManager()
          Gets the FaceManager in use by the CommandManager.
 CommandGroup getGroup(java.lang.String groupId)
          Gets the specifed group from the container.
 GroupFactory getGroupFactory()
          Gets the GroupFactory being used by the library.
 GroupMemberFactory getGroupMemberFactory()
          Gets the GroupMemberFactory used by the library to construct GroupMember.
 IconFactory getIconFactory()
          Gets this command managers IconFactory.
static Logger getLogger(java.lang.Class aClass)
          Gets a new logger for the command library.
 MenuFactory getMenuFactory()
          Gets the MenuFactory that is to be used by commands to create menu items.
 CommandManager getParent()
          Gets the parent of this CommandManager.
 java.util.ResourceBundle getResourceBundle()
          Gets the ResourceBundle for resolving i18n configuration parameters.
 ToolbarFactory getToolbarFactory()
          Gets the default ToolbarFactory to be used by commands to create toolbars and their associated buttons.
static CommandManager instance()
          Deprecated. defaultInstance should now be the preferred method for obtaining the global command manager. This method will be removed in a future release.
 boolean isGroup(java.lang.String commandId)
          Checks if the command identified by the specified id is a group.
static boolean isMacOS()
          A convenience method for GUI Commands to check if we're running in an apple Mac environment.
 boolean isMenuTooltipsEnabled()
          Checks if tooltip are globally enabled on menus.
protected  boolean isRegistered(Command command)
           
 void load(java.io.File file)
          Load the command definitions in the specified file.
 void load(java.io.File file, java.util.Locale locale)
          Load the command definitions in the specified file.
 void load(java.io.InputStream in)
          Load the command definitions using the specified reader.
 void load(java.io.InputStream in, java.util.Locale locale)
          Load the command definitions using the specified reader.
 void load(java.net.URL url)
          Load the command definitions from the specified URL.
 void load(java.net.URL url, java.util.Locale locale)
          Load the command definitions from the specified URL.
protected  void registerCommand(Command command)
          Registers this command with the manager so it can be accessed by the rest of the application.
 void removeCommandManagerListener(CommandManagerListener l)
           
 void removeHoverListener(HoverListener l)
          Removes the HoverListener from the command manager.
 void setButtonFactory(ButtonFactory factory)
          Sets the ButtonFactory that will be the default used by all ActionCommands and CommandGroups.
 void setClassLoader(java.lang.ClassLoader classLoader)
          Sets the class loader the libary is to use for opertations like loading icons from the classpath.
 void setConditionEvaluator(ConditionEvaluator conditionEvaluator)
          Sets the commands managers condition evaluator.
static void setDefaultButtonFactory(ButtonFactory defaultButtonFactory)
          Configures the default factory to be used when creating buttons.
static void setDefaultInstance(CommandManager manager)
          Sets the command manager to use for defaultInstance singleton.
static void setDefaultMenuFactory(MenuFactory defaultMenuFactory)
          Configures the default factory to be used when creating menus.
static void setDefaultToolbarFactory(ToolbarFactory defaultToolbarFactory)
          Configures the default factory to be used when creating toolbars and toolbar buttons.
 void setGroupFactory(GroupFactory groupFactory)
          Sets the GroupFactory being used by the library.
 void setGroupMemberFactory(GroupMemberFactory groupMemberFactory)
          Gets the GroupMemberFactory used by the library to construct GroupMember.
 void setIconFactory(IconFactory iconFactory)
          Sets this command managers IconFactory.
static void setLoggerFactory(LoggerFactory loggerFactory)
          Sets the log factory to use for creating new logger instances.
 void setMenuFactory(MenuFactory factory)
          Sets the MenuFactory that is to be used by commands to create menu items.
 void setMenuTooltipsEnabled(boolean menuTooltipsEnabled)
          Configures the current menu tooltip state and notifies all faces that the state has changed.
 void setResourceBundle(java.util.ResourceBundle resourceBundle)
          Sets the ResourceBundle for resolving i18n configuration parameters.
 void setToolbarFactory(ToolbarFactory factory)
          Sets the ToolbarFactory that will be the default used by all commands when creating toolbars and their associated buttons.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

registeredCommands

protected java.util.HashMap registeredCommands
Constructor Detail

CommandManager

public CommandManager()
Constructs and initializes the command manager.


CommandManager

public CommandManager(java.lang.Object context)
Constructs and initializes the command manager.


CommandManager

public CommandManager(CommandManager parent)
Constructs and initializes the command manager.


CommandManager

public CommandManager(CommandManager parent,
                      java.lang.Object context)
Constructs and initializes the command manager.

Method Detail

instance

public static CommandManager instance()
Deprecated. defaultInstance should now be the preferred method for obtaining the global command manager. This method will be removed in a future release.

Returns an instance of the CommandManager. The actuall object returned can be specified by calling setDefaultInstance(org.pietschy.command.CommandManager) before calling this method.

Returns:
the current installed CommandManager

defaultInstance

public static CommandManager defaultInstance()
Returns an instance of the CommandManager. The actuall object returned can be specified by calling setDefaultInstance(org.pietschy.command.CommandManager) before calling this method.

Returns:
the current installed CommandManager

setDefaultInstance

public static void setDefaultInstance(CommandManager manager)
Sets the command manager to use for defaultInstance singleton. The method must be called before defaultInstance() is called. Otherwise an IllegalStateException will be thrown.

Parameters:
manager - the CommandManager instance to use as the default.

getLogger

public static Logger getLogger(java.lang.Class aClass)
Gets a new logger for the command library.

See Also:
setLoggerFactory(org.pietschy.command.log.LoggerFactory)

setLoggerFactory

public static void setLoggerFactory(LoggerFactory loggerFactory)
Sets the log factory to use for creating new logger instances.

Parameters:
loggerFactory - the factory to use.
See Also:
getLogger(java.lang.Class)

isMacOS

public static boolean isMacOS()
A convenience method for GUI Commands to check if we're running in an apple Mac environment.

Returns:
true if running in the Mac environment, false otherwise.

getDefaultMenuFactory

public static MenuFactory getDefaultMenuFactory()
Gets the default MenuFactory.

Returns:
the default MenuFactory.

setDefaultMenuFactory

public static void setDefaultMenuFactory(MenuFactory defaultMenuFactory)
Configures the default factory to be used when creating menus. This can be overriden on a per command manager basis by calling setMenuFactory(MenuFactory).

Parameters:
defaultMenuFactory - the factory to use when creating menus.

getDefaultButtonFactory

public static ButtonFactory getDefaultButtonFactory()
Gets the default ButtonFactory.

Returns:
the default ButtonFactory.

setDefaultButtonFactory

public static void setDefaultButtonFactory(ButtonFactory defaultButtonFactory)
Configures the default factory to be used when creating buttons. This can be overriden on a per command manager basis by calling setButtonFactory(ButtonFactory).

Parameters:
defaultButtonFactory - the factory to use when creating buttons.

getDefaultToolbarFactory

public static ToolbarFactory getDefaultToolbarFactory()
Gets the default ToolbarFactory.

Returns:
the default ToolbarFactory.

setDefaultToolbarFactory

public static void setDefaultToolbarFactory(ToolbarFactory defaultToolbarFactory)
Configures the default factory to be used when creating toolbars and toolbar buttons. This can be overriden on a per command manager basis by calling setToolbarFactory(ToolbarFactory).

Parameters:
defaultToolbarFactory - the factory to use when creating toolbar and toolbar buttons.

getParent

public CommandManager getParent()
Gets the parent of this CommandManager. If present, the parent is used to resolve requests for ActionCommands that aren't present in this CommandManager

Returns:
the parent CommandManager or null if it doesn't have a parent.

dispose

public void dispose()
This method removes any listeners from this command managers parent (if it exists). This method should only be called when the command manager is no longer in use.


getContext

public java.lang.Object getContext()
Gets the context object specified in the constructor.

Returns:
this managers context object, or null if there is none.

getClassLoader

public java.lang.ClassLoader getClassLoader()
Gets the class loader the library is to use. If not explicitly set, this defaults to the class loader that loaded the command manager.

Returns:
the ClassLoader the library is to use.
See Also:
setClassLoader(java.lang.ClassLoader)

setClassLoader

public void setClassLoader(java.lang.ClassLoader classLoader)
Sets the class loader the libary is to use for opertations like loading icons from the classpath. This parameter must be set before calling load(java.io.File) to take affect.

Parameters:
classLoader - the class loader to use for resource loading.

getResourceBundle

public java.util.ResourceBundle getResourceBundle()
Gets the ResourceBundle for resolving i18n configuration parameters. This value is null by default.

Returns:
the command managers ResourceBundle
See Also:
setResourceBundle(java.util.ResourceBundle)

setResourceBundle

public void setResourceBundle(java.util.ResourceBundle resourceBundle)
Sets the ResourceBundle for resolving i18n configuration parameters.

Parameters:
resourceBundle - the ResourceBundle for resolving i18n configuration parameters.
See Also:
getResourceBundle()

getConditionEvaluator

public ConditionEvaluator getConditionEvaluator()
Gets the commands managers current condition evaluator. Conditions are used by groups to determine if a given command should be included.

Returns:
the current condition evaluator.

setConditionEvaluator

public void setConditionEvaluator(ConditionEvaluator conditionEvaluator)
Sets the commands managers condition evaluator. Conditions are used by groups to determine if a given command should be included. This must be configured before an command files are loaded.

The default implementation is an instance of DefaultConditionEvaluator.

Parameters:
conditionEvaluator - the new condition evaluator.

getIconFactory

public IconFactory getIconFactory()
Gets this command managers IconFactory. If the icon factory hasn't been configured, the parent, if present, is queried.

Returns:
this command managers IconFactory.

setIconFactory

public void setIconFactory(IconFactory iconFactory)
Sets this command managers IconFactory.

Parameters:
iconFactory - this command managers IconFactory.

isMenuTooltipsEnabled

public boolean isMenuTooltipsEnabled()
Checks if tooltip are globally enabled on menus. This setting will only be used by faces that haven't been explicitly configured to enable or disable tooltips on menus.

Returns:
true if tooltips are enabled on menus, false otherwise.

setMenuTooltipsEnabled

public void setMenuTooltipsEnabled(boolean menuTooltipsEnabled)
Configures the current menu tooltip state and notifies all faces that the state has changed. This setting will be used by all faces that haven't been explicitly configured to enable or disable tooltips on menus.

Parameters:
menuTooltipsEnabled - true to enable tooltips on menus, false to disable them.

getMenuFactory

public MenuFactory getMenuFactory()
Gets the MenuFactory that is to be used by commands to create menu items. If not explicitly set, the global getDefaultMenuFactory() will be used.

Returns:
the MenuFactory that is to be used by commands to create menu items.
See Also:
setMenuFactory(org.pietschy.command.MenuFactory)

setMenuFactory

public void setMenuFactory(MenuFactory factory)
Sets the MenuFactory that is to be used by commands to create menu items. This factory will be used unless a specific factory has been configured for an individual command.


getButtonFactory

public ButtonFactory getButtonFactory()
Gets the default ButtonFactory to use for buttons created by this command manager. If explicitly configured the global getDefaultButtonFactory() will be used.

Returns:
the button factory.

setButtonFactory

public void setButtonFactory(ButtonFactory factory)
Sets the ButtonFactory that will be the default used by all ActionCommands and CommandGroups.

Parameters:
factory - the default ButtonFactory

getToolbarFactory

public ToolbarFactory getToolbarFactory()
Gets the default ToolbarFactory to be used by commands to create toolbars and their associated buttons. If not explicitly set, the global getDefaultToolbarFactory() will be used.

Returns:
the default ToolbarFactory.

setToolbarFactory

public void setToolbarFactory(ToolbarFactory factory)
Sets the ToolbarFactory that will be the default used by all commands when creating toolbars and their associated buttons.

Parameters:
factory - the default ToolbarFactory.

getGroupFactory

public GroupFactory getGroupFactory()
Gets the GroupFactory being used by the library. This factory is used by the library whenever a group must be created. This is typically during calls to getGroup(java.lang.String).

Returns:
the GroupFactory being used by the library.
See Also:
setGroupFactory(org.pietschy.command.GroupFactory)

setGroupFactory

public void setGroupFactory(GroupFactory groupFactory)
Sets the GroupFactory being used by the library. This factory will be used by the library whenever a group must be created. This is typically during calls to getGroup(java.lang.String).

Parameters:
groupFactory - the GroupFactory to use.

getGroupMemberFactory

public GroupMemberFactory getGroupMemberFactory()
Gets the GroupMemberFactory used by the library to construct GroupMember. This factory will be used by groups to create the infrastructure for managing its members. By supplying custom implementations you can control the way groups populate their containers.

Returns:
the default GroupMemberFactory.
See Also:
CommandGroup.getMemberFactory()

setGroupMemberFactory

public void setGroupMemberFactory(GroupMemberFactory groupMemberFactory)
Gets the GroupMemberFactory used by the library to construct GroupMember. This factory will be used by groups to create the infrastructure for managing its members. By pluggin custome implementations you can control the way groups populate their containers.

Parameters:
groupMemberFactory - the default GroupMemberFactory for all groups to use.

getFaceManager

public FaceManager getFaceManager()
Gets the FaceManager in use by the CommandManager.

Returns:
the FaceManager in use by the CommandManager.

load

public void load(java.io.File file)
          throws LoadException
Load the command definitions in the specified file.

Parameters:
file - the file to load.
Throws:
LoadException - if an error occurs loading the file.

load

public void load(java.io.File file,
                 java.util.Locale locale)
          throws LoadException
Load the command definitions in the specified file.

Parameters:
file - the file to load.
locale - the locale to load.
Throws:
LoadException - if an error occurs loading the file.

load

public void load(java.net.URL url)
          throws LoadException
Load the command definitions from the specified URL.

Parameters:
url - the url of the command definition file.
Throws:
LoadException - if an error occurs loading the file.

load

public void load(java.net.URL url,
                 java.util.Locale locale)
          throws LoadException
Load the command definitions from the specified URL.

Parameters:
url - the url of the command definition file.
locale - the locale to load.
Throws:
LoadException - if an error occurs loading the file.

load

public void load(java.io.InputStream in)
          throws LoadException
Load the command definitions using the specified reader.

Parameters:
in - the reader to use.
Throws:
LoadException - if an error occurs loading the file.

load

public void load(java.io.InputStream in,
                 java.util.Locale locale)
          throws LoadException
Load the command definitions using the specified reader.

Parameters:
in - the reader to use.
locale - the locale to load.
Throws:
LoadException - if an error occurs loading the file.

configure

protected void configure(Command command)
Initialises the command from the current loaded set of properties.

Parameters:
command - the Command to initialise.

isGroup

public boolean isGroup(java.lang.String commandId)
Checks if the command identified by the specified id is a group.

Parameters:
commandId - the command id.
Returns:
true if the command id represents a CommandGroup, false otherwise.

addHoverListener

public void addHoverListener(HoverListener l)
Adds a HoverListener to the command manager. The listener will be notified when ever the mouse hovers over a command.

Parameters:
l - the hover listener
See Also:
HoverListener, removeHoverListener(org.pietschy.command.HoverListener)

removeHoverListener

public void removeHoverListener(HoverListener l)
Removes the HoverListener from the command manager.

Parameters:
l - the hover listener
See Also:
HoverListener, addHoverListener(org.pietschy.command.HoverListener)

fireHoverStarted

protected void fireHoverStarted(HoverEvent e)

fireHoverEnded

protected void fireHoverEnded(HoverEvent e)

registerCommand

protected void registerCommand(Command command)
Registers this command with the manager so it can be accessed by the rest of the application.

Parameters:
command - the command to register

isRegistered

protected boolean isRegistered(Command command)

getCommand

public ActionCommand getCommand(java.lang.String commandId)
Gets the specifed command from this container. If the command isn't registered with this container then the request is delegated to the containers parent.

Parameters:
commandId - the commands id.
Returns:
the command with the specified id, or null if it hasn't been registered with this container of one of its parents.

getGroup

public CommandGroup getGroup(java.lang.String groupId)
Gets the specifed group from the container. If the group hasn't already beed registered with this container, it will be be created automatically and registered. Please note that parent containers are never checked.

Parameters:
groupId - the Id of the group.
Returns:
the CommandGroup with the specified Id.

commandIterator

public java.util.Iterator commandIterator()

commandRegistered

public void commandRegistered(CommandManagerEvent event)
Pass on events from our parent.

Specified by:
commandRegistered in interface CommandManagerListener
Parameters:
event -

addCommandManagerListener

public void addCommandManagerListener(CommandManagerListener l)

removeCommandManagerListener

public void removeCommandManagerListener(CommandManagerListener l)

getCommandManagerListeners

public CommandManagerListener[] getCommandManagerListeners()

fireCommandRegistered

protected void fireCommandRegistered(Command command)