@Override public void addAction(final IAction action) { Check.notNull(action, "action"); //$NON-NLS-1$ final String commandId = action.getActionDefinitionId(); if (commandId == null) { throw new IllegalArgumentException("action does not have an action definition ID set"); //$NON-NLS-1$ } final TriggerSequence[] bindings = bindingService.getActiveBindingsFor(commandId); if (bindings.length > 0) { final IHandler handler = new ActionHandler(action); /* * Call this deprecated overload for 3.1 support */ final IHandlerActivation activation = handlerService.activateHandler(commandId, handler, expression, sourcePriorities); handlerActivations.add(activation); } }
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); } } }
private void activateTerminateHandler(final IProgressMonitor monitor, final WorkspaceJob job) { final IHandlerService handlerService = (IHandlerService) window .getService(IHandlerService.class); window.getShell().getDisplay().syncExec(new Runnable() { @Override public void run() { final IHandlerActivation activation = handlerService.activateHandler(TERMINATE_ID, new TerminateHandler(monitor)); job.addJobChangeListener(new JobChangeAdapter() { @Override public void done(IJobChangeEvent event) { window.getShell().getDisplay().syncExec(new Runnable() { @Override public void run() { handlerService.deactivateHandler(activation); } }); } }); } }); }
@Override public void dispose() { for (final Iterator it = handlerActivations.iterator(); it.hasNext();) { final IHandlerActivation activation = (IHandlerActivation) it.next(); handlerService.deactivateHandler(activation); activation.getHandler().dispose(); } handlerActivations.clear(); }
@Override public final void dispose() { doDispose(); for (IHandlerActivation handlerActivation : handlerActivations) { getHandlerService_2().deactivateHandler(handlerActivation); } super.dispose(); }
protected void activateHandler(String string, AbstractHandler handler) { IHandlerActivation handlerActivation = getHandlerService_2().activateHandler(string, handler); handlerActivations.add(handlerActivation); }