下面列出了怎么用org.eclipse.ui.commands.ICommandService的API类实例代码及写法,或者点击链接到github查看源代码。
@Inject
public void initializeAtStartup(final IWorkbench workbench, final ICommandService commandService) {
/*
* Check the UI state of the IHandler/Command which indicates if the user
* enabled automatic PlusCal conversion.
*/
final Command command = commandService.getCommand("toolbox.command.module.translate.automatially");
final State state = command.getState(RegistryToggleState.STATE_ID);
if (!((Boolean) state.getValue()).booleanValue()) {
return;
}
// This IHander is stateful even across Toolbox restarts. In other words, if the
// user enables automatic PlusCal translation, it will remain enabled even after
// a Toolbox restart. This means we have to register this EventHandler at the
// IEventBroker during Toolbox startup.
// It is vital that we use the Workbench's IEventBroker instance. If e.g. we
// would use an IEventBroker from higher up the IEclipseContext hierarchy, the
// broker would be disposed when a new spec gets opened while the IHandler's state
// remains enabled.
workbench.getService(IEventBroker.class).unsubscribe(this);
Assert.isTrue(workbench.getService(IEventBroker.class).subscribe(TLAEditor.PRE_SAVE_EVENT, this));
}
/**
* If {@link Preferences#P_TEXT_EDIT_LOCAL} is set, the
* <code> ch.elexis.core.ui.command.startEditLocalDocument </code> command is called with the
* provided {@link Brief}, and the provided {@link IViewPart} is hidden.
*
* @param view
* @param brief
* @return returns true if edit local is started and view is hidden
*/
public static boolean startEditLocalDocument(IViewPart view, Brief brief){
if (CoreHub.localCfg.get(Preferences.P_TEXT_EDIT_LOCAL, false) && brief != null) {
// open for editing
ICommandService commandService =
(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
Command command =
commandService.getCommand("ch.elexis.core.ui.command.startEditLocalDocument"); //$NON-NLS-1$
PlatformUI.getWorkbench().getService(IEclipseContext.class)
.set(command.getId().concat(".selection"), new StructuredSelection(brief));
try {
command.executeWithChecks(
new ExecutionEvent(command, Collections.EMPTY_MAP, view, null));
} catch (ExecutionException | NotDefinedException | NotEnabledException
| NotHandledException e) {
MessageDialog.openError(view.getSite().getShell(), Messages.TextView_errortitle,
Messages.TextView_errorlocaleditmessage);
}
view.getSite().getPage().hideView(view);
return true;
}
return false;
}
@Override
public boolean performOk() {
if (super.performOk()) {
final String value = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore()
.getString(BonitaCoolBarPreferenceConstant.COOLBAR_DEFAULT_SIZE);
try {
final ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
if (value.equals(BonitaCoolBarPreferenceConstant.SMALL)) {
service.getCommand("org.bonitasoft.studio.application.smallCoolbar").executeWithChecks(new ExecutionEvent());
} else if (value.equals(BonitaCoolBarPreferenceConstant.NORMAL)) {
service.getCommand("org.bonitasoft.studio.application.normalCoolbar").executeWithChecks(new ExecutionEvent());
}
} catch (final Exception e) {
BonitaStudioLog.error(e);
}
}
return false;
}
private static void executeCommand(IWorkbench workbench, String commandName, Map<String, Object> params) {
if (workbench == null) {
workbench = PlatformUI.getWorkbench();
}
// get command
ICommandService commandService = (ICommandService)workbench.getService(ICommandService.class);
Command command = commandService != null ? commandService.getCommand(commandName) : null;
// get handler service
//IBindingService bindingService = (IBindingService)workbench.getService(IBindingService.class);
//TriggerSequence[] triggerSequenceArray = bindingService.getActiveBindingsFor("de.anbos.eclipse.easyshell.plugin.commands.open");
IHandlerService handlerService = (IHandlerService)workbench.getService(IHandlerService.class);
if (command != null && handlerService != null) {
ParameterizedCommand paramCommand = ParameterizedCommand.generateCommand(command, params);
try {
handlerService.executeCommand(paramCommand, null);
} catch (Exception e) {
Activator.logError(Activator.getResourceString("easyshell.message.error.handlerservice.execution"), paramCommand.toString(), e, true);
}
}
}
@Override
public void run(IAction action) {
System.err.println("In run(IACtion)");
if (serviceLocator == null) {
serviceLocator = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
}
// Create an ExecutionEvent using Eclipse machinery.
ICommandService srv = (ICommandService) serviceLocator.getService(ICommandService.class);
IHandlerService hsrv = (IHandlerService) serviceLocator.getService(IHandlerService.class);
ExecutionEvent event = hsrv.createExecutionEvent(srv.getCommand(ActionCommands.COMPARE_WITH_ROUTE_ACTION), null);
// Fill it my current active selection.
if (event.getApplicationContext() instanceof IEvaluationContext) {
((IEvaluationContext) event.getApplicationContext()).addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, mySelection);
}
try {
handler.execute(event);
} catch (ExecutionException e) {
Activator.handleError(e.getMessage(), e, true);
}
}
@Override
public void run(IAction action) {
if (serviceLocator == null) {
serviceLocator = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
}
// Create an ExecutionEvent using Eclipse machinery.
ICommandService srv = (ICommandService) serviceLocator.getService(ICommandService.class);
IHandlerService hsrv = (IHandlerService) serviceLocator.getService(IHandlerService.class);
ExecutionEvent event = hsrv.createExecutionEvent(srv.getCommand(ActionCommands.PERSIST_TO_ROUTE_MODEL_ACTION), null);
// Fill it my current active selection.
if (event.getApplicationContext() instanceof IEvaluationContext) {
((IEvaluationContext) event.getApplicationContext()).addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, mySelection);
}
try {
handler.execute(event);
} catch (ExecutionException e) {
Activator.handleError(e.getMessage(), e, true);
}
}
@Override
public void run(IAction action) {
System.err.println("In run(IACtion)");
if (serviceLocator == null) {
serviceLocator = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
}
// Create an ExecutionEvent using Eclipse machinery.
ICommandService srv = (ICommandService) serviceLocator.getService(ICommandService.class);
IHandlerService hsrv = (IHandlerService) serviceLocator.getService(IHandlerService.class);
ExecutionEvent event = hsrv.createExecutionEvent(srv.getCommand(ActionCommands.COMPARE_WITH_ROUTE_ACTION), null);
// Fill it my current active selection.
if (event.getApplicationContext() instanceof IEvaluationContext) {
((IEvaluationContext) event.getApplicationContext()).addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, mySelection);
}
try {
handler.execute(event);
} catch (ExecutionException e) {
Activator.handleError(e.getMessage(), e, true);
}
}
@Override
public void run(IAction action) {
if (serviceLocator == null) {
serviceLocator = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
}
// Create an ExecutionEvent using Eclipse machinery.
ICommandService srv = (ICommandService) serviceLocator.getService(ICommandService.class);
IHandlerService hsrv = (IHandlerService) serviceLocator.getService(IHandlerService.class);
ExecutionEvent event = hsrv.createExecutionEvent(srv.getCommand(ActionCommands.PERSIST_TO_ROUTE_MODEL_ACTION), null);
// Fill it my current active selection.
if (event.getApplicationContext() instanceof IEvaluationContext) {
((IEvaluationContext) event.getApplicationContext()).addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, mySelection);
}
try {
handler.execute(event);
} catch (ExecutionException e) {
Activator.handleError(e.getMessage(), e, true);
}
}
/**
* setup
*/
private void setup()
{
try
{
// listen for execution events
Object service = PlatformUI.getWorkbench().getService(ICommandService.class);
if (service instanceof ICommandService)
{
ICommandService commandService = (ICommandService) service;
commandService.addExecutionListener(this);
}
}
catch (IllegalStateException e)
{
// workbench not yet started, or may be running headless (like in core unit tests)
}
// listen for element visibility events
BundleManager manager = BundleManager.getInstance();
manager.addElementVisibilityListener(this);
}
/**
* tearDown
*/
private void tearDown()
{
// stop listening for visibility events
BundleManager manager = BundleManager.getInstance();
manager.removeElementVisibilityListener(this);
// stop listening for execution events
Object service = PlatformUI.getWorkbench().getService(ICommandService.class);
if (service instanceof ICommandService)
{
ICommandService commandService = (ICommandService) service;
commandService.removeExecutionListener(this);
}
// drop all references
this._commandToIdsMap.clear();
this._idToCommandsMap.clear();
this._nonlimitedCommands.clear();
}
public static void setCoolBarVisibility(boolean visible)
{
IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow();
if (activeWorkbenchWindow instanceof WorkbenchWindow)
{
WorkbenchWindow workbenchWindow = (WorkbenchWindow) activeWorkbenchWindow;
workbenchWindow.setCoolBarVisible(visible);
workbenchWindow.setPerspectiveBarVisible(visible);
// Try to force a refresh of the text on the action
IWorkbenchPart activePart = getActivePart();
if (activePart != null)
{
ICommandService cmdService = (ICommandService) activePart.getSite().getService(ICommandService.class);
cmdService.refreshElements("org.eclipse.ui.ToggleCoolbarAction", null); //$NON-NLS-1$
}
}
}
public static void executeWithParams(PersistentObject parameter){
try {
// get the command
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
ICommandService cmdService = (ICommandService) window.getService(ICommandService.class);
Command cmd = cmdService.getCommand(EditEigenartikelUi.COMMANDID);
// create the parameter
HashMap<String, Object> param = new HashMap<String, Object>();
param.put(EditEigenartikelUi.PARAMETERID, parameter);
// build the parameterized command
ParameterizedCommand pc = ParameterizedCommand.generateCommand(cmd, param);
// execute the command
IHandlerService handlerService =
(IHandlerService) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getService(IHandlerService.class);
handlerService.executeCommand(pc, null);
} catch (Exception ex) {
throw new RuntimeException(EditEigenleistungUi.COMMANDID, ex);
}
}
public void registerCommands(CompilationUnitEditor editor) {
IWorkbench workbench= PlatformUI.getWorkbench();
ICommandService commandService= (ICommandService) workbench.getAdapter(ICommandService.class);
IHandlerService handlerService= (IHandlerService) workbench.getAdapter(IHandlerService.class);
if (commandService == null || handlerService == null) {
return;
}
if (fCorrectionHandlerActivations != null) {
JavaPlugin.logErrorMessage("correction handler activations not released"); //$NON-NLS-1$
}
fCorrectionHandlerActivations= new ArrayList<IHandlerActivation>();
Collection<String> definedCommandIds= commandService.getDefinedCommandIds();
for (Iterator<String> iter= definedCommandIds.iterator(); iter.hasNext();) {
String id= iter.next();
if (id.startsWith(ICommandAccess.COMMAND_ID_PREFIX)) {
boolean isAssist= id.endsWith(ICommandAccess.ASSIST_SUFFIX);
CorrectionCommandHandler handler= new CorrectionCommandHandler(editor, id, isAssist);
IHandlerActivation activation= handlerService.activateHandler(id, handler, new LegacyHandlerSubmissionExpression(null, null, editor.getSite()));
fCorrectionHandlerActivations.add(activation);
}
}
}
public boolean test(final Object receiver, final String property,
final Object[] args, final Object expectedValue) {
if (receiver instanceof IServiceLocator && args.length == 1
&& args[0] instanceof String) {
final IServiceLocator locator = (IServiceLocator) receiver;
if (TOGGLE_PROPERTY_NAME.equals(property)) {
final String commandId = args[0].toString();
final ICommandService commandService = (ICommandService) locator
.getService(ICommandService.class);
final Command command = commandService.getCommand(commandId);
final State state = command
.getState(RegistryToggleState.STATE_ID);
if (state != null) {
return state.getValue().equals(expectedValue);
}
}
}
return false;
}
public static Object ExecuteWithParams(IViewSite origin, Tree<?> tSelection){
IHandlerService handlerService = (IHandlerService) origin.getService(IHandlerService.class);
ICommandService cmdService = (ICommandService) origin.getService(ICommandService.class);
try {
Command command = cmdService.getCommand(ID);
Parameterization px =
new Parameterization(command.getParameter("ch.elexis.RechnungErstellen.parameter"), //$NON-NLS-1$
new TreeToStringConverter().convertToString(tSelection));
ParameterizedCommand parmCommand =
new ParameterizedCommand(command, new Parameterization[] {
px
});
return handlerService.executeCommand(parmCommand, null);
} catch (Exception ex) {
throw new RuntimeException("add.command not found"); //$NON-NLS-1$
}
}
/**
* Verify statically that this macro will execute properly
* - Ensure the current Eclipse defines the commands used by the macro
*
* @param editor
* @param kbdMacro
* @return true if validates, else false
*/
private String checkMacro(ITextEditor editor, KbdMacro kbdMacro) {
String result = null;
ICommandService ics = (editor != null ) ? (ICommandService) editor.getSite().getService(ICommandService.class) :
(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
@SuppressWarnings("unchecked") // Eclipse documents the type
Collection<String> cmdIds = (Collection<String>)ics.getDefinedCommandIds();
for (KbdEvent e : kbdMacro.getKbdMacro()) {
String cmdId;
if ((cmdId = e.getCmd()) != null) {
if (!cmdIds.contains(cmdId)) {
result = cmdId;
break;
}
}
}
return result;
}
/**
* Define the Command to be used when executing the named kbd macro
*
* @param editor
* @param id - the full command id
* @param name - the short name
* @param category - the category to use in the definition
* @return the Command
*/
Command defineKbdMacro(ITextEditor editor, String id, String name, String category) {
Command command = null;
if (id != null) {
// Now create the executable command
ICommandService ics = (editor != null ) ? (ICommandService) editor.getSite().getService(ICommandService.class) :
(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
command = ics.getCommand(id);
IParameter[] parameters = null;
try {
// kludge: Eclipse has no way to dynamically define a parameter, so grab it from a known command
IParameter p = ics.getCommand(PARAMETER_CMD).getParameter(PARAMETER);
parameters = new IParameter[] { p };
} catch (Exception e) {
}
command.define(name, String.format(KBD_DESCRIPTION,name), ics.getCategory(category), parameters);
command.setHandler(new KbdMacroNameExecuteHandler(name));
}
return command;
}
/**
* Execute the UI command found by the commandId, using the {@link ICommandService}.
*
* @param commandId
* @param selection
* @return
*/
public static Object executeCommand(String commandId, IFinding selection){
try {
ICommandService commandService =
(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
Command cmd = commandService.getCommand(commandId);
if(selection != null) {
PlatformUI.getWorkbench().getService(IEclipseContext.class)
.set(commandId.concat(".selection"), new StructuredSelection(selection));
}
ExecutionEvent ee = new ExecutionEvent(cmd, Collections.EMPTY_MAP, null, null);
return cmd.executeWithChecks(ee);
} catch (Exception e) {
LoggerFactory.getLogger(FindingsUiUtil.class)
.error("cannot execute command with id: " + commandId, e);
}
return null;
}
/**
* Start the definition of a keyboard macro
*
* @param editor
* @param append - if true, append to the current definition
*/
public void startKbdMacro(ITextEditor editor, boolean append) {
if (!isExecuting()) {
setEditor(editor);
isdefining = true;
ics = (ICommandService) editor.getSite().getService(ICommandService.class);
// listen for command executions
ics.addExecutionListener(this);
addDocumentListener(editor);
if (!append || kbdMacro == null) {
kbdMacro = new KbdMacro();
}
setViewer(findSourceViewer(editor));
if (viewer instanceof ITextViewerExtension) {
((ITextViewerExtension) viewer).prependVerifyKeyListener(whileDefining);
} else {
viewer = null;
}
// add a listener for ^G
Beeper.addBeepListener(KbdMacroBeeper.beeper);
currentCommand = null;
}
}
/**
* Get the current set of defined categories corresponding to the included category names
*
* @param ics
* @return the filtered set of categories
*
* @throws NotDefinedException
*/
private HashSet<Category> getCategories(ICommandService ics) throws NotDefinedException
{
if (catHash.isEmpty() && catIncludes != null) {
Category[] cats = ics.getDefinedCategories();
for (int i = 0; i < cats.length; i++) {
for (int j = 0; j < catIncludes.length; j++) {
if (catIncludes[j].equals(cats[i].getId())) {
catHash.add(cats[i]);
break;
}
}
}
}
return catHash;
}
/**
* @throws ExecutionException
*/
public void editAndSave() throws Exception {
processEditor = getTheOnlyOneEditor();
processEditor.getEditingDomain().getCommandStack().execute(
new SetCommand(processEditor.getEditingDomain(),
task,
ProcessPackage.Literals.ELEMENT__NAME,
TESTNAME));
final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
final ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
final Command saveCommand = commandService.getCommand("org.eclipse.ui.file.save");
final ExecutionEvent executionEvent = new ExecutionEvent(saveCommand, Collections.EMPTY_MAP, null,
handlerService.getClass());
saveCommand.executeWithChecks(executionEvent);
}
public static void executeWithParams(PersistentObject parameter){
try {
// get the command
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
ICommandService cmdService = (ICommandService) window.getService(ICommandService.class);
Command cmd = cmdService.getCommand(EditEigenleistungUi.COMMANDID);
// create the parameter
HashMap<String, Object> param = new HashMap<String, Object>();
param.put(EditEigenleistungUi.PARAMETERID, parameter);
// build the parameterized command
ParameterizedCommand pc = ParameterizedCommand.generateCommand(cmd, param);
// execute the command
IHandlerService handlerService =
(IHandlerService) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getService(IHandlerService.class);
handlerService.executeCommand(pc, null);
} catch (Exception ex) {
throw new RuntimeException(EditEigenleistungUi.COMMANDID, ex);
}
}
@Test
public void testFormatEnabled() throws IOException, PartInitException, CoreException {
File file = File.createTempFile("test", ".json");
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IDE.openEditorOnFileStore(activePage, EFS.getStore(file.toURI()));
ICommandService service = activePage.getWorkbenchWindow().getService(ICommandService.class);
Command formatCommand = service.getCommand("org.eclipse.lsp4e.format");
assertNotNull("Format command not found", formatCommand);
assertTrue("Format command not defined", formatCommand.isDefined());
assertTrue("Format command not enabled", formatCommand.isEnabled());
assertTrue("Format command not handled", formatCommand.isHandled());
}
@Override
public void earlyStartup() {
// Client code can still clone the repository on demand. (Mind plug-in UI tests.)
// TODO this should be a job that we can wait for
new Thread(() -> {
// trigger index loading which will potentially announce a recovery build on all projects to be
// necessary
// XXX it is crucial to call isEmpty before isRecoveryBuildRequired is checked, since isEmpty
// will set internal state that is afterwards queried by isRecoveryBuildRequired
boolean indexIsEmpty = builderState.isEmpty();
// check if this recovery build was really required
if (descriptionPersister.isRecoveryBuildRequired() || indexIsEmpty) {
// TODO return something like a Future that allows to say
// descriptionPersister.scheduleRecoveryBuildOnContributions().andThen(buildManager...)
descriptionPersister.scheduleRecoveryBuildOnContributions();
Map<String, String> args = Maps.newHashMap();
IBuildFlag.RECOVERY_BUILD.addToMap(args);
builderStateDiscarder.forgetLastBuildState(Arrays.asList(workspace.getRoot().getProjects()), args);
}
}).start();
// Add listener to monitor Cut and Copy commands
ICommandService commandService = PlatformUI.getWorkbench().getAdapter(ICommandService.class);
if (commandService != null) {
commandService.addExecutionListener(new CheckNodeModulesSyncOnRefresh());
}
}
protected IStatus openConfigureDialog() throws ExecutionException {
ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
Command cmd = service.getCommand("org.bonitasoft.studio.configuration.configure");
Map<String, Object> parameters = new HashMap<String, Object>();
String configuration = ConfigurationPlugin.getDefault().getPreferenceStore().getString(ConfigurationPreferenceConstants.DEFAULT_CONFIGURATION);
parameters.put("configuration", configuration);
parameters.put("process", process);
return (IStatus) new ConfigureHandler().execute(new ExecutionEvent(cmd, parameters, null, null));
}
/**
* Unregisters a command manager with the command service of the workbench.
* @param cm the command manager
*/
public static void unregister(CommandExecutionManager cm) {
ICommandService cs = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class);
if (cs != null) {
cs.removeExecutionListener(cm);
}
}
public void setViewerSortOrder(ViewerSortOrder vso){
medicationTableComposite.getTableViewer().setComparator(vso.vc);
medicationHistoryTableComposite.getTableViewer().setComparator(vso.vc);
ICommandService service =
(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
Command command = service.getCommand(ApplyCustomSortingHandler.CMD_ID);
command.getState(ApplyCustomSortingHandler.STATE_ID)
.setValue(vso.equals(ViewerSortOrder.MANUAL));
}
protected void startHdView ()
{
try
{
final ICommandService commandService = (ICommandService)PlatformUI.getWorkbench ().getService ( ICommandService.class );
final IHandlerService handlerService = (IHandlerService)PlatformUI.getWorkbench ().getService ( IHandlerService.class );
final Command command = commandService.getCommand ( "org.eclipse.scada.ui.chart.view.commands.OpenParametersChartView" ); //$NON-NLS-1$
final Parameterization[] parameterizations = new Parameterization[4];
parameterizations[0] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.connectionId" ), this.connectionId ); //$NON-NLS-1$
parameterizations[1] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.itemId" ), this.itemId ); //$NON-NLS-1$
if ( this.queryString == null || this.queryString.isEmpty () )
{
parameterizations[2] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.queryTimespec" ), "2400000:600000" ); //$NON-NLS-1$ //$NON-NLS-2$
}
else
{
parameterizations[2] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.queryTimespec" ), this.queryString ); //$NON-NLS-1$
}
parameterizations[3] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.itemType" ), "hd" ); //$NON-NLS-1$ //$NON-NLS-2$
final ParameterizedCommand parameterCommand = new ParameterizedCommand ( command, parameterizations );
handlerService.executeCommand ( parameterCommand, null );
}
catch ( final Exception e )
{
logger.debug ( "Failed to open view", e );
StatusManager.getManager ().handle ( new Status ( IStatus.ERROR, Activator.PLUGIN_ID, Messages.TrendControlImage_TrendError, e ), StatusManager.BLOCK );
}
}
/**
* Execute an Eclipse command
*
* @param commandId
* the command to execute
* @param eventData
* the parameter event data (depends on the command)
*/
public void executeCommand ( final String commandId, final Map<String, String> eventData )
{
try
{
final ICommandService commandService = (ICommandService)PlatformUI.getWorkbench ().getService ( ICommandService.class );
final IHandlerService handlerService = (IHandlerService)PlatformUI.getWorkbench ().getService ( IHandlerService.class );
final Command command = commandService.getCommand ( commandId );
final Parameterization[] parameterizations = new Parameterization[eventData.size ()];
int i = 0;
for ( final Map.Entry<String, String> entry : eventData.entrySet () )
{
parameterizations[i] = new Parameterization ( command.getParameter ( entry.getKey () ), entry.getValue () );
i++;
}
final ParameterizedCommand parameterCommand = new ParameterizedCommand ( command, parameterizations );
handlerService.executeCommand ( parameterCommand, null );
}
catch ( final Exception e )
{
logger.warn ( "Failed to execute command", e );
StatusManager.getManager ().handle ( StatusHelper.convertStatus ( Activator.PLUGIN_ID, e ), StatusManager.BLOCK );
}
}
public KeyboardBindingsTask(KeyBindingsModel model, IResourceTaskReference taskRef) {
this(
MechanicLog.getDefault(),
PlatformUI.getWorkbench(),
(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class),
(IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class),
model,
String.format("%[email protected]%s", KeyboardBindingsTask.class.getName(), taskRef.getPath()));
}