Search in sources :

Example 1 with IProjectMenuPlugin

use of com.google.security.zynamics.binnavi.API.plugins.IProjectMenuPlugin in project binnavi by google.

the class CProjectNodeMenuBuilder method addPluginMenus.

/**
   * Adds the plugin-generated menus to the context menu.
   * 
   * @param menu The context menu where the menu items are added.
   */
private void addPluginMenus(final JComponent menu) {
    final List<IProjectMenuPlugin> plugins = new ArrayList<IProjectMenuPlugin>();
    for (@SuppressWarnings("rawtypes") final IPlugin plugin : PluginInterface.instance().getPluginRegistry()) {
        if (plugin instanceof IProjectMenuPlugin) {
            plugins.add((IProjectMenuPlugin) plugin);
        }
    }
    if (!plugins.isEmpty()) {
        boolean addedSeparator = false;
        for (final IProjectMenuPlugin plugin : plugins) {
            try {
                final List<JComponent> menuItems = plugin.extendProjectMenu(getPluginProjects());
                if (menuItems != null) {
                    for (final JComponent menuItem : menuItems) {
                        if (!addedSeparator) {
                            menu.add(new JSeparator());
                            addedSeparator = true;
                        }
                        menu.add(menuItem);
                    }
                }
            } catch (final Exception exception) {
                CUtilityFunctions.logException(exception);
                final String innerMessage = "E00088: " + "Plugin caused an unexpected exception";
                final String innerDescription = CUtilityFunctions.createDescription(String.format("The plugin %s caused an unexpected exception.", plugin.getName()), new String[] { "The plugin contains a bug." }, new String[] { "The plugin probably behaves erroneously from this point on but it remains active" });
                NaviErrorDialog.show(getParent(), innerMessage, innerDescription, exception);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) JComponent(javax.swing.JComponent) IProjectMenuPlugin(com.google.security.zynamics.binnavi.API.plugins.IProjectMenuPlugin) JSeparator(javax.swing.JSeparator) IPlugin(com.google.security.zynamics.binnavi.api2.plugins.IPlugin)

Aggregations

IProjectMenuPlugin (com.google.security.zynamics.binnavi.API.plugins.IProjectMenuPlugin)1 IPlugin (com.google.security.zynamics.binnavi.api2.plugins.IPlugin)1 ArrayList (java.util.ArrayList)1 JComponent (javax.swing.JComponent)1 JSeparator (javax.swing.JSeparator)1