Bug #2341

MENUS: Top-Level Menu - Some mapped menu items not working

Added by Matthew Brooke over 16 years ago. Updated over 16 years ago.

Target version:
Start date:
Due date:
% Done:


Estimated time:


Five of the menu items mapped from ptii menus don't work under the new kepler
menu hierarchy:

File->Save As (in ptii was: File->SaveAs)
View->XML View (in ptii was: View->XML View)
Workflow->Run Window (in ptii was: View->Run Window)
Tools->Check System Settings (in ptii was: View->JVM Properties)
Help->Documentation (in ptii was: Help->Help)

1) None of the above have Actions associated in PTII - they all use
ActionListeners, from which Actions are created for use in the new Kepler menus.
All remaining menus work OK
2) There are other PTII menus that have had Actions created from
ActionListeners, so that's not the problem per se, but it might be somehow

Related issues

Blocked by Kepler - Bug #2337: TRACKING - MENUS: Top-Level Menu RevisionIn Progress01/18/2006


#1 Updated by Matthew Brooke over 16 years ago

This was happening because we were setting the Action.NAME, and the ptii code
uses the menu name to create a Factory to respond to the menu selection. I have
currently commented out the code that changes Action.NAME (since this was also
the cause of bug #2342) - however, this means that any menu items that should be
renamed for Kepler do not actually get renamed - they still have their old names
(specifically File->New->Graph Editor should be File->New Workflow->Blank, and
File->SaveAs should be File->Save As). Suggested fix shown further down the

Here's the culprit code (discovered by Christopher):

It looks like
is being called but for XML view and JVM properties the factory is

In the line marked --->, the factory is null for XML view


    /** Listener for view menu commands. */
    class ViewMenuListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            // Make this the default context for modal messages.
            System.out.println("TableauFrame.actionPerformed()" + e +
                    " " + _factoryContainer);
            if (_factoryContainer != null) {
                JMenuItem target = (JMenuItem) e.getSource();
                String actionCommand = target.getActionCommand();
                TableauFactory factory = (TableauFactory) _factoryContainer

--->            System.out.println("TableauFrame.actionPerformed(): factory " 
                        + factory);
                if (factory != null) {
                    Effigy tableauContainer = (Effigy) _tableau.getContainer();

                    try {
                        Tableau tableau = factory
                    } catch (Throwable throwable) {
                        // Copernicus might throw a java.lang.Error if
                        // jhdl.Main cannot be resolved
                        MessageHandler.error("Cannot create view",

            // NOTE: The following should not be needed, but
            // appears to have a bug in swing where repainting doesn't
            // properly occur.

In lieu of commenting out the Action.NAME assignment, however, it would be nice
if we could fix the above code so it looks for an Action first - something like

snippet from your quoted code, with new code added:

  JMenuItem target = (JMenuItem) e.getSource();

//NEW CODE -----------
  String actionCommand = null;

  Action action = target.getAction();
  if (action!=null) {

    //the following should be OK because GUIUtilities.addMenuItem()
    //automatically adds each incoming JMenuItems as a property of
    //the Action itself - see diva.gui.GUIUtilities.addMenuItem(),
    //line 202, ans so does kepler/src/exp/ptolemy/vergil/basic/
    // BasicGraphFrame.storeSubMenus() line 2519...

    JMenuItem origMItem  = (JMenuItem) action.getValue("menuitem");
    if (origMItem!=null) {
      actionCommand = origMItem.getActionCommand();
    } else {
      actionCommand = target.getActionCommand();
  } else {

//EDIT THIS ORIGINAL CODE - delete the "String":
    actionCommand = target.getActionCommand();
//        String actionCommand = target.getActionCommand();

//NEW CODE - close bracket:
// END --- 

#2 Updated by Matthew Brooke over 16 years ago

Christopher added the code changes to, which fixed
some of these menu items (the ones not in the File or Help menus. I then changed
the code in BasicGraphFrame to fix the remaining menu items.

#3 Updated by Redmine Admin over 9 years ago

Original Bugzilla ID was 2341

Also available in: Atom PDF