Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » MenuManager as submenu with ISelectionListener
MenuManager as submenu with ISelectionListener [message #756456] Sun, 13 November 2011 15:20 Go to next message
kenny is currently offline kenny
Messages: 1
Registered: November 2011
Junior Member
I am creating a menubar, this menu bar contains a sub-menu (a menumanager).
I want this sub-menu to be disabled on app start-up.

My program also has jface treeviewer, I want to toggle sub-menu's state based on the selection in tree-view.

final MenuManager subMenu = new MenuManager("Main",null);
subMenu.add(mActionClose);    

MenuManager menubar = new MenuManager(...);
menubar.add(action1);
menubar.add(action2);
menubar.add(subMenu);


Some issues:
Actions are act as menu items, when I use Action (IAction) I can use setEnabled(false) to disable, I can not do it with MenuManager.

I can extend actions like this:
public class MyNewAction extends Action implements ISelectionListener, IWorkbenchAction {

    private final IWorkbenchWindow window;  	
    public RCNActionNewScriptKsh(IWorkbenchWindow window) {
		this.window = window;				
		window.getSelectionService().addSelectionListener(this);
     }
     public void selectionChanged(IWorkbenchPart part, ISelection selection) {
     }



With that I can listen to selections of tree-view items and act accordingly.
I can't do it with menu manager.


Please advice Smile

Re: MenuManager as submenu with ISelectionListener [message #756611 is a reply to message #756456] Mon, 14 November 2011 14:11 Go to previous messageGo to next message
Michal Sova is currently offline Michal Sova
Messages: 1
Registered: July 2009
Junior Member
Hi,

the treeviewer implements ISelectionProvider, you can getSelection(), addSelectionChangedListener(ISelectionChangedListener listener) .You can also set the treeviewer as a selection provider on your site in view/editor
getSite().setSelectionProvider(treeviewer ) and then listen to selection changes using an ISelectionListener attached to the selection service.
Re: MenuManager as submenu with ISelectionListener [message #756616 is a reply to message #756611] Mon, 14 November 2011 14:19 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Kenny, while you can't set a MenuManager to disabled you can setVisible(false). Does that work?

PW


Previous Topic:How to have Tree View inside a Table
Next Topic:Using EditingSupport.setValue(Object element, Object value) with strings.
Goto Forum:
  


Current Time: Sat Sep 20 02:10:54 GMT 2014

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

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