Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » How to programmatically activate a command's handler?
How to programmatically activate a command's handler? [message #542487] Fri, 25 June 2010 01:15 Go to next message
Eclipse UserFriend
I have a command whose handler's "activeWhen" expression evaluates to
true if the selected item(s) adapt to my domain model. I'm unit testing
the code and of course there's no selection and so the command has no
active handler.

Is it possible to programmatically activate the declared handler and
invoke it? I'm thinking of perhaps creating an EvaluationContext with a
List of objects that adapt to my domain model then somehow using it to
activate the handler so I can invoke it. I understand I can create a new
Handler in my test case and use Command.setHandler(IHandler) but that
wouldn't be testing my declared handler. I believe IHandlerService has
some methods that might be of use, e.g. #executeCommandInContext but my
command is not parameterized.

Any ideas?

Craig
Re: How to programmatically activate a command's handler? [message #542596 is a reply to message #542487] Fri, 25 June 2010 07:56 Go to previous message
Eclipse UserFriend
Craig Foote wrote:
> Is it possible to programmatically activate the declared handler and
> invoke it? I'm thinking of perhaps creating an EvaluationContext with a
> List of objects that adapt to my domain model then somehow using it to
> activate the handler so I can invoke it. I understand I can create a new
> Handler in my test case and use Command.setHandler(IHandler) but that
> wouldn't be testing my declared handler. I believe IHandlerService has
> some methods that might be of use, e.g. #executeCommandInContext but my
> command is not parameterized.

You can either try and get the ISelectionService for your window and set
a selection on it (I'm not sure if that's possible) or you can use
executeCommandInContext(*). You can generate a ParameterizedCommand
from a normal Command, just don't pass in any parameters.

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:Eclipse Helios Hanging
Next Topic:eclipse helio
Goto Forum:
  


Current Time: Wed Jul 23 23:18:32 EDT 2025

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

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

Back to the top