コード例 #1
0
  @Override
  public void launch(final IEditorPart editor, final String mode) {
    assert mode.equals("run"); // $NON-NLS-1$

    final IWorkbenchPart workbenchPart = UIAccess.getActiveWorkbenchPart(false);
    final IWorkbenchPartSite site = workbenchPart.getSite();
    if (site != null) {
      final IHandlerService handlerService =
          (IHandlerService) site.getService(IHandlerService.class);
      final ICommandService commandService =
          (ICommandService) site.getService(ICommandService.class);

      final Map<String, String> parameters = new HashMap<String, String>();
      parameters.put(RCodeLaunching.FILE_COMMAND_ID_PARAMTER_ID, fFileCommandId);
      final Command command =
          commandService.getCommand(
              !fGotoConsole
                  ? RCodeLaunching.RUN_FILEVIACOMMAND_COMMAND_ID
                  : RCodeLaunching.RUN_FILEVIACOMMAND_GOTOCONSOLE_COMMAND_ID);
      final ExecutionEvent executionEvent =
          new ExecutionEvent(command, parameters, null, handlerService.getCurrentState());
      if (!editor.equals(HandlerUtil.getActivePart(executionEvent))) {
        LaunchShortcutUtil.handleUnsupportedExecution(executionEvent);
        return;
      }
      try {
        command.executeWithChecks(executionEvent);
      } catch (final ExecutionException e) {
        LaunchShortcutUtil.handleRLaunchException(
            e, RLaunchingMessages.RScriptLaunch_error_message, executionEvent);
      } catch (final NotDefinedException e) {
        LaunchShortcutUtil.handleUnsupportedExecution(executionEvent);
      } catch (final NotEnabledException e) {
        LaunchShortcutUtil.handleUnsupportedExecution(executionEvent);
      } catch (final NotHandledException e) {
        LaunchShortcutUtil.handleUnsupportedExecution(executionEvent);
      }
    }
  }