com.levigo.util.swing.action
Class DefaultMenuComponentFactory

java.lang.Object
  extended by com.levigo.util.swing.action.DefaultMenuComponentFactory
All Implemented Interfaces:
MenuComponentFactory, NamedMenuComponentFactory

public class DefaultMenuComponentFactory
extends Object
implements NamedMenuComponentFactory

Used by GUI components to create CommandAction-based toolbars, contextmenus and menus. This class not just returns GUI components, but can also return a collection of actions for a specific area (given by the template key or context name which is used as a key).

Version:
$Data$ $Revision$
Author:
l.boureanu@levigo.de, Carolin Köhler
See Also:
MenuComponentFactory

Field Summary
static String COMPONENT_KEY
          Accessor key for the structure identifier of JComponents builded by this factory.
static String COMPONENT_RESOURCE
          Accessor key for the resource name of JComponents builded by this factory.
protected  String factoryName
          Name of this menu component factory, usually its properties file name.
protected  List<BasicMenuComponentFactory> linkedMenuComponentFactories
          List of associated menu component factories
 
Fields inherited from interface com.levigo.util.swing.action.MenuComponentFactory
ACTIONS, CONTEXT_MENU_ACTIONS, MENU_ACTIONS, TOOLBAR_ACTIONS
 
Method Summary
 void addLinkedMenuComponentFactory(BasicMenuComponentFactory menuComponentFactory)
          Adds a menu component factory as linked factory to this factory.
static void addMenuComponentCreationListener(MenuComponentCreationListener listener)
          Adds a command creation listener to receive informations or failure messages of command creation process.
 Collection<String> getActions(String key)
          Create a collection of all currently available action names(!) for the given template key.
 Collection<String> getActionsForType(String key, String type)
          Create a collection of all currently available action names(!) for the given template key and action structure type.
 Collection<CommandAction> getCommandActions(String key, Context context)
          Create all currently available command actions for the given template key.
 JPopupMenu getContextMenu(String key, Context context)
          Create a JPopupMenu for the given template key or context name.
 JPopupMenu getContextMenu(String key, Context context, Action[] additionalActions)
          Create a JPopupMenu for the given template key or context name.
 String getFactoryName()
          Returns the name of this factory, usually its properties resource name.
static DefaultMenuComponentFactory getInstance(String propertiesFileName)
          Create instance for the factory.
 String getLinkedFactoryDescription()
          Returns a description of linked factories.
 NamedMenuComponentFactory[] getLinkedMenuComponentFactories()
          Returns an array of linked menu component factories
 String getLookupProperty(String key)
          Allows an application to programmatically request lookup properties.
 JMenu getMenu(String key, Context context)
          Create a JMenu for the given template key or context name.
 JMenu getMenu(String key, Context context, Action[] additionalActions)
          Create a JMenu for the given template key or context name.
 JMenuBar getMenuBar(String key, Context context)
          Create a JMenuBar for the given template key or context name.
static MenuComponentCreationListener[] getMenuComponentCreationListeners()
          Returns an array of currently registered creation listeners
 JToolBar getToolbar(String key, Context context)
          Create a JToolBar for the given template key or context name.
 JToolBar getToolbar(String key, Context context, Action[] additionalActions)
          Create a JToolbar for the given template key or context name.
 void insertLinkedMenuComponentFactory(int index, BasicMenuComponentFactory menuComponentFactory)
          Inserts a menu component factory at index position of linked factories.
static boolean isIgnoreEmptyActions()
          Returns an indicator whether to ignore actions with no commands configured.
 void putLookupProperty(String key, String value)
          Deprecated. use setLookupProperty(String, String) instead
 void removeLinkedMenuComponentFactory(BasicMenuComponentFactory menuComponentFactory)
          Removes a menu component factory of linked factories.
static void removeMenuComponentCreationListener(MenuComponentCreationListener listener)
          Removes a command creation listener.
 void reset()
          Clears, resets and reloads this factory instance.
static void setIgnoreEmptyActions(boolean ignore)
          Whether to ignore actions with no commands configured.
 void setLookupProperty(String key, String value)
          Allows an application to overwrite or set lookup properties programmatically.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMPONENT_RESOURCE

public static String COMPONENT_RESOURCE
Accessor key for the resource name of JComponents builded by this factory. The resource name can be accessed as client property of the component identified by this key.


COMPONENT_KEY

public static String COMPONENT_KEY
Accessor key for the structure identifier of JComponents builded by this factory. The structure key can be accessed as client property of the component identified by this key.


linkedMenuComponentFactories

protected List<BasicMenuComponentFactory> linkedMenuComponentFactories
List of associated menu component factories


factoryName

protected String factoryName
Name of this menu component factory, usually its properties file name.

