Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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
Craig Foote is currently offline Craig Foote
Messages: 195
Registered: July 2009
Senior Member
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
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

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: Thu Jul 24 06:51:31 EDT 2014

Powered by FUDForum. Page generated in 0.01611 seconds