Different menu item types in Eclipse 4 - eclipse-rcp

When I right click on a menu and select Add child, I am presented with several options:
Handled Menu Item
Menu
Direct Menu Item
Dynamic Menu Contribution
VisibleWhen Core Expression
What is the difference between each of these choices?

Handled Menu Item
This is a menu item that uses a command id (and therefore one or more handlers).
Direct Menu Item
This is a menu item where you specify the class to handle the item directly without using a command id.
Menu
This adds a new sub-menu.
Dynamic Menu Contribution
This lets you specify a class that can add multiple menu items dynamically. See here
VisibleWhen Core Expression
This lets you add a 'core expression' to the current menu item to control when it is visible. See the Eclipse help for details of core expressions. Eclipse Oxygen also now supports Imperative Expressions where you can specify a Java class to control the menu visibility.

Related

Removing "Show In" menu items in Eclipse RCP application

I am developing an Eclipse RCP application, and would like to remove some of the items displayed in the "Show In" context menu. The items are placed in this menu by various plug-ins, and I would prefer to not have them there.
Adding a new entry to this menu is well documented: https://wiki.eclipse.org/FAQ_How_do_I_make_my_view_appear_in_the_Show_In_menu%3F
However, removing an existing entry seems problematic, since Views are listed in the "Show In" menu by virtue of them implementing the IShowInTarget interface. The resulting menu items do not have unique IDs that could be used to disable them via an Activity.
It seems to me like the only way to avoid listing a View defined by an existing plug-in in the "Show In" menu is to extend the plug-in class implementing this View.
The source code for the 'Show In' menu is org.eclipse.ui.internal.ShowInMenu.
This gets contributions from a number of places but I don't see anything that could be used to filter them.
'Extending the plug-in class implementing the view' is not really possible.

Eclipse e4: add commands to context menu

I defined several commands in my Application Model, say like openCommand, saveCommand. And I can add them to the menu bar or tool bar easily. Now I want them to also appear in the context menu of the edit part, how can this be done?
To be short, I want a menu item in main menu, a tool bar item in tool bar and another menu item in context menu. All these three items have the same function and thus should be mapped to the same command. I can do the first two but have no idea about the third.
Any help would be appreciated! Thanks a lot!
You define the context menu for a Part in the Menu section of the Part Descriptor in the application model. Add a 'Popup Menu' and give it a unique id. Add menu items to the popup menu in the normal way.
Tell Eclipse the menu is the context menu for a control using the EMenuService:
#Inject
private EMenuService menuService;
...
menuService.registerContextMenu(control, "menu id");

Eclipse toolbar shortcuts

Does anyone know how to get the default toolbar on Eclipse.
Basically it had all the shortcuts like AVD manager, SDK manager, new, etc etc...
I somehow lost a few of them. Now I am trying to reset things if possible.
Follow the below steps, might help you out :-
To hide a menu item or toolbar button:
1) Switch to the perspective that you want to configure.
2) Select command link Window > Customize Perspective....
3) Open the Menu Visibility or Tool Bar Visibility tab.
4) Find the item you want to hide. You can do this two ways:
Expand the menu or toolbar hierarchy to find the item you want to hide.
Click the Filter by command group check box to see a list of command groups which contribute items, and choose the command group the item you wish to hide. Then navigate to the item in the hierarchy in the Structure tree.
5)Hover over the item to get additional information:
a description of what the item does
the name of the command group which contributes the item (click the link in this item to switch to the Command Groups Availability tab with the appropriate command group selected).
any key bindings associated with the command the item performs (click the link in this item to open the Keys page of the Preferences dialog with the command selected, if possible).
if the item is dynamic, a preview of its current appearance (dynamic items are listed as [Dynamic]).
6) Uncheck the check box next to the item. Uncheck a menu to hide all its children.
7) Click OK to cause the changes to take effect.
Using the tooltip which appears over items, you can navigate to the Command Group Availability tab and make the entire command group unavailable if you wish to remove all menu items, toolbar buttons and keybindings of all commands contributed by the command group.

In Eclipse How to Enable and Disable Main Menu Items in Run time

During menu added into the main menu of eclipse which has sub-menus. I need these sub-menus to be enabled/disabled based on a condition
which I can check programmatically.
Enabling/Disabling the items via plugin.xml is static, even if a condition can be checked it is only after we click on the menu item.
How to happen at run time when the user clicks the Menu itself rather than the sub-menu items.
Use action enablement property in plugin.xml, refer to
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fextension-points%2Forg_eclipse_ui_actionSets.html

Is it possible to hide/remove arbitrary context menu items in Eclipse (3.6)

My question can be split into three:
Is it possible to hide/remove arbitrary context menu items in Eclipse (3.6) by ...
standard UI?
some existing plug-in?
custom plug-in?
I failed to find ways to do this by methods 1 and 2. If the only option is creating custom plug-in, could anyone push me towards the right direction where to start (I have some experience in Java, but not in Eclipse plug-ins).
You can hide menus or menu entries through the standard GUI: see help
To hide a menu item or toolbar button:
Switch to the perspective that you want to configure.
Select Window > Customize Perspective....
Open the Menu Visibility or Tool Bar Visibility tab.
Find the item you want to hide.
Uncheck the check box next to the item. Uncheck a menu to hide all its children.
Click OK to cause the changes to take effect.
But that will hide this entry from all the menus (contextual or not) in which it is present.
So it may not be as fine-grained as you want through the GUI.
You can also try it through a plugin (see also Menu contribution)
The first steps are pretty standard for using extensions in Eclipse.
Open the plugin.xml file and add the org.eclipse.ui.activities extension.
Then create an activity node and give it a unique ID.
Then create an activityPatternBinding node and use the unique ID for the activity to find the pattern node to the activity node.
The activityPatternBinding node requires that you supply a regular expression for the ID string of the UI element that you wish to hide.
The problem is that there appears to be at least 3 ways that menu items and toolbar buttons are added to the UI.
The first way is through the newer Command/Menu Extensions.
The second way is through the older ActionSets Extension.
Then there are other UI elements that appear to be hard coded into the Workbench and do not have ID strings and cannot be hidden using the Activities Extension. Luckily there are few of this third type of UI element.
Considering you are talking about the latest Eclipse, I will copy only the first way:
1/ Use the Plug-In Spy
The first way is to use the Plug-In Spy.
Press alt-shift-F2 and click on a menu item or toolbar button that you want to be hidden.
If there is an ID string under the heading "active action definition identifier" then you are in luck.
This item has been added using the Command Extension and you can use this ID as the pattern argument for the Activities Extension.
But not all items that have been added using the Command Extension present their ID string to the plug-in spy.
As a side note, the ID strings are period separated.
For instance the ID for a button might be "org.eclipse.ui.navigate.backwardHistory".
Regular expressions use the period to stand for any character. Luckily the period used as a wild card matches with actual period characters so you don't need to escape them if you don't want to. I find it makes it a bit easier to read if they are not escaped and it is highly unlikely it will cause any ambiguous matches.