IHWMMenuToolbarCustomizer
Many applications will require you to add new items to the menubar or toolbar, both of which can be modified in the designer mode. Select Tools > Template Preferences > Menubar/Toolbar. There you will be able to:
- Rename any of the out of the box menu/toolbar items.
- Suppress any of the out of the box menu/toolbar items.
- Add a new menu/toolbar item.
Any bean can programmatically add themselves as a listener (via the IHWMMenuToolbarCustomizer interface) to the new menu/toolbar item. The bean will then implement the actionPerformed for the new menu/toolbar item.
/**
* This method is called by the HWPM engine to set the interface with
* which a bean can communicate directly with the HWPM classes.
* @param hwmFrameWork The interface with which a bean can
* communicate with HWPM.
*/
public void SetFrameWork(IHWMFrameWork hwmFrameWork)
m_hwmFrameWork = hwmFrameWork;
IHWMDataModel hwmDataModel = m_hwmFrameWork.GetDataModel();
// Add self as listener to any datamodel property change
hwmDataModel.addPropertyChangeListener(this);
//Setup callback hookup to my MenuItem
IMenuToolBarCustomizer hwmMenuToolBarCustomizer =
m_hwmFrameWork.GetMenuToolBarCustomizer();
JMenu menu = hwmMenuToolBarCustomizer.GetMenu("My Menu");
if (menu != null)
JMenuItem menuItem;
for (int nIndex=0; nIndex<menu.getItemCount(); nIndex++)
{
menuItem = menu.getItem(nIndex);
String strActionCommand = menuItem.getActionCommand();
if (menuItem.getActionCommand().
compareToIgnoreCase("My Test Item") == 0)
menuItem.setEnabled(true); //IMPORTANT: MUST DO THIS
menuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent actionEvent)
//DO WHATEVER NEEDS TO BE DONE HERE !!!
}
});
break;
} //if (menuItem.getActionCommand().compareToIgnoreCase(...)
} //for (int nIndex=0; nIndex<menu.getItemCount(); nIndex++)
} //if (menu != null)
}