org.peace_tools.core
Class ServerMenuHelper

java.lang.Object
  extended by org.peace_tools.core.AbstractMenuHelper
      extended by org.peace_tools.core.ServerMenuHelper
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener, javax.swing.event.ListSelectionListener, javax.swing.event.TableModelListener

public class ServerMenuHelper
extends AbstractMenuHelper
implements java.awt.event.ActionListener, javax.swing.event.ListSelectionListener

The server menu helper for the application. This class encapsulates the code related to the operations performed by various menu items in the "Server" menu. This class is typically created once from the MainFrame.createMenus() method. The primary motivation for introducing sub-menu handler classes is to improve code organization and minimize code clutter. Note that the ServerMenuHelper is essentially an event handler that is set on the various menu items in this class. This helper class also provides a createServerMenu() method that actually creates the "Server" menu.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.peace_tools.core.AbstractMenuHelper
AbstractMenuHelper.ActionType, AbstractMenuHelper.HelperType
 
Field Summary
private static java.lang.String[] ActionCmds
          The strings for the action commands generated by the various menu items in the help menu.
private static java.lang.String[] IconNames
          The icon file names for each menu title created by this helper.
private static java.lang.String[] MenuSubTitles
          The various sub menu titles that are used in the main menu.
private static java.lang.String[] MenuTitles
          The strings for each menu title created by this helper.
private  Server server
          The currently selected server entry (if any).
 
Fields inherited from class org.peace_tools.core.AbstractMenuHelper
contextItemList, mainFrame, table, tree
 
Constructor Summary
ServerMenuHelper(MainFrame mainFrame)
          The constructor.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent event)
           
private  void addServer()
          Add a new server entry.
 javax.swing.JMenu createServerMenu(javax.swing.JToolBar toolbar)
          Helper method to create the server menu.
private  void deleteServer()
          Helper method to verify and delete server entry.
 java.awt.event.ActionListener getActionListener()
          The action listener to handle actions created by this menu helper.
 javax.swing.event.ListSelectionListener getListSelectionListener(javax.swing.JTable table)
          The listener to be used in JTable to update tools & menu items.
 javax.swing.JMenuItem getMenuItem(AbstractMenuHelper.ActionType actionType, boolean mainMenu)
          Obtain a main menu item for the given action type.
 javax.swing.AbstractButton getTool(AbstractMenuHelper.ActionType actionType, boolean mainToolBar)
          Obtain a tool bar button for the given action type.
 javax.swing.event.TreeSelectionListener getTreeSelectionListener(javax.swing.JTree tree)
          The listener to be used in JTree to update tools & menu items.
 void valueChanged(javax.swing.event.ListSelectionEvent event)
          The selection listener/handler for a table.
 
Methods inherited from class org.peace_tools.core.AbstractMenuHelper
getHelperType, setEnabled, tableChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

server

private Server server
The currently selected server entry (if any). This value is updated by the list selection listener whenever a valid server entry is selected. If a valid server entry is not selected then this entry is set to null.


MenuTitles

private static final java.lang.String[] MenuTitles
The strings for each menu title created by this helper. The list of values are organized in the same order as the ordinal values of the ActionType enumeration. Preserving the order is important.


IconNames

private static final java.lang.String[] IconNames
The icon file names for each menu title created by this helper. The list of values are organized in the same order as the ordinal values of the ActionType enumeration. Preserving the order is important. Note that a prefix directory (such as: images/16x16) and a suffix extension (.png) is added when tools or menu items are created.


ActionCmds

private static final java.lang.String[] ActionCmds
The strings for the action commands generated by the various menu items in the help menu. The list of values are organized in the same order as the ordinal values of the ActionType enumeration. Preserving the order is important.


MenuSubTitles

private static final java.lang.String[] MenuSubTitles
The various sub menu titles that are used in the main menu. The sub menu titles are used to provide the user with a bit more verbose description on the action that will be performed by a given menu item. The list of values are organized in the same order as the ordinal values of the ActionType enumeration. Preserving the order is important.

Constructor Detail

ServerMenuHelper

public ServerMenuHelper(MainFrame mainFrame)
The constructor. This class is an action listener that responds to the user clicking on various menu items. Since this is only an action listener the constructor does not have any special tasks to perform.

Parameters:
mainFrame - The main frame that logically owns the "Help" menu in its top-level menu bar. This reference is saved in this class for future use.
Method Detail

createServerMenu

public javax.swing.JMenu createServerMenu(javax.swing.JToolBar toolbar)
Helper method to create the server menu. This method performs the actual task of creating the "Server" menu. This method has been introduced to organize all the methods related to the "Server" menu into a single class. This method is invoked from the MainMenu class to create the "Server" menu.

Parameters:
toolbar - The toolbar to which frequently used shortcuts can be added typically in the form of icons. If the toolbar is null, then shortcuts are not added.

getActionListener

public java.awt.event.ActionListener getActionListener()
Description copied from class: AbstractMenuHelper
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.

Specified by:
getActionListener in class AbstractMenuHelper
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.

getListSelectionListener

public javax.swing.event.ListSelectionListener getListSelectionListener(javax.swing.JTable table)
Description copied from class: AbstractMenuHelper
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.

Specified by:
getListSelectionListener in class AbstractMenuHelper
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.

valueChanged

public void valueChanged(javax.swing.event.ListSelectionEvent event)
The selection listener/handler for a table. This method is invoked by the core Swing classes whenever the user selects a specific entry in a list or table. This method essentially enables/disables various tool bar buttons and menu items based on the current job selection.

Note: Currently we only handle JTable and not JList.

Specified by:
valueChanged in interface javax.swing.event.ListSelectionListener
Parameters:
event - The selection event associated with this method. This event is not really used.

getMenuItem

public javax.swing.JMenuItem getMenuItem(AbstractMenuHelper.ActionType actionType,
                                         boolean mainMenu)
Description copied from class: AbstractMenuHelper
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.

Specified by:
getMenuItem in class AbstractMenuHelper
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.

getTool

public javax.swing.AbstractButton getTool(AbstractMenuHelper.ActionType actionType,
                                          boolean mainToolBar)
Description copied from class: AbstractMenuHelper
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.

Specified by:
getTool in class AbstractMenuHelper
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.

addServer

private void addServer()
Add a new server entry. This method is invoked when the user chooses to add a new server entry. This method is actually invoked from the actionPerformed() method. This method starts up a new instance of the ServerWizard that guides the user through the process of adding a new server entry and installing PEACE on the server.


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent event)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

deleteServer

private void deleteServer()
Helper method to verify and delete server entry. This is a helper method that was introduced to keep the code clutter in the actionPerformed() method to a minimum. This method uses the DeleteDialog helper dialog to actually delete the server entry.

Note: Deleting the server entry from the work space will cause the GUI to automatically reflect the changes.


getTreeSelectionListener

public javax.swing.event.TreeSelectionListener getTreeSelectionListener(javax.swing.JTree tree)
Description copied from class: AbstractMenuHelper
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.

Specified by:
getTreeSelectionListener in class AbstractMenuHelper
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.