Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Enable/disable command handlers depending on command parameter(Enable/disable command handlers depending on command parameter value)
Enable/disable command handlers depending on command parameter [message #1001988] Thu, 17 January 2013 12:00 Go to next message
Timo Rohrberg is currently offline Timo Rohrberg
Messages: 28
Registered: September 2011
Location: Karlsruhe
Junior Member
Hello everybody,

is it somehow possible to enable/disable a command handler (declaratively or programmatically) depending on the particular value of a command parameter passed to the command it handles?

Background: In my RCP application, one bundle defines a custom command to open a custom editor. The content to be loaded within this editor (i.e. the actual editor input) is defined by one or more parameters passed to the command. The bundle providing the editor (different from the one defining the command) also provides the handler to this command which actually opens the editor with the correct editor input. A third bundle now uses the command for a number of menu entries. For each different menu entry, the command is paramerized with another parameter value to define which content should be loaded into the editor by clicking the particular menu entry.

The requirement now is to enable/disable the handler for certain command parameter values depending on comparing those values with some global application state. In certain application states, particular editor inputs cannot be constructed and thus, the corresponding menu entry should be disabled.

I was thinking of using custom PropertyTester implementations. The problem is that I cannot access the command parameter value within those implementations...

Do you guys have an idea how this could be solved? Maybe there's an approach which I did not consider so far...

Thanks for any hints.

Regards
Timo
Re: Enable/disable command handlers depending on command parameter [message #1005645 is a reply to message #1001988] Sun, 27 January 2013 21:51 Go to previous message
John Steele is currently offline John Steele
Messages: 49
Registered: January 2010
Member
Hey,

Take a look at the IHandlerService and ICommandService:
IHandlerService hService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
ICommandService cService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);


Get the actual command programmatically:
Command command = cService.getCommand("openEditorCommand");


Get the command prarameters:
IParameter p = command.getParameter("inputParam");


Get the current application state:
IEvaluationContext eContext = hService.getCurrentState();
InputSourceProvider sProvider = (InputSourceProvider) eContext.getVariable("inputSourceProvider");


Browse through the API of those services, and I'm sure you'll find the appropriate solution.

Hope this helps.

j
Previous Topic:embed audio player
Next Topic:Hiding and restoring a view in RCP
Goto Forum:
  


Current Time: Sat Aug 23 15:28:19 EDT 2014

Powered by FUDForum. Page generated in 0.06145 seconds