com.sas.util
Class CommandManager

com.sas.util.CommandManager
All Implemented Interfaces:
ContextCommandsConsumerInterface, ContextCommandsInterface

public class CommandManager
implements ContextCommandsConsumerInterface, ContextCommandsInterface

Provides various utility methods for managing commands. These include an implementation of ContextCommandsConsumerInterface, a method that concatenates the commands of all registered producers, methods for adding commands to menus, and methods that help avoid proliferation of zero-length command arrays.

Using this class, the typical ContextCommandsConsumerInterface implementation should simply be:

 private transient CommandManager _commandManager;
 private CommandManager getCommandManager ()
    {
    if (_commandManager == null)
       _commandManager = new CommandManager();
    return _commandManager;
    }

 public ContextCommandsInterface[] getContextCommandsProducers ()
    {
    return getCommandManager().getContextCommandsProducers();
    }

 public void addContextCommandsProducer (ContextCommandsInterface producer)
    {
    getCommandManager().addContextCommandsProducer(producer);
    }

 public void removeContextCommandsProducer (ContextCommandsInterface producer)
    {
    getCommandManager().removeContextCommandsProducer(producer);
    }
 

See Also:
ContextCommandsConsumerInterface

Constructor Summary
CommandManager()
           
 
Method Summary
static void addCommand(javax.swing.JMenu menu, com.sas.util.Command command, java.lang.Object executeParm)
          Adds a command to a JMenu by constructing an appropriate menu item, including a submenu or separator as necessary.
static void addCommand(javax.swing.JPopupMenu menu, com.sas.util.Command command, java.lang.Object executeParm)
          Adds a command to a JPopupMenu by constructing an appropriate menu item, including a submenu or separator as necessary.
static void addCommand(java.awt.Menu menu, com.sas.util.Command command, java.lang.Object executeParm)
          Adds a command to a menu by constructing an appropriate menu item, including a submenu or separator as necessary.
static void addCommands(javax.swing.JMenu menu, com.sas.util.Command[] commands, java.lang.Object executeParm)
          Adds a set of commands to a JMenu by constructing a appropriate menu items, including a submenus and/or separators as necessary.
static void addCommands(javax.swing.JPopupMenu menu, com.sas.util.Command[] commands, java.lang.Object executeParm)
          Adds a set of commands to a JPopupMenu by constructing a appropriate menu items, including a submenus and/or separators as necessary.
static void addCommands(java.awt.Menu menu, com.sas.util.Command[] commands, java.lang.Object executeParm)
          Adds a set of commands to a menu by constructing a appropriate menu items, including a submenus and/or separators as necessary.
 void addContextCommandsProducer(ContextCommandsInterface producer)
          Registers a new context commands producer.
 com.sas.util.Command[] getContextCommands(java.lang.Object context, int x, int y)
          Returns a list of commands associated with a given context.
 ContextCommandsInterface[] getContextCommandsProducers()
          Returns the set of context command producers that have been registered via addContextCommandsProducer().
static com.sas.util.Command[] getEmptyCommandArray()
          Returns a zero-length Command array.
static CommandsInterface[] getEmptyCommandsInterfaceArray()
          Returns a zero-length CommandsInterface array.
static ContextCommandsInterface[] getEmptyContextCommandsInterfaceArray()
          Returns a zero-length ContextCommandsInterface array.
 boolean isSeparatorsAdded()
          Returns whether or not getContextCommands adds a separator between each producer's list of commands.
 void removeContextCommandsProducer(ContextCommandsInterface producer)
          Unregisters a context commands producer.
 void setSeparatorsAdded(boolean newValue)
          Specifies whether or not getContextCommands adds a separator between each producer's list of commands.
 

Constructor Detail

CommandManager

public CommandManager()
Method Detail

getContextCommandsProducers

public ContextCommandsInterface[] getContextCommandsProducers()
Returns the set of context command producers that have been registered via addContextCommandsProducer(). The order of the set will reflect the order of registration.

Specified by:
getContextCommandsProducers in interface ContextCommandsConsumerInterface
Returns:
The set of producers.
See Also:
addContextCommandsProducer(com.sas.util.ContextCommandsInterface)

addContextCommandsProducer

public void addContextCommandsProducer(ContextCommandsInterface producer)
Registers a new context commands producer. Does nothing if the producer has already been registered. The producer will be queried for commands whenever this component needs context commands, such as when populating a popup menu.

Specified by:
addContextCommandsProducer in interface ContextCommandsConsumerInterface
Parameters:
producer - An object that implements ContextCommandsInterface.
See Also:
removeContextCommandsProducer(com.sas.util.ContextCommandsInterface)

removeContextCommandsProducer

public void removeContextCommandsProducer(ContextCommandsInterface producer)
Unregisters a context commands producer. Does nothing if the producer was not registered.

Specified by:
removeContextCommandsProducer in interface ContextCommandsConsumerInterface
Parameters:
producer - An object previously passed to addContextCommandsProducer().
See Also:
addContextCommandsProducer(com.sas.util.ContextCommandsInterface)

getContextCommands

public com.sas.util.Command[] getContextCommands(java.lang.Object context,
                                                 int x,
                                                 int y)
Returns a list of commands associated with a given context. The list may contain sublists by making one of the items a menu command.

The list is generated by calling getContextCommands() on each of the producers returned by getContextCommandsProducers(). If isSeparatorsAdded() returns true, then a separator is included between each producer's list.

