コード例 #1
0
ファイル: RConsolePage.java プロジェクト: donkang/statet
 public void run(final IToolRunnableControllerAdapter tools, final IProgressMonitor monitor)
     throws InterruptedException, CoreException {
   final AtomicInteger width = new AtomicInteger(-1);
   UIAccess.getDisplay()
       .syncExec(
           new Runnable() {
             public void run() {
               final TextConsoleViewer outputViewer = getOutputViewer();
               if (UIAccess.isOkToUse(outputViewer)) {
                 final GC gc = new GC(Display.getCurrent());
                 gc.setFont(outputViewer.getTextWidget().getFont());
                 final FontMetrics fontMetrics = gc.getFontMetrics();
                 final int charWidth = fontMetrics.getAverageCharWidth();
                 final int clientWidth = outputViewer.getTextWidget().getClientArea().width;
                 width.set(clientWidth / charWidth);
                 gc.dispose();
               }
             }
           });
   int setWidth = width.get();
   if (setWidth >= 0) {
     if (setWidth < 10) {
       setWidth = 10;
     }
     tools.submitToConsole(
         "options(width = " + setWidth + ")", monitor); // $NON-NLS-1$ //$NON-NLS-2$
   }
 }
コード例 #2
0
ファイル: ExecServlet.java プロジェクト: wtcooper/statet
 protected void openExtern(final IFileStore fileStore) {
   final IWorkbenchPage page = UIAccess.getActiveWorkbenchPage(true);
   try {
     IDE.openEditorOnFileStore(page, fileStore);
   } catch (final PartInitException e) {
     //			final String fileName = FileUtil.toString(fileStore);
     //			Program.launch(fileName);
   }
 }
コード例 #3
0
  @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;
  }
コード例 #4
0
ファイル: OutputViewer.java プロジェクト: akbertram/statet
 @Override
 public void revealEndOfDocument() {
   final Display display = UIAccess.getDisplay();
   display.asyncExec(
       new Runnable() {
         public void run() {
           final StyledText textWidget = getTextWidget();
           if (!UIAccess.isOkToUse(textWidget)) {
             return;
           }
           final AbstractDocument document = (AbstractDocument) getDocument();
           final long timestamp = document.getModificationStamp();
           final int lineCount = textWidget.getLineCount();
           final int lineToShow =
               ((lineCount > 1
                       && textWidget.getCharCount() == textWidget.getOffsetAtLine(lineCount - 1))
                   ? (lineCount - 1)
                   : (lineCount));
           final int visiblePixel = textWidget.getClientArea().height;
           final int linePixel = textWidget.getLineHeight();
           final int topPixel = (linePixel * (lineToShow - 1)) - visiblePixel + 2;
           if (topPixel + linePixel > 0) {
             if (topPixel < 0) {
               textWidget.setTopPixel(topPixel + linePixel);
             } else {
               final int[] move =
                   new int[] {
                     topPixel,
                     topPixel + linePixel - 2,
                     topPixel + linePixel - 1,
                     topPixel + linePixel
                   };
               textWidget.setTopPixel(move[0]);
               final int[] state = new int[] {1};
               display.timerExec(
                   75,
                   new Runnable() {
                     public void run() {
                       int i = state[0];
                       if (!UIAccess.isOkToUse(textWidget)
                           || timestamp
                               != ((IDocumentExtension4) getDocument()).getModificationStamp()
                           || move[i - 1] != textWidget.getTopPixel()) {
                         return;
                       }
                       textWidget.setTopPixel(move[i++]);
                       if (i < move.length) {
                         state[0] = i;
                         display.timerExec(25, this);
                       }
                     }
                   });
             }
           }
         }
       });
 }
コード例 #5
0
  @Override
  public void run() {
    final ToolProcess tool = getTool();
    if (tool == null) {
      return;
    }

    final WizardDialog dialog =
        new WizardDialog(UIAccess.getActiveWorkbenchShell(true), new SaveHistoryWizard(tool));
    dialog.open();
  }
コード例 #6
0
ファイル: RConsolePage.java プロジェクト: donkang/statet
 @Override
 protected void handleSettingsChanged(
     final Set<String> groupIds, final Map<String, Object> options) {
   super.handleSettingsChanged(groupIds, options);
   if (groupIds.contains(RCodeStyleSettings.INDENT_GROUP_ID)
       && UIAccess.isOkToUse(getOutputViewer())) {
     final RCodeStyleSettings codeStyle = (getConsole()).getRCodeStyle();
     if (codeStyle.isDirty()) {
       getOutputViewer().setTabWidth(codeStyle.getTabSize());
     }
   }
 }
