Home » Eclipse Projects » Eclipse Platform » How to programmatically create ParameterizedCommand
| |
Re: How to programmatically create ParameterizedCommand [message #510806 is a reply to message #510794] |
Thu, 28 January 2010 12:16 |
Gerald Rosenberg Messages: 106 Registered: July 2009 |
Senior Member |
|
|
In article <hjsdut$gvk$1@build.eclipse.org>, pwebster@ca.ibm.com says...
>
> Gerald Rosenberg wrote:
> > Trying to figure out how to programmatically define and add parameters to a Command.
> >
>
> There's no public definition of a Parameter, only
> org.eclipse.ui.internal.commands.Parameter ... see
> org.eclipse.ui.internal.commands.CommandPersistence.readComm andsFromRegistry(IConfigurationElement[],
> int, ICommandService) and
> org.eclipse.ui.internal.commands.CommandPersistence.readPara meters(IConfigurationElement,
> List, ICommandService) for an example of how we define a Command with
> IParameters in the workbench.
>
> PW
Yes, I have been looking at those. Seems that Parameters can only be statically defined and valued
at design-time. Bummer.
So, maybe I should back up and ask the question this way. I am generating and executing commands
programmatically. While I could generate *alot* of discrete commands, I would prefer to just add
some run-time determined data to a chosen command just before execution. A key, value string pair
is sufficient. Is there some other command mechanism I could use?
Thanks...
|
|
|
Re: How to programmatically create ParameterizedCommand [message #510834 is a reply to message #510806] |
Thu, 28 January 2010 18:42 |
Gerald Rosenberg Messages: 106 Registered: July 2009 |
Senior Member |
|
|
In article <MPG.25cb63924e994b939896d3@news.eclipse.org>, gerald@certiv.net says...
>
> In article <hjsdut$gvk$1@build.eclipse.org>, pwebster@ca.ibm.com says...
> >
> > Gerald Rosenberg wrote:
> > > Trying to figure out how to programmatically define and add parameters to a Command.
> > >
> >
> > There's no public definition of a Parameter, only
> > org.eclipse.ui.internal.commands.Parameter ... see
> > org.eclipse.ui.internal.commands.CommandPersistence.readComm andsFromRegistry(IConfigurationElement[],
> > int, ICommandService) and
> > org.eclipse.ui.internal.commands.CommandPersistence.readPara meters(IConfigurationElement,
> > List, ICommandService) for an example of how we define a Command with
> > IParameters in the workbench.
> >
> > PW
>
> Yes, I have been looking at those. Seems that Parameters can only be statically defined and valued
> at design-time. Bummer.
>
> So, maybe I should back up and ask the question this way. I am generating and executing commands
> programmatically. While I could generate *alot* of discrete commands, I would prefer to just add
> some run-time determined data to a chosen command just before execution. A key, value string pair
> is sufficient. Is there some other command mechanism I could use?
>
> Thanks...
Looks like I can package the parameters in a subclass of the command's event parameter (and
retrieve using ExecutionEvent#getTrigger). Unless there is a better alternative?
Thanks...
|
|
|
Re: How to programmatically create ParameterizedCommand [message #510835 is a reply to message #510806] |
Thu, 28 January 2010 18:52 |
|
Gerald Rosenberg wrote:
>
> Yes, I have been looking at those. Seems that Parameters can only be statically defined and valued
> at design-time. Bummer.
>
> So, maybe I should back up and ask the question this way. I am generating and executing commands
> programmatically. While I could generate *alot* of discrete commands, I would prefer to just add
> some run-time determined data to a chosen command just before execution. A key, value string pair
> is sufficient. Is there some other command mechanism I could use?
ah, OK. Yes, the parameterization of commands is very much a static
thing. It's designed to accommodate things like keybindings and menu
items, that are very static once instantiated.
If you are executing your commands programmatically, there are a couple
of options.
You can take any defined command and execute it through the
org.eclipse.ui.handlers.IHandlerService. You can also modify the
application context (which is an IEvaluationContext) before executing
the command.
example (add appropriate check before casting):
ExecutionEvent event = handlerService.createExecutionEvent(cmd, null);
IEvaluationContext c
= (IEvaluationContext) event.getApplicationContext();
c.addVariable("my.data", new MyObject());
cmd.executeWithChecks(event);
You could do a similar thing by creating and contributing an
AbstractSourceProvider (extension point org.eclipse.ui.services). It's
a lot more work, but it would make the variables available for when any
event executed your command ... that might not be necessary in your case.
Later,
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
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
|
|
|
Goto Forum:
Current Time: Thu Apr 25 15:59:19 GMT 2024
Powered by FUDForum. Page generated in 0.03619 seconds
|