Method Detail

setIgnoreEmptyActions

public static void setIgnoreEmptyActions(boolean ignore)
Whether to ignore actions with no commands configured. This usually happens if the actions.properties file is misconfigured - either unintentionally or by purpose.

It may be "misconfigured" by purpose to support a "maximum" action set in a modular product. In some deployments, not all actions may be available. If this is the case, we certainly do not want to paint menu entries for non-existent actions.

Parameters:
ignore -

isIgnoreEmptyActions

public static boolean isIgnoreEmptyActions()
Returns an indicator whether to ignore actions with no commands configured. This usually happens if the actions.properties file is misconfigured - either unintentionally or by purpose.

It may be "misconfigured" by purpose to support a "maximum" action set in a modular product. In some deployments, not all actions may be available. If this is the case, we certainly do not want to paint menu entries for non-existent actions.

Returns:
boolean

addMenuComponentCreationListener

public static void addMenuComponentCreationListener(MenuComponentCreationListener listener)
Adds a command creation listener to receive informations or failure messages of command creation process.

Parameters:
listener - the listener instance to add

removeMenuComponentCreationListener

public static void removeMenuComponentCreationListener(MenuComponentCreationListener listener)
Removes a command creation listener.

Parameters:
listener - the listener instance to remove

getMenuComponentCreationListeners

public static MenuComponentCreationListener[] getMenuComponentCreationListeners()
Returns an array of currently registered creation listeners

Returns:
MenuComponentCreationListener[] registered listeners

getInstance

public static DefaultMenuComponentFactory getInstance(String propertiesFileName)
Create instance for the factory. It can exist more types of the MenuComponentFactorybut just one instance.

The default properties File doesn't have to be used. It can be used the custom property File. If the custom property file is null then will be the default property file used.

Parameters:
propertiesFileName - custom properties file name
Returns:
instance of the MenuComponentFactory

getLinkedFactoryDescription

public String getLinkedFactoryDescription()
Returns a description of linked factories.


getFactoryName

public String getFactoryName()
Description copied from interface: NamedMenuComponentFactory
Returns the name of this factory, usually its properties resource name.

Specified by:
getFactoryName in interface NamedMenuComponentFactory
Returns:
name
See Also:
NamedMenuComponentFactory.getFactoryName()

getActions

public Collection<String> getActions(String key)
Description copied from interface: MenuComponentFactory
Create a collection of all currently available action names(!) for the given template key. The returning object is just a collection of action names (as Strings), not the real action objects. This method is a shortcut for getActionsForType(key, MenuComponentFactory .ACTIONS);

Specified by:
getActions in interface MenuComponentFactory
Parameters:
key - template key
Returns:
Collection of the actions names
See Also:
MenuComponentFactory.getActions(java.lang.String)

getCommandActions

public Collection<CommandAction> getCommandActions(String key,
                                                   Context context)
Description copied from interface: MenuComponentFactory
Create all currently available command actions for the given template key.

Specified by:
getCommandActions in interface MenuComponentFactory
Parameters:
key - template key for action structure
context - the returned actions refer to this context.
Returns:
Collection of created and available command actions for the given template key
See Also:
MenuComponentFactory.getCommandActions(java.lang.String, com.levigo.util.swing.action.Context)

getContextMenu

public JPopupMenu getContextMenu(String key,
                                 Context context)
Description copied from interface: MenuComponentFactory
Create a JPopupMenu for the given template key or context name.

Specified by:
getContextMenu in interface MenuComponentFactory
Parameters:
key - of the context menu which should be created
context - for the actions in the context menu. Actions in the context menu belong then in this context.

Returns:
Created context menu
See Also:
MenuComponentFactory.getContextMenu(java.lang.String, com.levigo.util.swing.action.Context)

getContextMenu

public JPopupMenu getContextMenu(String key,
                                 Context context,
                                 Action[] additionalActions)
Description copied from interface: MenuComponentFactory
Create a JPopupMenu for the given template key or context name. Additional actions NOT defined in the properties file can be specified with the parameter additionalActions.

Specified by:
getContextMenu in interface MenuComponentFactory
See Also:
MenuComponentFactory.getContextMenu(java.lang.String, com.levigo.util.swing.action.Context, javax.swing.Action[])

getMenu

public JMenu getMenu(String key,
                     Context context)
Description copied from interface: MenuComponentFactory
Create a JMenu for the given template key or context name.

Note:The JMenuBar is created outside of this factory. The created menus can be added in the JMenuBar!

Specified by:
getMenu in interface MenuComponentFactory
Parameters:
key - of the menu which should be created
context - for the actions in the menu. Actions in the menu belong then in this context.

