|
|
|
|
|
Re: Passing parameters while executing command programmatically [message #334236 is a reply to message #334230] |
Wed, 28 January 2009 14:23 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
|
Raja Kannappan wrote:
> I followed your steps but ParameterizedCommand.generateCommand(command,
> params) returns null, even though command and params are valid objects.
> My code looks like this:
>
> ICommandService commandService = (ICommandService)
> getSite().getService(ICommandService.class);
> IHandlerService handlerService = (IHandlerService)
> getSite().getService(IHandlerService.class);
> Command showElement =
> commandService.getCommand("com.xyz.commands.showElement");
> Map<String, Object> params = new HashMap<String,
> Object>();
> params.put("viewId", ID);
> ParameterizedCommand paramShowElement =
> ParameterizedCommand.generateCommand(showElement, params);
> ExecutionEvent execEvent =
> handlerService.createExecutionEvent(paramShowElement, new Event());
> try {
> showElement.executeWithChecks(execEvent);
> } catch (Exception ex) {
> throw new RuntimeException("com.xyz.commands.showElement
> could not be executed");
> }
>
> Am I missing something? Thanks,
Does your command definition include a commandParameter? parameters are
defined with the command, and tend to be static in nature (or simple,
a viewId is acceptable). For example, our showView command takes the
viewId, and our definition looks like:
<command
name="%command.showView.name"
description="%command.showView.description"
categoryId="org.eclipse.ui.category.views"
id="org.eclipse.ui.views.showView"
defaultHandler="org.eclipse.ui.handlers.ShowViewHandler">
<commandParameter
id="org.eclipse.ui.views.showView.viewId"
name="%command.showView.viewIdParameter"
values="org.eclipse.ui.internal.registry.ViewParameterValues " />
<commandParameter
id="org.eclipse.ui.views.showView.makeFast"
name="%command.showView.makeFastParameter"
optional="true">
</commandParameter>
</command>
[/xml]
Other than that, use
handlerService.createExecutionEvent(paramShowElement, null) to create
the ExecutionEvent (if you don't have an SWT event, don't create one).
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/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
|
|
|
Powered by
FUDForum. Page generated in 0.05885 seconds