org.peace_tools.core
Class AbstractMenuHelper

java.lang.Object
  extended by org.peace_tools.core.AbstractMenuHelper
All Implemented Interfaces:
java.util.EventListener, javax.swing.event.TableModelListener
Direct Known Subclasses:
FileMenuHelper, HelpMenuHelper, JobMenuHelper, ServerMenuHelper, ViewMenuHelper

public abstract class AbstractMenuHelper
extends java.lang.Object
implements javax.swing.event.TableModelListener

The base class for various menu helpers. The base class provides the common infrastructure for all menu helpers in the GUI. In addition, it also serves as a common interface to obtain and use various menu helpers in the core package.

See Also:
MainFrame.getMenuHelper(org.peace_tools.core.AbstractMenuHelper.HelperType)

Nested Class Summary
static class AbstractMenuHelper.ActionType
          Enumeration to enable referring to a specific type of action.
static class AbstractMenuHelper.HelperType
          Enumeration to enable convenient identification/classification of menu helper objects.
 
Field Summary
protected  java.util.ArrayList<javax.swing.AbstractButton> contextItemList
          The list of main menu items created by this helper.
private  AbstractMenuHelper.HelperType helperType
          The type of helper that the derived class represents.
protected  MainFrame mainFrame
          A convenience reference to the main frame that logically owns this menu helper.
protected  javax.swing.JTable table
          Reference to the JTable that last requested a selection listener.
protected  javax.swing.JTree tree
          Reference to the JTree that last requested a selection listener.
 
Constructor Summary
AbstractMenuHelper(AbstractMenuHelper.HelperType helperType, MainFrame mainFrame)
           
 
Method Summary
abstract  java.awt.event.ActionListener getActionListener()
          The action listener to handle actions created by this menu helper.
 AbstractMenuHelper.HelperType getHelperType()
          Determine the type of helper that this object represents.
abstract  javax.swing.event.ListSelectionListener getListSelectionListener(javax.swing.JTable table)
          The listener to be used in JTable to update tools & menu items.
abstract  javax.swing.JMenuItem getMenuItem(AbstractMenuHelper.ActionType actionType, boolean mainMenu)
          Obtain a main menu item for the given action type.
abstract  javax.swing.AbstractButton getTool(AbstractMenuHelper.ActionType actionType, boolean mainToolBar)
          Obtain a tool bar button for the given action type.
abstract  javax.swing.event.TreeSelectionListener getTreeSelectionListener(javax.swing.JTree tree)
          The listener to be used in JTree to update tools & menu items.
protected  void setEnabled(java.lang.String actionCommand, boolean enabled)
          Helper method to update status of all items for a given action command.
 void tableChanged(javax.swing.event.TableModelEvent tme)
          Default implementation for TableModelListener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mainFrame

protected final MainFrame mainFrame
A convenience reference to the main frame that logically owns this menu helper. This instance variable provides a convenient reference to the main frame that logically owns this menu helper. Each instance of the main frame has its own set of menu helpers.


contextItemList

protected java.util.ArrayList<javax.swing.AbstractButton> contextItemList
The list of main menu items created by this helper. This list is used to update the status of menu entries and tool bar buttons based on the current context. Selected entries are added to this list by derived classes when the getMenuItem() or getTool() method is called.


tree

protected javax.swing.JTree tree
Reference to the JTree that last requested a selection listener. This reference is updated to refer to the last JTree that requested a selection listener from this menu helper. This information is used to enable operation of the listener because currently in the event model it is impossible to obtain reference to the tree from the selection event.


table

protected javax.swing.JTable table
Reference to the JTable that last requested a selection listener. This reference is updated to refer to the last JTable that requested a selection listener from this menu helper. This information is used to enable operation of the listener because currently in the event model it is impossible to obtain reference to the table from the selection event.


helperType

private final AbstractMenuHelper.HelperType helperType
The type of helper that the derived class represents. This value is set when a menu helper object is instantiated and is never changed during the lifetime of the object.

Constructor Detail

AbstractMenuHelper

public AbstractMenuHelper(AbstractMenuHelper.HelperType helperType,
                          MainFrame mainFrame)
Method Detail

getHelperType

public AbstractMenuHelper.HelperType getHelperType()
Determine the type of helper that this object represents. This method can be used to determine the type of helper that this menu helper represents. This information is useful when dealing with menu helpers and creating tools because certain menu helpers only implement certain functionality.

