How to access the map returned by IParameterValues::getParameterValues()?

Posted by Hua on Stack Overflow See other posts from Stack Overflow or by Hua
Published on 2012-09-26T03:36:11Z Indexed on 2012/09/26 3:37 UTC
Read the original article Hit count: 193

Filed under:
|

I declared a command and a commandParameter for this command. I specified the "values" of this commandParameter as a class implemented by myself. The implementation of this class is below,

public class ParameterValues implements IParameterValues {

    @Override
    public Map<String, Double> getParameterValues() {
        // TODO Auto-generated method stub
        Map<String, Double> values = new HashMap<String, Double>(2);
        values.put("testParam", 1.1239);
        values.put("AnotherTest", 4.1239);
        return values;      
    }

}

The implementation of the handler of this command is blow,

public class testHandler extends AbstractHandler implements IHandler {
    private static String PARAMETER_ID = "my.parameter1";

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {

        String value = event.getParameter(PARAMETER_ID);    
        MessageDialog.openInformation(HandlerUtil.getActiveShell(event),
                "Test", "Parameter ID: " + PARAMETER_ID + "\nValue: " + value);

        return null;
    }

}

Now, I contribute the command to a menu,

 <menuContribution
            locationURI="menu:org.eclipse.ui.main.menu">
         <menu
               id="my.edit"
               label="Edit">
            <command
                  commandId="myCommand.test"
                  label="Test1">
               <parameter
                     name="my.parameter1"
                     value="testParam">
               </parameter>
            </command>

Since I specified a "values" class for the commandParater, I expect when the menu is clicked, this code line "String value = event.getParameter(PARAMETER_ID);" in the handler class returns 1.1239 instead of "testParam". But, I still see that code line returns "testParam".

What's the problem? How could I access the map returned by getParameterValues()?

By the way, following menu declaration still works even I don't define "ppp" in the map.

 <menuContribution
            locationURI="menu:org.eclipse.ui.main.menu">
         <menu
               id="my.edit"
               label="Edit">
            <command
                  commandId="myCommand.test"
                  label="Test1">
               <parameter
                     name="my.parameter1"
                     value="ppp">
               </parameter>
            </command>

Thanks!

© Stack Overflow or respective owner

Related posts about eclipse-plugin

Related posts about eclipse-rcp