下面列出了怎么用org.eclipse.ui.handlers.IHandlerActivation的API类实例代码及写法,或者点击链接到github查看源代码。
private void dispose() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
//During Eclipse shutdown the active workbench window is null
return;
}
Object serviceObject = window.getService(IHandlerService.class);
IHandlerService service = (IHandlerService) serviceObject;
for (IHandlerActivation activation : fHandlerActivations) {
service.deactivateHandler(activation);
}
fHandlerActivations.clear();
fGoToMessageForKeyBinding = null;
fFindForKeyBinding = null;
fMoveUpForKeyBinding = null;
fMoveDownForKeyBinding = null;
fMoveLeftForKeyBinding = null;
fMoveRightForKeyBinding = null;
fShowNodeStartForKeyBinding = null;
fShowNodeEndForKeyBinding = null;
}
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);
}
}
}
@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);
}