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();

    Collection definedCommandIds = commandService.getDefinedCommandIds();
    for (Iterator iter = definedCommandIds.iterator(); iter.hasNext(); ) {
      String id = (String) iter.next();
      if (id.startsWith(COMMAND_PREFIX)) {
        boolean isAssist = id.endsWith(ASSIST_SUFFIX);
        CorrectionCommandHandler handler = new CorrectionCommandHandler(editor, id, isAssist);
        IHandlerActivation activation =
            handlerService.activateHandler(
                id, handler, new LegacyHandlerSubmissionExpression(null, null, editor.getSite()));
        fCorrectionHandlerActivations.add(activation);
      }
    }
  }
Пример #2
0
  public int open() {
    IWorkbench workbench = window.getWorkbench();
    bindingService = (IBindingService) workbench.getAdapter(IBindingService.class);
    contextService = (IContextService) workbench.getAdapter(IContextService.class);
    if (bindingService != null) {
      registerWorkbenchCommands();
    }
    int ret = super.open();
    if (ret == OK) {
      if (contextService != null) {
        contextActivation = contextService.activateContext(CONTEXT_ID);
      }
      if (bindingService != null) {
        registerDialogCommands();
      }
    }
    activateJob();

    return ret;
  }