org.pietschy.command

Class CommandManager

Implemented Interfaces:
CommandManagerListener, EventListener

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(String), getCommand(String)

Field Summary

protected HashMap
registeredCommands

Constructor Summary

CommandManager()
Constructs and initializes the command manager.
CommandManager(Object context)
Constructs and initializes the command manager.
CommandManager(CommandManager parent)
Constructs and initializes the command manager.
CommandManager(CommandManager parent, 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.
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.
ClassLoader
getClassLoader()
Gets the class loader the library is to use.
ActionCommand
getCommand(String commandId)
Gets the specifed command from this container.
CommandManagerListener[]
getCommandManagerListeners()
ConditionEvaluator
getConditionEvaluator()
Gets the commands managers current condition evaluator.
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(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(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.
ResourceBundle
getResourceBundle()
Gets the java.util.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.
boolean
isGroup(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(File file)
Load the command definitions in the specified file.
void
load(File file, Locale locale)
Load the command definitions in the specified file.
void
load(InputStream in)
Load the command definitions using the specified reader.
void
load(InputStream in, Locale locale)
Load the command definitions using the specified reader.
void
load(URL url)
Load the command definitions from the specified URL.
void
load(URL url, 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(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(ResourceBundle resourceBundle)
Sets the java.util.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.

Field Details

registeredCommands

protected HashMap registeredCommands

Constructor Details

CommandManager

public CommandManager()
Constructs and initializes the command manager.

CommandManager

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

CommandManager

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

CommandManager

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

Method Details

addCommandManagerListener

public void addCommandManagerListener(CommandManagerListener l)

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

commandIterator

public Iterator commandIterator()

commandRegistered

public void commandRegistered(CommandManagerEvent event)
Pass on events from our parent.
Specified by:
commandRegistered in interface CommandManagerListener
Parameters:
event -

configure

protected void configure(Command command)
Initialises the command from the current loaded set of properties.
Parameters:
command - the Command to initialise.

defaultInstance

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

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.

fireCommandRegistered

protected void fireCommandRegistered(Command command)

fireHoverEnded

protected void fireHoverEnded(HoverEvent e)

fireHoverStarted

protected void fireHoverStarted(HoverEvent e)

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.

getClassLoader

public 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.

getCommand

public ActionCommand getCommand(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.

getCommandManagerListeners

public CommandManagerListener[] getCommandManagerListeners()

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.

getContext

public Object getContext()
Gets the context object specified in the constructor.
Returns:
this managers context object, or null if there is none.

getDefaultButtonFactory

public static ButtonFactory getDefaultButtonFactory()
Gets the default ButtonFactory.
Returns:
the default ButtonFactory.

getDefaultMenuFactory

public static MenuFactory getDefaultMenuFactory()
Gets the default MenuFactory.
Returns:
the default MenuFactory.

getDefaultToolbarFactory

public static ToolbarFactory getDefaultToolbarFactory()
Gets the default ToolbarFactory.
Returns:
the default ToolbarFactory.

getFaceManager

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

getGroup

public CommandGroup getGroup(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.

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(String).
Returns:
the GroupFactory being used by the library.

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.

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.

getLogger

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

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.

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.

getResourceBundle

public ResourceBundle getResourceBundle()
Gets the java.util.ResourceBundle for resolving i18n configuration parameters. This value is null by default.
Returns:
the command managers ResourceBundle
See Also:
setResourceBundle(java.util.ResourceBundle)

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.

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(CommandManager) before calling this method.
Returns:
the current installed CommandManager

isGroup

public boolean isGroup(String commandId)
Checks if the command identified by the specified id is a group.
Parameters:
commandId - the command id.

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.

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.

isRegistered

protected boolean isRegistered(Command command)

load

public void load(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(File file,
                 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(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(InputStream in,
                 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.

load

public void load(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(URL url,
                 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.

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

removeCommandManagerListener

public void removeCommandManagerListener(CommandManagerListener l)

removeHoverListener

public void removeHoverListener(HoverListener l)
Removes the HoverListener from the command manager.
Parameters:
l - the hover listener

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

setClassLoader

public void setClassLoader(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 to take affect.
Parameters:
classLoader - the class loader to use for resource loading.

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.

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.

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.

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.

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.

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(String).
Parameters:
groupFactory - the GroupFactory to use.

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.

setIconFactory

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

setLoggerFactory

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

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.

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.

setResourceBundle

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

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.