Returns:
This method returns the type of helper that was specified when this menu helper was instantiated.

getMenuItem

public abstract javax.swing.JMenuItem getMenuItem(AbstractMenuHelper.ActionType actionType,
                                                  boolean mainMenu)
Obtain a main menu item for the given action type. This method must be used to create a suitable main menu entry for the given type of action. This action type must be supported by the menu helper in order to obtain a valid menu item. If the action is not supported, then this method returns null.

Note: The returned menu item has all the necessary information already filled-in. Do not modify the action command and other properties as it will interfere with correct operation of the menu item.

Parameters:
actionType - The action type for which a main menu item is to be created.
mainMenu - If this flag is true, then it indicates that the menu should be created to be used in the main menu. Otherwise it is assumed that the menu item will be used in a context sensitive popup menu.
Returns:
A JMenuItem corresponding to the given type of action. If the specified actionType is not supported by this menu helper, then this method returns null.

getActionListener

public abstract java.awt.event.ActionListener getActionListener()
The action listener to handle actions created by this menu helper. This method is a convenience method that can be used to obtain the actual action listener associated with this menu helper. The action listener is responsible for handling action call backs associated with the tools created by this menu helper.

Returns:
The action listener associated with this menu helper. This action listener must be used only with the tools and menu items created by this menu helper.

getTreeSelectionListener

public abstract javax.swing.event.TreeSelectionListener getTreeSelectionListener(javax.swing.JTree tree)
The listener to be used in JTree to update tools & menu items. This method is a convenience method that can be used to obtain a tree selection listener associated with this menu helper. The tree listener must be added to suitable JTree that display appropriate Workspace entries. The tree selection listener intercepts events generated by Java when the user clicks on specific entries in a JTree. This information is used to suitable enable/disable the tools generated by this listener.

Parameters:
tree - The JTree to which the tree selection listener is going to be added. This reference is maintained by the menu helper to handle tree selection events.
Returns:
The tree listener associated with this menu helper. If this listener does not provide a tree selection listener then this method returns null.

getListSelectionListener

public abstract javax.swing.event.ListSelectionListener getListSelectionListener(javax.swing.JTable table)
The listener to be used in JTable to update tools & menu items. This method is a convenience method that can be used to obtain a list selection listener associated with this menu helper. The list listener must be added to suitable JTable that display appropriate Workspace entries. The table selection listener intercepts events generated by Java when the user clicks on specific entries in a JTable. This information is used to suitable enable/disable the tools generated by this listener.

Note: The list selection listeners handle only single selection model for the table.

Parameters:
table - The JTable to which the list selection listener is going to be added. This reference is maintained by the menu helper to handle row selection events.
Returns:
The table listener associated with this menu helper. If this listener does not provide a table selection listener then this method returns null.

getTool

public abstract javax.swing.AbstractButton getTool(AbstractMenuHelper.ActionType actionType,
                                                   boolean mainToolBar)
Obtain a tool bar button for the given action type. This method must be used to create a suitable tool bar entry for the given type of action. This action type must be supported by the menu helper in order to obtain a valid menu item. If the action is not supported, then this method returns null.

Note: The returned button has all the necessary information already filled-in. Do not modify the action command and other properties as it will interfere with correct operation of the too bar button.

Parameters:
actionType - The action type for which a tool bar button is to be created.
mainToolBar - If this flag is true, then it indicates that the tool will be used in the main tool bar in PEACE. Otherwise it is is assumed that the tool will be used in a view specific tool bar.
Returns:
An abstract button corresponding to the given type of action. If the specified actionType is not supported by this menu helper, then this method returns null.

setEnabled

protected void setEnabled(java.lang.String actionCommand,
                          boolean enabled)
Helper method to update status of all items for a given action command. This method iterates over the list of items that have been added to the contextItemList and changes status of those items that have the same action command as the one specified.

Parameters:
actionCommand - The action command associated with a given set of items.
enabled - If this flag is true, then the item is enabled. Otherwise the item is disabled.

tableChanged

public void tableChanged(javax.swing.event.TableModelEvent tme)
Default implementation for TableModelListener. This method intercepts changes occurring to the table and translates the event to a suitable ListSelectionListener call if the derived class provides a suitable ListSelectionLister.

Specified by:
tableChanged in interface javax.swing.event.TableModelListener