org.peace_tools.core
Class JobMenuHelper

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

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

The file menu helper for the application. This class encapsulates the code related to the operations performed by various menu items in the "Job" 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 JobMenuHelper is essentially an event handler that is set on the various menu items in this class. This helper class also provides a createJobMenu() method that actually creates the file 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 CANT_ABORT_JOB
          An error message that is formatted (to fill-in missing information) and displayed to the user if aborting a job fails.
private static java.lang.String CANT_FIND_SERVER
          An error message that is formatted (to fill-in missing information) and displayed to the user when a server entry could not be successfully located to abort a job.
private  Job job
          The currently selected job entry (if any).
private static java.lang.String[] MenuSubTitles
          The various sub menu titles that are used in the main menu.
private static java.lang.String SESSION_PURPOSE
          An error message that is formatted (to fill-in missing information) and displayed to the user as the reason for making a remote server connection.
private static java.lang.String SUCCESS_MSG
          A success message that is formatted (to fill-in missing information) and displayed to the user indicating that the job was aborted.
private static java.lang.String SURE_ABORT_JOB
          An verification message that is formatted (to fill-in missing information) and displayed to the user just before a job is aborted on a server.
 
Fields inherited from class org.peace_tools.core.AbstractMenuHelper
contextItemList, mainFrame, table, tree
 
Constructor Summary
JobMenuHelper(MainFrame mainFrame)
          The constructor.
 
Method Summary
 void abortJob(Job job)
          Method to abort a job running on a server.
 void actionPerformed(java.awt.event.ActionEvent event)
           
 javax.swing.JMenu createJobMenu(javax.swing.JToolBar toolbar, AbstractMenuHelper vmh)
          Helper method to create the job menu.
 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

job

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


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.


CANT_FIND_SERVER

private static final java.lang.String CANT_FIND_SERVER
An error message that is formatted (to fill-in missing information) and displayed to the user when a server entry could not be successfully located to abort a job.

See Also:
Constant Field Values

SURE_ABORT_JOB

private static final java.lang.String SURE_ABORT_JOB
An verification message that is formatted (to fill-in missing information) and displayed to the user just before a job is aborted on a server.

See Also:
Constant Field Values

CANT_ABORT_JOB

private static final java.lang.String CANT_ABORT_JOB
An error message that is formatted (to fill-in missing information) and displayed to the user if aborting a job fails.

See Also:
Constant Field Values

SESSION_PURPOSE

private static final java.lang.String SESSION_PURPOSE
An error message that is formatted (to fill-in missing information) and displayed to the user as the reason for making a remote server connection.

See Also:
Constant Field Values

SUCCESS_MSG

private static final java.lang.String SUCCESS_MSG
A success message that is formatted (to fill-in missing information) and displayed to the user indicating that the job was aborted.

See Also:
Constant Field Values
Constructor Detail

JobMenuHelper

public JobMenuHelper(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 "File" menu in its top-level menu bar. This reference is saved in this class for future use.
Method Detail

createJobMenu

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

Parameters:
toolbar - The tool bar to which frequently used shortcuts can be added typically in the form of icons. If the tool bar is null, then shortcuts are not added.
vmh - The view menu helper associated with the main frame. This entry is used to create menu entry for viewing the "Jobs" tab.

actionPerformed

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

abortJob

public void abortJob(Job job)
Method to abort a job running on a server. This method is a convenience method that can be used to abort a job that is currently running on a server. This method performs the following tasks:

Parameters:
job - The job to be aborted. This entry cannot be null.

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 for any major information. So it can be null.

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.

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.