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

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

Related

Different menu item types in Eclipse 4

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.

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.

Hide Resource Management Context Menu entries from a view

I have a custom view in my eclipse RCP and want to hide some of the actions from org.eclipse.ui.navigator.resources.ResourceMgmtActions when a user right clicks on a IProject resource. I just want to display "refresh" action and hide Close, Open, Close Unrelated projects, Build option from the context menu. Is there a way to do this declaratively via plugin.xml or pro grammatically without copying the code from ResourceMgmtActionProvider.java?

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.

Remove view name from Eclipse menu Window -> Show View

I need to remove the name/shortcut of the view which I have created from the Window->Show View menu and add them as a separate menu.
Is there any way to hide/remove its entry from Window->Show View menu.
You can add/remove any view from the "Show View" menu from the Customize Perspective / Menu Visibility tab:
To do the same thing programmatically would imply to follow the same course of action than the class org.eclipse.ui.internal.dialogs.CustomizePerspectiveDialog, and look into the method okPressed() for instance:
perspective.setShowViewActionIds(menu.getCheckedItemIds());
Vlad Ilie mentions in the comments:
as I only needed for the View to be completely inaccessible via usual GUI, activities were enough for me as per this blog post "eEclipse Activities – Hide / Display certain UI elements":
This would mean that programmatically the WorkbenchActivitySupport.setEnabledActivityIds(String[]) method can be used to enable or disable views after they've been introduced into an activity.
I would suggest you to go to window->Preferences or customize perspective. I think this is place from where we can controls the menu's to be displayed.