use of org.apache.jmeter.gui.plugin.MenuCreator in project jmeter by apache.
the class JMeterMenuBar method createMenuBar.
/**
* Creates the MenuBar for this application. I believe in my heart that this
* should be defined in a file somewhere, but that is for later.
*/
public void createMenuBar() {
this.menuCreators = new ArrayList<>();
try {
List<String> listClasses = ClassFinder.findClassesThatExtend(JMeterUtils.getSearchPaths(), new Class[] { MenuCreator.class });
for (String strClassName : listClasses) {
try {
log.debug("Loading menu creator class: {}", strClassName);
Class<?> commandClass = Class.forName(strClassName);
if (!Modifier.isAbstract(commandClass.getModifiers())) {
log.debug("Instantiating: {}", commandClass);
MenuCreator creator = (MenuCreator) commandClass.newInstance();
menuCreators.add(creator);
}
} catch (Exception e) {
log.error("Exception registering {} with implementation: {}", MenuCreator.class, strClassName, e);
}
}
} catch (IOException e) {
log.error("Exception finding implementations of {}", MenuCreator.class, e);
}
makeFileMenu();
makeEditMenu();
makeRunMenu();
makeOptionsMenu();
makeHelpMenu();
makeSearchMenu();
this.add(fileMenu);
this.add(editMenu);
this.add(searchMenu);
this.add(runMenu);
this.add(optionsMenu);
for (MenuCreator menuCreator : menuCreators) {
JMenu[] topLevelMenus = menuCreator.getTopLevelMenus();
for (JMenu topLevelMenu : topLevelMenus) {
this.add(topLevelMenu);
}
}
this.add(helpMenu);
}
use of org.apache.jmeter.gui.plugin.MenuCreator in project jmeter by apache.
the class JMeterMenuBar method addPluginsMenuItems.
/**
* @param menu
* @param menuCreators
* @param location
*/
private void addPluginsMenuItems(JMenu menu, List<MenuCreator> menuCreators, MENU_LOCATION location) {
boolean addedSeparator = false;
for (MenuCreator menuCreator : menuCreators) {
JMenuItem[] menuItems = menuCreator.getMenuItemsAtLocation(location);
for (JMenuItem jMenuItem : menuItems) {
if (!addedSeparator) {
menu.addSeparator();
addedSeparator = true;
}
menu.add(jMenuItem);
}
}
}
use of org.apache.jmeter.gui.plugin.MenuCreator in project jmeter by apache.
the class JMeterMenuBar method localeChanged.
/** {@inheritDoc} */
@Override
public void localeChanged(LocaleChangeEvent event) {
updateMenuElement(fileMenu);
updateMenuElement(editMenu);
updateMenuElement(searchMenu);
updateMenuElement(runMenu);
updateMenuElement(optionsMenu);
updateMenuElement(helpMenu);
for (MenuCreator creator : menuCreators) {
creator.localeChanged();
}
}
use of org.apache.jmeter.gui.plugin.MenuCreator in project jmeter by apache.
the class JMeterMenuBar method updateMenuElement.
/**
* <p>Refreshes all texts in the menu and all submenus to a new locale.</p>
*
* <p>Assumes that the item name is set to the resource key, so the resource can be retrieved.
* Certain action types do not follow this rule, @see JMeterMenuBar#isNotResource(String)</p>
*
* The Language Change event assumes that the name is the same as the locale name,
* so this additionally means that all supported locales must be defined as resources.
*
*/
private void updateMenuElement(MenuElement menu) {
Component component = menu.getComponent();
final String compName = component.getName();
if (compName != null) {
for (MenuCreator menuCreator : menuCreators) {
if (menuCreator.localeChanged(menu)) {
return;
}
}
if (component instanceof JMenu) {
final JMenu jMenu = (JMenu) component;
if (isResource(jMenu.getActionCommand())) {
jMenu.setText(JMeterUtils.getResString(compName));
}
} else {
final JMenuItem jMenuItem = (JMenuItem) component;
if (isResource(jMenuItem.getActionCommand())) {
jMenuItem.setText(JMeterUtils.getResString(compName));
} else if (ActionNames.CHANGE_LANGUAGE.equals(jMenuItem.getActionCommand())) {
jMenuItem.setText(JMeterUtils.getLocaleString(compName));
}
}
}
for (MenuElement subElement : menu.getSubElements()) {
updateMenuElement(subElement);
}
}
Aggregations