コード例 #7
0
 @Override
 public Object execute(final ExecutionEvent event) throws ExecutionException {
   ToolProcess process = fProcess;
   if (process == null) {
     final IWorkbenchPage page = UIAccess.getActiveWorkbenchPage(false);
     process = NicoUI.getToolRegistry().getActiveToolSession(page).getProcess();
   }
   if (!NicoUITools.isToolReady(RTool.TYPE, RTool.R_DATA_FEATURESET_ID, process)) {
     return null;
   }
   process.getQueue().add(new REnvIndexAutoUpdater.UpdateRunnable(fCompletely));
   return null;
 }
コード例 #8
0
    @Override
    public void widgetSelected(final SelectionEvent event) {
      final TexCommand command = (TexCommand) event.widget.getData();

      final IEditorPart editor = UIAccess.getActiveWorkbenchPage(true).getActiveEditor();
      if (editor instanceof ILtxEditor) {
        final ILtxEditor texEditor = (ILtxEditor) editor;
        if (!texEditor.isEditable(true)) {
          return;
        }
        final SourceViewer viewer = ((ILtxEditor) editor).getViewer();
        Point selection = viewer.getSelectedRange();
        if (selection == null || selection.x < 0) {
          return;
        }
        try {
          final String contentType =
              TextUtils.getContentType(
                  viewer.getDocument(),
                  texEditor.getDocumentContentInfo(),
                  selection.x,
                  selection.y == 0);

          final LtxAssistInvocationContext context =
              new LtxAssistInvocationContext(
                  texEditor, selection.x, contentType, true, new NullProgressMonitor());
          final LtxCommandCompletionProposal proposal =
              new LtxCommandCompletionProposal(context, context.getInvocationOffset(), command);
          proposal.apply(viewer, (char) 0, 1, context.getInvocationOffset());
          selection = proposal.getSelection(viewer.getDocument());
          if (selection != null) {
            viewer.setSelectedRange(selection.x, selection.y);
            viewer.revealRange(selection.x, selection.y);
          } else {
            viewer.revealRange(context.getInvocationOffset(), 0);
          }
        } catch (final Exception e) {
          StatusManager.getManager()
              .handle(
                  new Status(
                      IStatus.ERROR,
                      TexUI.PLUGIN_ID,
                      0,
                      "An error occurred when inserting LaTeX symbol.",
                      e));
        }
      }
    }
コード例 #9
0
 public EclipseRGraphicFactory() {
   fDefaultDisplay = UIAccess.getDisplay();
   fFontManager = new FontManager(fDefaultDisplay);
   fColorManager = new ColorManager(fDefaultDisplay);
   fDefaultDisplay.asyncExec(
       new Runnable() {
         public void run() {
           fDefaultDisplay.disposeExec(
               new Runnable() {
                 public void run() {
                   fFontManager.dispose();
                   fColorManager.dispose();
                 }
               });
         }
       });
 }
コード例 #10
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);
      }
    }
  }
コード例 #11
0
ファイル: SelectFileHandler.java プロジェクト: donkang/statet
 public IStatus handle(
     final String id,
     final IToolRunnableControllerAdapter tools,
     final Map<String, Object> data,
     final IProgressMonitor monitor) {
   final String message;
   {
     String s =
         ToolEventHandlerUtil.getCheckedData(data, LOGIN_MESSAGE_DATA_KEY, String.class, false);
     if (s == null) {
       final IProgressInfo progressInfo = tools.getController().getProgressInfo();
       s = NLS.bind("Select file (in {0}):", progressInfo.getLabel());
     }
     message = s;
   }
   final Boolean newFile =
       ToolEventHandlerUtil.getCheckedData(
           data, "newResource", Boolean.class, true); // $NON-NLS-1$
   final ToolProcess tool = tools.getController().getProcess();
   final AtomicReference<IFileStore> file = new AtomicReference<IFileStore>();
   final Runnable runnable =
       new Runnable() {
         public void run() {
           final SelectFileDialog dialog =
               new SelectFileDialog(
                   UIAccess.getActiveWorkbenchShell(true), tool, message, newFile.booleanValue());
           dialog.setBlockOnOpen(true);
           if (dialog.open() == Dialog.OK) {
             file.set(dialog.getResource());
           }
         }
       };
   UIAccess.getDisplay().syncExec(runnable);
   if (file.get() == null) {
     return Status.CANCEL_STATUS;
   }
   data.put("filename", file.get().toURI().toString()); // $NON-NLS-1$
   return Status.OK_STATUS;
 }
コード例 #12
0
ファイル: ExecServlet.java プロジェクト: wtcooper/statet
  protected void execOpenFile(final HttpServletRequest req, final HttpServletResponse resp)
      throws IOException {
    final String path = req.getParameter("path"); // $NON-NLS-1$

    if (path == null) {
      resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
      return;
    }
    try {
      final IFileStore fileStore = EFS.getLocalFileSystem().getStore(new URI(path));
      UIAccess.getDisplay()
          .asyncExec(
              new Runnable() {
                @Override
                public void run() {
                  openExtern(fileStore);
                }
              });
    } catch (final URISyntaxException e) {
      resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    }
  }