public void focusOnLines(ILocation range) {
   if (range instanceof ILineLocation) {
     ILineLocation lineLocation = (ILineLocation) range;
     // editors count lines from 0, Crucible counts from 1
     final int startLine = lineLocation.getRangeMin() - 1;
     final int endLine = lineLocation.getRangeMax() - 1;
     if (sourceViewer != null) {
       IDocument document = sourceViewer.getDocument();
       if (document != null) {
         try {
           int offset = document.getLineOffset(startLine);
           int length = document.getLineOffset(endLine) - offset;
           StyledText widget = sourceViewer.getTextWidget();
           try {
             widget.setRedraw(false);
             // sourceViewer.revealRange(offset, length);
             // sourceViewer.setSelectedRange(offset, 0);
             sourceViewer.setSelection(new TextSelection(offset, length), true);
           } finally {
             widget.setRedraw(true);
           }
         } catch (BadLocationException e) {
           StatusHandler.log(
               new Status(IStatus.ERROR, ReviewsUiPlugin.PLUGIN_ID, e.getMessage(), e));
         }
       }
     }
   }
 }
  private void gotoLine(int line) {

    TextViewer viewer = getTextViewer();

    IDocument document = viewer.getDocument();

    try {
      int start = document.getLineOffset(line);

      StyledText widget = viewer.getTextWidget();
      widget.setRedraw(false);
      {
        viewer.revealRange(start, 0);
        viewer.setSelectedRange(start, 0);
        widget.setFocus();
      }
      widget.setRedraw(true);
    } catch (BadLocationException e) {
      // ignore
    }
  }
    /*
     * @see org.eclipse.ui.texteditor.AbstractTextEditor#selectAndReveal(int, int, int, int)
     */
    private void selectAndReveal(
        int selectionStart, int selectionLength, int revealStart, int revealLength) {

      ISelection selection = getSelectionProvider().getSelection();
      if (selection instanceof ITextSelection) {
        ITextSelection textSelection = (ITextSelection) selection;
        if (textSelection.getOffset() != 0 || textSelection.getLength() != 0)
          markInNavigationHistory();
      }

      StyledText widget = MergeSourceViewer.this.getSourceViewer().getTextWidget();
      widget.setRedraw(false);
      {
        adjustHighlightRange(revealStart, revealLength);
        MergeSourceViewer.this.getSourceViewer().revealRange(revealStart, revealLength);

        MergeSourceViewer.this.getSourceViewer().setSelectedRange(selectionStart, selectionLength);

        markInNavigationHistory();
      }
      widget.setRedraw(true);
    }
Exemple #4
0
  public void _setWhatsNew() {

    if (sWhatsNew.indexOf("<html") >= 0 || sWhatsNew.indexOf("<HTML") >= 0) {
      BrowserWrapper browser = Utils.createSafeBrowser(cWhatsNew, SWT.NONE);
      if (browser != null) {
        browser.setText(sWhatsNew);
      } else {
        try {
          File tempFile = File.createTempFile("AZU", ".html");
          tempFile.deleteOnExit();
          FileUtil.writeBytesAsFile(tempFile.getAbsolutePath(), sWhatsNew.getBytes("utf8"));
          Utils.launch(tempFile.getAbsolutePath());
          shell.dispose();
          return;
        } catch (IOException e) {
        }
      }
    } else {

      StyledText helpPanel = new StyledText(cWhatsNew, SWT.VERTICAL | SWT.HORIZONTAL);

      helpPanel.setEditable(false);
      try {
        helpPanel.setRedraw(false);
        helpPanel.setWordWrap(false);
        helpPanel.setFont(monospace);

        black = ColorCache.getColor(display, 0, 0, 0);
        white = ColorCache.getColor(display, 255, 255, 255);
        light = ColorCache.getColor(display, 200, 200, 200);
        grey = ColorCache.getColor(display, 50, 50, 50);
        green = ColorCache.getColor(display, 30, 80, 30);
        blue = ColorCache.getColor(display, 20, 20, 80);
        int style;
        boolean setStyle;

        helpPanel.setForeground(grey);

        String[] lines = sWhatsNew.split("\\r?\\n");
        for (int i = 0; i < lines.length; i++) {
          String line = lines[i];

          setStyle = false;
          fg = grey;
          bg = white;
          style = SWT.NORMAL;

          char styleChar;
          String text;

          if (line.length() < 2) {
            styleChar = ' ';
            text = " " + lineSeparator;
          } else {
            styleChar = line.charAt(0);
            text = line.substring(1) + lineSeparator;
          }

          switch (styleChar) {
            case '*':
              text = "  * " + text;
              fg = green;
              setStyle = true;
              break;
            case '+':
              text = "     " + text;
              fg = black;
              bg = light;
              style = SWT.BOLD;
              setStyle = true;
              break;
            case '!':
              style = SWT.BOLD;
              setStyle = true;
              break;
            case '@':
              fg = blue;
              setStyle = true;
              break;
            case '$':
              bg = blue;
              fg = white;
              style = SWT.BOLD;
              setStyle = true;
              break;
            case ' ':
              text = "  " + text;
              break;

            default:
              text = styleChar + text;
          }

          helpPanel.append(text);

          if (setStyle) {
            int lineCount = helpPanel.getLineCount() - 1;
            int charCount = helpPanel.getCharCount();
            //          System.out.println("Got Linecount " + lineCount + ", Charcount " +
            // charCount);

            int lineOfs = helpPanel.getOffsetAtLine(lineCount - 1);
            int lineLen = charCount - lineOfs;
            //          System.out.println("Setting Style : " + lineOfs + ", " + lineLen);
            helpPanel.setStyleRange(new StyleRange(lineOfs, lineLen, fg, bg, style));
            helpPanel.setLineBackground(lineCount - 1, 1, bg);
          }
        }

        helpPanel.setRedraw(true);
      } catch (Exception e) {
        System.out.println("Unable to load help contents because:" + e);
        // e.printStackTrace();
      }
    }

    if (labelLoading != null && !labelLoading.isDisposed()) {
      labelLoading.dispose();
    }
    shell.layout(true, true);
  }