Skip to main content


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 05:15 Go to next message
Craig Foote is currently offline Craig FooteFriend
Messages: 217
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 11:56 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
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: Fri Apr 26 09:34:12 GMT 2024

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

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

Back to the top