Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Difficulties setting the enablement of a command
Difficulties setting the enablement of a command [message #519773] Tue, 09 March 2010 21:51 Go to next message
John Cortell is currently offline John Cortell
Messages: 28
Registered: July 2009
Junior Member
I have a view with a command. I have the command appearing in the view's toolbar. The view has a TableViewer. I register the viewer as the selection provider for the workbench site, so that I can use a selection-based enablement expression in the comand handler definition (in the plugin.xml).

Here's my problem: the selection is a TreeNode. TreeNode.getValue() returns the *real* view model element for my view--let's say, com.acme.Customer. Now, I want the command to be enabled if the user selects a Customer, but disabled if he selects something else. (a) I can't figure out how to do that via the enablement expression. Doing an instanceof on the variable=selection won't help since that's a TreeNode, not a Customer (b) What if I wanted an even more complex enablement--one that needs to be programatic? The handler isn't called when I change the selection.

I've looked at a million write-ups on the web on commands and handlers and I'm just not finding the answer to what seems like a fairly simple thing. If would appreciate a pointer in the right direction.

Re: Difficulties setting the enablement of a command [message #519787 is a reply to message #519773] Wed, 10 March 2010 00:30 Go to previous message
John Cortell is currently offline John Cortell
Messages: 28
Registered: July 2009
Junior Member
The millionth-and-tenth writeup finally clued me in. The answer is to use a custom property tester. A property tester is a class which can be (indirectly) referenced in an enablement expression and which is instantiated and exercised at expression evaluation time. You can develop a property tester to do any amount of complex programmatic testing of, say, the viewer selection and respond with a true/false as to whether the command should be enabled (assuming you're using it in an "enabledWhen" element of a handler definition).

The writeup that clued me in was this very insightful and well written blog entry:
http://blog.richclientgui.com/?p=50
Previous Topic:build.xml gets deleted randomly
Next Topic:[Databinding] Modifying properties of bindings in a TableViewer
Goto Forum:
  


Current Time: Tue Sep 16 05:10:38 GMT 2014

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

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