Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » ParameterizedCommand.generateCommand
ParameterizedCommand.generateCommand [message #112314] Wed, 12 November 2008 16:14 Go to next message
Mark Freiheit is currently offline Mark FreiheitFriend
Messages: 30
Registered: July 2009
Member
Hello group.

I was trying to use the ParameterizedCommand.generateCommand(Command
command, Map parameters) method to create a ParameterizedCommand using my
import file command and a Map containing one entry
(ISources.ACTIVE_WORKBENCH_WINDOW_NAME,
partRef.getPage().getWorkbenchWindow()).

However, the generateCommand function returns null. I inspected the
generateCommand code which I will include at the bottom of this post. At
lines 306 through 313 of ParameterizedCommand.java, I observed that this
method iterates over the keys of the parameter map, and checks for the
value in the command itself. If the parameter is not already in the
command, null is returned.

I would expect this method to use the parameter in the passed in Map and
apply it to the Command. I think that I am misunderstanding how this
method should work. Would someone please help clarify the proper use of
the generateCommand method.

Thanks very much for your help -- Mark

P.S. - I work around this by creating an EvaluationContext, adding my
variables, creating an ExecutionEvent, then calling
command.executeWithChecks(executionEvent).

------------------------------------------------------------ -----------------

/**
* Take a command and a map of parameter IDs to values, and generate the
* appropriate parameterized command.
*
* @param command
* The command object. Must not be <code>null</code>.
* @param parameters
* A map of String parameter ids to objects. May be
* <code>null</code>.
* @return the parameterized command, or <code>null</code> if it could not
* be generated
* @since 3.4
*/
public static final ParameterizedCommand generateCommand(Command command,
Map parameters) {
// no parameters
if (parameters == null || parameters.isEmpty()) {
return new ParameterizedCommand(command, null);
}

try {
ArrayList parms = new ArrayList();
Iterator i = parameters.keySet().iterator();

// iterate over given parameters
while (i.hasNext()) {
String key = (String) i.next();
IParameter parameter = null;
// get the parameter from the command
parameter = command.getParameter(key);

// if the parameter is defined add it to the parameter list
if (parameter == null) {
return null;
}
ParameterType parameterType = command.getParameterType(key);
if (parameterType == null) {
parms.add(new Parameterization(parameter,
(String) parameters.get(key)));
} else {
AbstractParameterValueConverter valueConverter = parameterType
.getValueConverter();
if (valueConverter != null) {
String val = valueConverter.convertToString(parameters
.get(key));
parms.add(new Parameterization(parameter, val));
} else {
parms.add(new Parameterization(parameter,
(String) parameters.get(key)));
}
}
}

// convert the parameters to an Parameterization array and create
// the command
return new ParameterizedCommand(command, (Parameterization[]) parms
.toArray(new Parameterization[parms.size()]));
} catch (NotDefinedException e) {
} catch (ParameterValueConversionException e) {
}
return null;
}
Re: ParameterizedCommand.generateCommand [message #113146 is a reply to message #112314] Sun, 23 November 2008 18:55 Go to previous message
Eclipse UserFriend
Originally posted by: rherrmann.innoopract.com

Mark,

from a glance at the code, I would assume that the command you pass
in does not define a matching parameter.
Did you try the same with RCP? If it works there, feel free to file
a bugzilla.

HTH
Rüdiger


Mark Freiheit wrote:
> Hello group.
>
> I was trying to use the ParameterizedCommand.generateCommand(Command
> command, Map parameters) method to create a ParameterizedCommand using
> my import file command and a Map containing one entry
> (ISources.ACTIVE_WORKBENCH_WINDOW_NAME,
> partRef.getPage().getWorkbenchWindow()).
>
> However, the generateCommand function returns null. I inspected the
> generateCommand code which I will include at the bottom of this post.
> At lines 306 through 313 of ParameterizedCommand.java, I observed that
> this method iterates over the keys of the parameter map, and checks for
> the value in the command itself. If the parameter is not already in the
> command, null is returned.
>
> I would expect this method to use the parameter in the passed in Map and
> apply it to the Command. I think that I am misunderstanding how this
> method should work. Would someone please help clarify the proper use of
> the generateCommand method.
>
> Thanks very much for your help -- Mark
>
> P.S. - I work around this by creating an EvaluationContext, adding my
> variables, creating an ExecutionEvent, then calling
> command.executeWithChecks(executionEvent).
>
> ------------------------------------------------------------ -----------------
>
>
> /**
> * Take a command and a map of parameter IDs to values, and generate
> the
> * appropriate parameterized command.
> * * @param command
> * The command object. Must not be <code>null</code>.
> * @param parameters
> * A map of String parameter ids to objects. May be
> * <code>null</code>.
> * @return the parameterized command, or <code>null</code> if it
> could not
> * be generated
> * @since 3.4
> */
> public static final ParameterizedCommand generateCommand(Command
> command,
> Map parameters) {
> // no parameters
> if (parameters == null || parameters.isEmpty()) {
> return new ParameterizedCommand(command, null);
> }
>
> try {
> ArrayList parms = new ArrayList();
> Iterator i = parameters.keySet().iterator();
>
> // iterate over given parameters
> while (i.hasNext()) {
> String key = (String) i.next();
> IParameter parameter = null;
> // get the parameter from the command
> parameter = command.getParameter(key);
>
> // if the parameter is defined add it to the parameter list
> if (parameter == null) {
> return null;
> }
> ParameterType parameterType =
> command.getParameterType(key);
> if (parameterType == null) {
> parms.add(new Parameterization(parameter,
> (String) parameters.get(key)));
> } else {
> AbstractParameterValueConverter valueConverter =
> parameterType
> .getValueConverter();
> if (valueConverter != null) {
> String val =
> valueConverter.convertToString(parameters
> .get(key));
> parms.add(new Parameterization(parameter, val));
> } else {
> parms.add(new Parameterization(parameter,
> (String) parameters.get(key)));
> }
> }
> }
>
> // convert the parameters to an Parameterization array and
> create
> // the command
> return new ParameterizedCommand(command,
> (Parameterization[]) parms
> .toArray(new Parameterization[parms.size()]));
> } catch (NotDefinedException e) {
> } catch (ParameterValueConversionException e) {
> }
> return null;
> }
>
Previous Topic:BUG in CVS Head: Highlighting in List widget doesn't work
Next Topic:Misplaced drop down menu in a toolbar drop-down item when working with ActionCon
Goto Forum:
  


Current Time: Fri Apr 19 04:58:41 GMT 2024

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

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

Back to the top