Search in sources :

Example 1 with MenuCreator

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);
}
Also used : MenuCreator(org.apache.jmeter.gui.plugin.MenuCreator) IOException(java.io.IOException) IOException(java.io.IOException) JMenu(javax.swing.JMenu)

Example 2 with MenuCreator

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);
        }
    }
}
Also used : MenuCreator(org.apache.jmeter.gui.plugin.MenuCreator) JMenuItem(javax.swing.JMenuItem)

Example 3 with MenuCreator

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();
    }
}
Also used : MenuCreator(org.apache.jmeter.gui.plugin.MenuCreator)

Example 4 with MenuCreator

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);
    }
}
Also used : MenuCreator(org.apache.jmeter.gui.plugin.MenuCreator) JComponent(javax.swing.JComponent) Component(java.awt.Component) JMenuItem(javax.swing.JMenuItem) MenuElement(javax.swing.MenuElement) JMenu(javax.swing.JMenu)

Aggregations

MenuCreator (org.apache.jmeter.gui.plugin.MenuCreator)4 JMenu (javax.swing.JMenu)2 JMenuItem (javax.swing.JMenuItem)2 Component (java.awt.Component)1 IOException (java.io.IOException)1 JComponent (javax.swing.JComponent)1 MenuElement (javax.swing.MenuElement)1