Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "FAQ How do I build menus and toolbars programmatically?"

 
m
Line 10: Line 10:
 
and these interfaces help avoid unnecessary coupling between the items
 
and these interfaces help avoid unnecessary coupling between the items
 
and the containers presenting them.
 
and the containers presenting them.
 
  
 
So, for each toolbar or menu, you need to create a contribution
 
So, for each toolbar or menu, you need to create a contribution
Line 18: Line 17:
 
or <tt>CoolBarManager</tt>, respectively. The following snippet
 
or <tt>CoolBarManager</tt>, respectively. The following snippet
 
creates a top-level menu and a submenu, each with one action:
 
creates a top-level menu and a submenu, each with one action:
 +
 
<pre>
 
<pre>
 
   IMenuManager mainMenu = ...;//get ref to main menu manager
 
   IMenuManager mainMenu = ...;//get ref to main menu manager
Line 27: Line 27:
 
   menu1.add(menu2);
 
   menu1.add(menu2);
 
</pre>
 
</pre>
 
  
 
== See Also: ==
 
== See Also: ==
 
+
*[[FAQ_How_do_I_make_menus_with_dynamic_contents%3F]]
[[FAQ_How_do_I_make_menus_with_dynamic_contents%3F]]
+
*[[FAQ_What_is_the_difference_between_a_toolbar_and_a_cool_bar%3F]]
 
+
[[FAQ_What_is_the_difference_between_a_toolbar_and_a_cool_bar%3F]]
+
  
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>

Revision as of 22:23, 29 May 2006

Menus and toolbars in JFace are based on two key interfaces: IContributionItem and IContributionManager. A contribution manager is simply an object that contains contribution items. The major types of contribution managers are menus, toolbars, and status lines. Contribution items represent any object that is logically contained within a menu or a toolbar, such as actions, submenus, and separators. These interfaces abstract away the differences between the contexts in which actions can appear. An action doesn&#146;t care whether it is invoked from a toolbar or a menu, and these interfaces help avoid unnecessary coupling between the items and the containers presenting them.

So, for each toolbar or menu, you need to create a contribution manager. For menus, including drop-down menus, context menus, and submenus, create an instance of MenuManager. For toolbars or cool bars, create an instance of ToolBarManager or CoolBarManager, respectively. The following snippet creates a top-level menu and a submenu, each with one action:

   IMenuManager mainMenu = ...;//get ref to main menu manager
   MenuManager menu1 = new MenuManager("Menu &1", "1");
   menu1.add(new Action("Action 1") {});
   mainMenu.add(menu1);
   MenuManager menu2 = new MenuManager("Menu &2", "2");
   menu2.add(new Action("Action 2") {});
   menu1.add(menu2);

See Also:


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.

Back to the top