@Override
  public Object execute(final ExecutionEvent event) throws ExecutionException {
    final ISelection selection = WorkbenchUIUtil.getCurrentSelection(event.getApplicationContext());
    final List<IProject> projects;
    if (selection instanceof IStructuredSelection) {
      final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
      projects = new ArrayList<>(structuredSelection.size());
      for (final Iterator<?> iter = structuredSelection.iterator(); iter.hasNext(); ) {
        final Object obj = iter.next();
        if (obj instanceof IAdaptable) {
          final IProject project = (IProject) ((IAdaptable) obj).getAdapter(IProject.class);
          if (project != null) {
            projects.add(project);
          }
        }
      }
    } else {
      return null;
    }

    final WorkspaceModifyOperation op =
        new WorkspaceModifyOperation() {

          @Override
          protected void execute(final IProgressMonitor monitor)
              throws CoreException, InvocationTargetException, InterruptedException {
            final SubMonitor m =
                SubMonitor.convert(monitor, TexUIMessages.TexProject_ConvertTask_label, 100);
            try {
              final SubMonitor mProjects = m.newChild(100).setWorkRemaining(projects.size());
              for (final IProject project : projects) {
                if (m.isCanceled()) {
                  throw new InterruptedException();
                }
                TexProjects.setupTexProject(project, mProjects.newChild(1));
              }
            } finally {
              m.done();
            }
          }
        };
    try {
      UIAccess.getActiveWorkbenchWindow(true).run(true, true, op);
    } catch (final InvocationTargetException e) {
      StatusManager.getManager()
          .handle(
              new Status(
                  IStatus.ERROR,
                  TexUI.PLUGIN_ID,
                  TexUIMessages.TexProject_ConvertTask_error_message,
                  e.getTargetException()));
    } catch (final InterruptedException e) {
      // cancelled
    }

    return null;
  }
  @Override
  public Object execute(final ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPart workbenchPart = HandlerUtil.getActivePart(event);
    final ISelection selection = WorkbenchUIUtil.getCurrentSelection(event.getApplicationContext());

    try {
      if (workbenchPart instanceof ITextEditor && selection instanceof ITextSelection) {
        final ITextEditor editor = (ITextEditor) workbenchPart;
        final IDocumentProvider documentProvider = editor.getDocumentProvider();
        if (documentProvider == null) {
          return null;
        }
        final IDocument document = documentProvider.getDocument(editor.getEditorInput());
        if (document == null) {
          return null;
        }
        final List<String> lines = LaunchShortcutUtil.getSelectedCodeLines(event);
        if (lines != null) {
          RCodeLaunching.runRCodeDirect(lines, false, null);
          final int newOffset =
              getNextLineOffset(document, ((ITextSelection) selection).getEndLine());
          if (newOffset >= 0) {
            editor.selectAndReveal(newOffset, 0);
          }
        }
        return null;
      }
    } catch (final CoreException e) {
      LaunchShortcutUtil.handleRLaunchException(
          e, RLaunchingMessages.RSelectionLaunch_error_message, event);
      return null;
    }

    LaunchShortcutUtil.handleUnsupportedExecution(event);
    return null;
  }