How to pass parameters to comman in eclipse rcp application through code?

I am using the below code to run a command added via org.eclipse.ui.commands:

IServiceLocator serviceLocator = PlatformUI.getWorkbench();
ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class);

try  {
        Command command = commandService.getCommand("my_command_id");
        command.executeWithChecks(new ExecutionEvent());

    } catch (ExecutionException ex1) {

    } catch (NotDefinedException ex2){

    } catch(NotEnabledException ex3){

    } catch(NotHandledException ex4){

    }


This works fine, but I want to pass a parameter to this command. I have mechanism to accept parameters, but how to pass it through code?


Figured it! Did the following to do the same:

IServiceLocator serviceLocator = PlatformUI.getWorkbench();
ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class);

try  { 
        Command command = commandService.getCommand("my_command_id");
        Map<String, String> map = new HashMap<String, String>();
        map.put("param_name", "param_value");
        /*more parameter's can be added to Map and passed*/
        command.executeWithChecks(new ExecutionEvent(null, map, null, null));

    } catch (ExecutionException e1) {

    } catch (NotDefinedException e2){

    } catch(NotEnabledException e3){

    } catch(NotHandledException e4){

    }
链接地址: http://www.djcxy.com/p/18686.html

上一篇: 在自定义视图中显示结果

下一篇: 如何通过代码将参数传递给eclipse rcp应用程序中的comman?