Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Contextual Menu visibility(I have to play with the context menu visibility depending on a model decision)
Contextual Menu visibility [message #516943] Thu, 25 February 2010 15:03 Go to next message
Juan Lagostena is currently offline Juan LagostenaFriend
Messages: 4
Registered: November 2009
Junior Member
Hi everyone,

I have some problems with a contextual menu, maybe you can help me. I have a tree view where the context menu is hooked. This context menu is a kind of hybrid, because some contributions are made by "old school" actions , and the others are commands defined in the plugin.xml. I have a method to fill the context menu, and there, depending on the selection, the menu has to be shown or not. Let's see a piece of code:

public void createPartControl(Composite parent) {

private void hookContextMenu() {
	MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
	menuMgr.addMenuListener(new IMenuListener() {
		public void menuAboutToShow(IMenuManager manager) {
	Menu menu = menuMgr.createContextMenu(viewer.getControl());
	getSite().registerContextMenu(menuMgr, viewer);

private void fillContextMenu(IMenuManager manager) {
	(contribute with the "old school" actions")

I'm trying with a hack in the fill context menu, checking the decision there, and calling setVisible(false) to the manager, but the result is avoiding contribute the "actions" , but the commands are still there, and the menu is shown.

This kind of of hybrid is the result of an incomplete migration, I know that is not the ideal situation :S .

Any clue will be welcome.

Thanks on advance,


Re: Contextual Menu visibility [message #517178 is a reply to message #516943] Fri, 26 February 2010 14:12 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

The Menu contributions (commands) are basically being re-added after
your code is called (you get to go first :-)

You can make your commands visible on also based on the selection, using
visibleWhen and "activeMenuSelection" (or "selection", if your view
exports the viewer selection through its site).


<with variable="activeMenuSelection">
<count value="+"/>
<iterate operator="and">
<instanceof value="MyObject"/>


Paul Webster .platform.doc.isv/guide/workbench.htm

Previous Topic:Refresh TreeViewer with attached ViewerFilter
Next Topic:How can I use the DEL key for mutiple objectContributions?
Goto Forum:

Current Time: Mon May 21 18:55:12 GMT 2018

Powered by FUDForum. Page generated in 0.02013 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top