Re: Grouping of plug-in actions

by enkonyito » Thu Nov 03, 2016 4:29 am

What do you think about this?

Code: Select all

    // Add menus to menu bar
    JMenuBar menuBar = new JMenuBar();
    fileMenu.addSeparator(); // test (enkonyito)
    menuBar.add(fileMenu);
    editMenu.addSeparator(); // test (enkonyito)
    menuBar.add(editMenu);
    furnitureMenu.addSeparator(); // test (enkonyito)
    menuBar.add(furnitureMenu);
    if (controller.getPlanController().getView() != null) {
      planMenu.addSeparator(); // test (enkonyito)
      menuBar.add(planMenu);
    }
    if (controller.getHomeController3D().getView() != null) {
      preview3DMenu.addSeparator(); // test (enkonyito)
      menuBar.add(preview3DMenu);
    }
    menuBar.add(helpMenu);

    // Add plugin actions menu items
    // debut test (enkonyito)
    // Create missing menu
    for (Action pluginAction : this.pluginActions) {
      String pluginMenu = (String)pluginAction.getValue(PluginAction.Property.MENU.name());
      if (pluginMenu != null) {
        boolean pluginMenuExisting = false;
        for (int i = 0; i < menuBar.getMenuCount(); i++) {
          JMenu menu = menuBar.getMenu(i);
          if (menu.getText().equals(pluginMenu)) {
            pluginMenuExisting = true;
            break;
          }
        }
        if (!pluginMenuExisting) {
          // Create missing menu before last menu
          JMenu menu = new JMenu(pluginMenu);
          menuBar.add(menu, menuBar.getMenuCount() - 1);
        }
      }
    }
    // Group plug-in actions by menu
    for (int i = 0; i < menuBar.getMenuCount(); i++) {
      JMenu menu = menuBar.getMenu(i);
      for (Plugin plugin : this.plugins) {
        boolean pluginActionAdded = false;
        createActionsPlugin(plugin);
        for (Action pluginAction : this.actionsPlugin) {
          String pluginMenu = (String)pluginAction.getValue(PluginAction.Property.MENU.name());
          if (pluginMenu != null) {
            if (menu.getText().equals(pluginMenu)) {
              // Add menu item to existing menu
              menu.add(new ResourceAction.MenuItemAction(pluginAction));
              pluginActionAdded = true;
            }
          }
        }
        if (pluginActionAdded) {
          menu.addSeparator();
        }
      } 
    }
    // fin test (enkonyito)
  
  //debut test (enkonyito)
  private void createActionsPlugin(Plugin plugin) {
    this.actionsPlugin = new ArrayList<Action>();
    if (plugin != null) {
      for (final PluginAction pluginAction : plugin.getActions()) {
        // Create a Swing action adapter to plug-in action
        this.actionsPlugin.add(new ActionAdapter(pluginAction)); 
      }
    }
  }
  //fin test (enkonyito)
before
Image

after
Image