Specified by:
getContextCommands in interface ContextCommandsInterface
Parameters:
context - The object requesting the commands; If it is an instance of com.sas.util.ContextInterface, the context will be queried to see if it has any subcontext to be used. This parameter is required, i.e. it may not be null.
x - The x position to pass to the context if the context implements the com.sas.util.ContextInterface. If the position is not relevant to the context then -1 should be used.
y - The y position to pass to the context if the context implements the com.sas.util.ContextInterface. If the position is not relevant to the context then -1 should be used.
Returns:
An array of commands.

isSeparatorsAdded

public boolean isSeparatorsAdded()
Returns whether or not getContextCommands adds a separator between each producer's list of commands. The default is true.

Returns:
true if a separator is added, and false otherwise
See Also:
setSeparatorsAdded(boolean)

setSeparatorsAdded

public void setSeparatorsAdded(boolean newValue)
Specifies whether or not getContextCommands adds a separator between each producer's list of commands.

Parameters:
newValue - true if a separator should be added, and false otherwise
See Also:
isSeparatorsAdded()

addCommand

public static void addCommand(java.awt.Menu menu,
                              com.sas.util.Command command,
                              java.lang.Object executeParm)
Adds a command to a menu by constructing an appropriate menu item, including a submenu or separator as necessary.

If command is an instance of MenuCommand, a Menu will be created and added to menu; unless MenuCommand.isSeparator() returns true, in which case menu.addSeparator() will be called instead.

If command is an instance of BooleanDataInterface, a CheckBoxMenuItem will be created and added to menu.

Parameters:
menu - The menu to add to.
command - The command to add.
executeParm - The parameter to pass to command.execute() when the command's menu item is selected.
See Also:
addCommands(java.awt.Menu, com.sas.util.Command[], java.lang.Object), MenuItem, MenuCommand, BooleanData

addCommands

public static void addCommands(java.awt.Menu menu,
                               com.sas.util.Command[] commands,
                               java.lang.Object executeParm)
Adds a set of commands to a menu by constructing a appropriate menu items, including a submenus and/or separators as necessary.

Parameters:
menu - The menu to add to.
commands - The set of commands to add; may be null.
executeParm - The parameter to pass to command.execute() when a command's menu item is selected.
See Also:
addCommand(java.awt.Menu, com.sas.util.Command, java.lang.Object)

addCommand

public static void addCommand(javax.swing.JPopupMenu menu,
                              com.sas.util.Command command,
                              java.lang.Object executeParm)
Adds a command to a JPopupMenu by constructing an appropriate menu item, including a submenu or separator as necessary.

If command is an instance of MenuCommand, a JMenu will be created and added to menu; unless MenuCommand.isSeparator() returns true, in which case menu.addSeparator() will be called instead.

If command is an instance of BooleanDataInterface, a JCheckBoxMenuItem will be created and added to menu.

Parameters:
menu - The menu to add to.
command - The command to add.
executeParm - The parameter to pass to command.execute() when the command's menu item is selected.
See Also:
addCommands(java.awt.Menu, com.sas.util.Command[], java.lang.Object), JMenuItem, MenuCommand, BooleanData

addCommands

public static void addCommands(javax.swing.JPopupMenu menu,
                               com.sas.util.Command[] commands,
                               java.lang.Object executeParm)
Adds a set of commands to a JPopupMenu by constructing a appropriate menu items, including a submenus and/or separators as necessary.

Parameters:
menu - The menu to add to.
commands - The set of commands to add; may be null.
executeParm - The parameter to pass to command.execute() when a command's menu item is selected.
See Also:
addCommand(java.awt.Menu, com.sas.util.Command, java.lang.Object)

addCommand

public static void addCommand(javax.swing.JMenu menu,
                              com.sas.util.Command command,
                              java.lang.Object executeParm)
Adds a command to a JMenu by constructing an appropriate menu item, including a submenu or separator as necessary.

If command is an instance of MenuCommand, a JMenu will be created and added to menu; unless MenuCommand.isSeparator() returns true, in which case menu.addSeparator() will be called instead.

If command is an instance of BooleanDataInterface, a JCheckBoxMenuItem will be created and added to menu.

Parameters:
menu - The menu to add to.
command - The command to add.
executeParm - The parameter to pass to command.execute() when the command's menu item is selected.
See Also:
addCommands(java.awt.Menu, com.sas.util.Command[], java.lang.Object), JMenuItem, MenuCommand, BooleanData

addCommands

public static void addCommands(javax.swing.JMenu menu,
                               com.sas.util.Command[] commands,
                               java.lang.Object executeParm)
Adds a set of commands to a JMenu by constructing a appropriate menu items, including a submenus and/or separators as necessary.

Parameters:
menu - The menu to add to.
commands - The set of commands to add; may be null.
executeParm - The parameter to pass to command.execute() when a command's menu item is selected.
See Also:
addCommand(java.awt.Menu, com.sas.util.Command, java.lang.Object)

getEmptyCommandArray

public static com.sas.util.Command[] getEmptyCommandArray()
Returns a zero-length Command array.

Returns:
A zero-length array.

getEmptyCommandsInterfaceArray

public static CommandsInterface[] getEmptyCommandsInterfaceArray()
Returns a zero-length CommandsInterface array.

Returns:
A zero-length array.

getEmptyContextCommandsInterfaceArray

public static ContextCommandsInterface[] getEmptyContextCommandsInterfaceArray()
Returns a zero-length ContextCommandsInterface array.

Returns:
A zero-length array.



Copyright © 2009 SAS Institute Inc. All Rights Reserved.