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 10:03 Go to next message
Juan Lagostena is currently offline Juan Lagostena
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:

@Override
public void createPartControl(Composite parent) {

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


@SuppressWarnings("unchecked")
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,

Juan

Re: Contextual Menu visibility [message #517178 is a reply to message #516943] Fri, 26 February 2010 09:12 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6850
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).

example:

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

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .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: Sat Apr 19 06:09:18 EDT 2014

Powered by FUDForum. Page generated in 0.02046 seconds