Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Handler enablement for a view's selection
Handler enablement for a view's selection [message #331565] Thu, 11 September 2008 18:36 Go to next message
Ryan Norris is currently offline Ryan NorrisFriend
Messages: 18
Registered: July 2009
Junior Member
I'm working on an application where I'm contributing actions to the
local toolbar/menu/popup of my views using commands/handlers/menus. I
want some of the handlers to be enabled based on there being a
selection. This seemed easy enough by building an enabledWhen
expression with a count of 1 or + on my handler definition in XML. When
my view is active, this works well, however, when my view is inactive
the handlers are not enabled because they are based on the selection of
the active view.

I'd like to apply an expression that enables/disables the buttons based
only on the selection of the view that's hosting them. This way, the
action could remain enabled in the local toolbar of one view when
another is active. Currently a toolbar button becomes disabled when the
active view is changed giving the appearance that the user has to click
the view to activate it and then click the toolbar button to invoke the
command. Before switching to commands/handlers, my actions would stay
enabled giving the appearance that only one click is needed to invoke
the action.

Is there a way, other than perhaps through a custom source provider, to
link the enablement for a command in a local menu/toolbar/popup to the
selection for the hosting view?

I'm using Eclipse 3.4

Thanks,
-Ryan Norris
Re: Handler enablement for a view's selection [message #331597 is a reply to message #331565] Fri, 12 September 2008 12:43 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You have 2 choices.

One is a common pattern, to instantiate the handler in the view itself
and have the handler simply look at the view selection and control its
own enabled state. The handler API allows it to fire an event on
enabled change, see org.eclipse.core.commands.AbstractHandler

The other is to create a property tester that can get your view selection.

IWorkbenchPart p = page.findViewReference("your.id").getPart(false);
if (p!=null) {
p.getSite().getSelectionProvider().getSelection() ... whatever
}

Your view would monitor its own selection change events, and call
org.eclipse.ui.services.IEvaluationService.requestEvaluation (String) for
that property (which would cause all core expressions using that
property tester to be re-evaluated). The important point is that simply
changing views would not cause a re-evaluation (and not change enabled
state).

You can set up the property tester to be specific to each view that you
need this for, or create one com.example.views.localSelection and use
args to specify the view id.

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/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


Previous Topic:Radio Buttons in Dynamic Menu
Next Topic:hierarchical (nested) content assist
Goto Forum:
  


Current Time: Sat Jul 06 17:21:13 GMT 2024

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

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

Back to the top