Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Local toolbar of a view
Local toolbar of a view [message #542511] Fri, 25 June 2010 07:24 Go to next message
Martin Lange is currently offline Martin LangeFriend
Messages: 16
Registered: May 2010
Location: Munich, Germany
Junior Member

Hi,

I have a small problem and hope somebody can help me.

I have implemented a view (... extends ViewPart ...). The only control in this view is a TableViewer which I set as the selection provider for the Site.

@Override
public void createPartControl(Composite parent)
{
     // ...
     // create TableViewer
     // ...
     getSite().setSelectionProvider(tableViewer)
}


I also added a local toolbar for this view through a menuContribution in my plugin.xml. The commands in this toolbar only have a default handler assigned. The default handler implements the isEnabled method to enable/disable the command depending on the selection of the view.

@Override
public boolean isEnabled() 
{
     ISelection sel = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection("id of my view");
     if (/* case a */)
           return true;
     return false;
}


Imho the isEnabled method of my CommandHandler should be called everytime the selection in my view changes, but it does not.

What have I to implement also, that I can react in the isEnabled method on the selections in my view.

Thanks in advance.

--Martin
Re: Local toolbar of a view [message #542604 is a reply to message #542511] Fri, 25 June 2010 12:12 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

declarative enabledWhen will get updated based on the variables it uses
as they change (like "selection" or "activePart").

If you declare you handlers in your plugin.xml, you probably have to
break them out to the org.eclipse.ui.handlers extension point if you
want to use enabledWhen to provide the enabled state with a core expression.


With programmatic enablement, its the responsibility of the handler to
fire an event when its enabled state changes... use AbstractHandler and
org.eclipse.core.commands.AbstractHandler.setBaseEnabled(boo lean), which
will fire the event for you. You would probably have to add a selection
listener to your window/page selection service. The other alternative
is to provide a core Expression and use IEvaluationService (it provides
the same level of variable notification as the enabledWhen declarative
expression)


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:Different height in different table rows
Next Topic:Center wizard relative to workbench
Goto Forum:
  


Current Time: Sun Dec 05 05:59:42 GMT 2021

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

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

Back to the top