Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Menu Contributions/Populating a dynamic submenu"

 
m (Add a dynamic submenu to the ProblemView menu)
Line 3: Line 3:
 
In [[Menu Contributions/Problems View Example]] we added 2 dynamic menus.  You then have to implement CompoundContributionItem in your provided class.
 
In [[Menu Contributions/Problems View Example]] we added 2 dynamic menus.  You then have to implement CompoundContributionItem in your provided class.
  
      <menu id="org.eclipse.ui.views.problems.groupBy.menu"
+
<source lang="xml">
            label="%ProblemView.GroupBy.label"
+
<menu id="org.eclipse.ui.views.problems.groupBy.menu"
            mnemonic="%ProblemView.GroupBy.mnemonic">
+
    label="%ProblemView.GroupBy.label"
        <dynamic class="org.eclipse.ui.views.markers.internal.GroupByItems"
+
    mnemonic="%ProblemView.GroupBy.mnemonic">
                id="org.eclipse.ui.views.problems.groupBy.items"/>
+
  <dynamic class="org.eclipse.ui.views.markers.internal.GroupByItems"
      </menu>
+
      id="org.eclipse.ui.views.problems.groupBy.items"/>
 
+
</menu>
 +
</source>
  
 
When your menu is populated, you'll have your getContributionItems() method called:
 
When your menu is populated, you'll have your getContributionItems() method called:
  
 
+
<source lang="java">
protected IContributionItem[] getContributionItems() {
+
protected IContributionItem[] getContributionItems() {
      IContributionItem[] list = new IContributionItem[2];
+
    IContributionItem[] list = new IContributionItem[2];
      Map parms = new HashMap();
+
    Map parms = new HashMap();
      parms.put("groupBy", "Severity");
+
    parms.put("groupBy", "Severity");
      list[0] = new CommandContributionItem(null,
+
    list[0] = new CommandContributionItem(null,
              "org.eclipse.ui.views.problems.grouping",
+
            "org.eclipse.ui.views.problems.grouping",
              parms, null, null, null, "Severity", null,
+
            parms, null, null, null, "Severity", null,
              null, CommandContributionItem.STYLE_PUSH);
+
            null, CommandContributionItem.STYLE_PUSH);
 
   
 
   
      parms = new HashMap();
+
    parms = new HashMap();
      parms.put("groupBy", "None");
+
    parms.put("groupBy", "None");
      list[1] = new CommandContributionItem(null,
+
    list[1] = new CommandContributionItem(null,
              "org.eclipse.ui.views.problems.grouping",
+
            "org.eclipse.ui.views.problems.grouping",
              parms, null, null, null, "None", null, null,
+
            parms, null, null, null, "None", null, null,
              CommandContributionItem.STYLE_PUSH);
+
            CommandContributionItem.STYLE_PUSH);
      return list;
+
    return list;
}
+
}
 +
</source>

Revision as of 07:09, 25 September 2008

Add a dynamic submenu to the ProblemView menu

In Menu Contributions/Problems View Example we added 2 dynamic menus. You then have to implement CompoundContributionItem in your provided class.

<menu id="org.eclipse.ui.views.problems.groupBy.menu"
    label="%ProblemView.GroupBy.label"
    mnemonic="%ProblemView.GroupBy.mnemonic">
  <dynamic class="org.eclipse.ui.views.markers.internal.GroupByItems"
      id="org.eclipse.ui.views.problems.groupBy.items"/>
</menu>

When your menu is populated, you'll have your getContributionItems() method called:

protected IContributionItem[] getContributionItems() {
    IContributionItem[] list = new IContributionItem[2];
    Map parms = new HashMap();
    parms.put("groupBy", "Severity");
    list[0] = new CommandContributionItem(null,
            "org.eclipse.ui.views.problems.grouping",
            parms, null, null, null, "Severity", null,
            null, CommandContributionItem.STYLE_PUSH);
 
    parms = new HashMap();
    parms.put("groupBy", "None");
    list[1] = new CommandContributionItem(null,
            "org.eclipse.ui.views.problems.grouping",
            parms, null, null, null, "None", null, null,
            CommandContributionItem.STYLE_PUSH);
    return list;
}

Back to the top