1 package org
.argeo
.eclipse
.ui
.utils
;
3 import java
.util
.ArrayList
;
5 import org
.argeo
.ArgeoException
;
6 import org
.argeo
.eclipse
.ui
.ArgeoUiPlugin
;
7 import org
.eclipse
.core
.commands
.Command
;
8 import org
.eclipse
.core
.commands
.IParameter
;
9 import org
.eclipse
.core
.commands
.Parameterization
;
10 import org
.eclipse
.core
.commands
.ParameterizedCommand
;
11 import org
.eclipse
.ui
.IWorkbench
;
12 import org
.eclipse
.ui
.IWorkbenchWindow
;
13 import org
.eclipse
.ui
.commands
.ICommandService
;
14 import org
.eclipse
.ui
.handlers
.IHandlerService
;
17 * Centralizes useful and generic methods concerning eclipse commands.
20 public class CommandUtils
{
23 * Factorizes command call that is quite verbose and always the same
25 * NOTE that none of the parameter can be null
27 public static void CallCommandWithOneParameter(String commandId
,
28 String paramId
, String paramValue
) {
30 IWorkbench iw
= ArgeoUiPlugin
.getDefault().getWorkbench();
32 IHandlerService handlerService
= (IHandlerService
) iw
33 .getService(IHandlerService
.class);
35 // get the command from plugin.xml
36 IWorkbenchWindow window
= iw
.getActiveWorkbenchWindow();
37 ICommandService cmdService
= (ICommandService
) window
38 .getService(ICommandService
.class);
40 Command cmd
= cmdService
.getCommand(commandId
);
42 ArrayList
<Parameterization
> parameters
= new ArrayList
<Parameterization
>();
45 IParameter iparam
= cmd
.getParameter(paramId
);
47 Parameterization params
= new Parameterization(iparam
, paramValue
);
48 parameters
.add(params
);
50 // build the parameterized command
51 ParameterizedCommand pc
= new ParameterizedCommand(cmd
,
52 parameters
.toArray(new Parameterization
[parameters
.size()]));
54 // execute the command
55 handlerService
= (IHandlerService
) window
56 .getService(IHandlerService
.class);
57 handlerService
.executeCommand(pc
, null);
58 } catch (Exception e
) {
59 throw new ArgeoException("Error while calling command of id :"