Returns:
Created menu
See Also:
MenuComponentFactory.getMenu(java.lang.String, com.levigo.util.swing.action.Context)

getMenu

public JMenu getMenu(String key,
                     Context context,
                     Action[] additionalActions)
Description copied from interface: MenuComponentFactory
Create a JMenu for the given template key or context name. Additional actions NOT defined in the properties file can be specified with the parameter additionalActions.

Specified by:
getMenu in interface MenuComponentFactory
See Also:
MenuComponentFactory.getMenu(java.lang.String, com.levigo.util.swing.action.Context, javax.swing.Action[])

getToolbar

public JToolBar getToolbar(String key,
                           Context context)
Description copied from interface: MenuComponentFactory
Create a JToolBar for the given template key or context name.

Specified by:
getToolbar in interface MenuComponentFactory
Parameters:
key - of the toolbar which should be created
context - for the actions in the toolbar. Actions in the toolbar belong then in this context.

Returns:
Created toolbar
See Also:
MenuComponentFactory.getToolbar(java.lang.String, com.levigo.util.swing.action.Context)

getToolbar

public JToolBar getToolbar(String key,
                           Context context,
                           Action[] additionalActions)
Description copied from interface: MenuComponentFactory
Create a JToolbar for the given template key or context name. Additional actions NOT defined in the properties file can be specified with the parameter additionalActions.

Specified by:
getToolbar in interface MenuComponentFactory
See Also:
MenuComponentFactory.getToolbar(java.lang.String, com.levigo.util.swing.action.Context, javax.swing.Action[])

getMenuBar

public JMenuBar getMenuBar(String key,
                           Context context)
Description copied from interface: MenuComponentFactory
Create a JMenuBar for the given template key or context name.

Specified by:
getMenuBar in interface MenuComponentFactory
See Also:
MenuComponentFactory.getMenuBar(java.lang.String, com.levigo.util.swing.action.Context)

putLookupProperty

public void putLookupProperty(String key,
                              String value)
Deprecated. use setLookupProperty(String, String) instead

Allows an application to programmatically overwrite or set lookup properties. This is useful if some of the properties are not yet known in advance from its properties resource.

Parameters:
key -
value - The value of the given key, null if the key is not mapped to any value.

setLookupProperty

public void setLookupProperty(String key,
                              String value)
Allows an application to overwrite or set lookup properties programmatically. This is useful if some of the properties are not yet known in advance from its properties resource.

Parameters:
key -
value - The value of the given key, null if the key is not mapped to any value.
Throws:
NullPointerException - if the key or value is null.

getLookupProperty

public String getLookupProperty(String key)
Allows an application to programmatically request lookup properties.

Parameters:
key - A key to look up
Returns:
value The value of the given key, null if the key is not mapped to any value.
Throws:
NullPointerException - if the key is null.

getActionsForType

public Collection<String> getActionsForType(String key,
                                            String type)
Description copied from interface: MenuComponentFactory
Create a collection of all currently available action names(!) for the given template key and action structure type. The returning object is just a collection of action names (as Strings), not the real action objects.

Specified by:
getActionsForType in interface MenuComponentFactory
Parameters:
key - template key
type - structure type like MenuComponentFactoryMenuComponentFactory.ACTIONS, MenuComponentFactoryMenuComponentFactory.CONTEXT_MENU_ACTIONS,MenuComponentFactoryMenuComponentFactory.MENU_ACTIONS,MenuComponentFactoryMenuComponentFactory.TOOLBAR_ACTIONS
Returns:
Collection of the actions names
See Also:
MenuComponentFactory.getActionsForType(java.lang.String, java.lang.String)

getLinkedMenuComponentFactories

public NamedMenuComponentFactory[] getLinkedMenuComponentFactories()
Returns an array of linked menu component factories

Returns:
NamedMenuComponentFactory[] linked menu component factories.

addLinkedMenuComponentFactory

public void addLinkedMenuComponentFactory(BasicMenuComponentFactory menuComponentFactory)
Adds a menu component factory as linked factory to this factory.

Parameters:
menuComponentFactory - factory to add

removeLinkedMenuComponentFactory

public void removeLinkedMenuComponentFactory(BasicMenuComponentFactory menuComponentFactory)
Removes a menu component factory of linked factories.

Parameters:
menuComponentFactory - factory to remove

insertLinkedMenuComponentFactory

public void insertLinkedMenuComponentFactory(int index,
                                             BasicMenuComponentFactory menuComponentFactory)
Inserts a menu component factory at index position of linked factories.

Parameters:
index - index of factory
menuComponentFactory - factory to insert

reset

public void reset()
Clears, resets and reloads this factory instance. This is useful if the property sources have been changed and should be reload.



Copyright © 1995-2020 levigo holding gmbh. All Rights Reserved.