@Override
 public void scrollDown(boolean wholeScreen) {
   int topLine = commandLineText.getTopIndex();
   if (wholeScreen) {
     int bottomLine = commandLineText.getLineIndex(commandLineText.getBounds().y - 1);
     int nLines = bottomLine - topLine;
     commandLineText.setTopIndex(topLine + nLines);
   } else {
     // For some reason, getTopIndex() seems to return the second fully shown line... No +1
     commandLineText.setTopIndex(topLine);
   }
 }
  /**
   * set text
   *
   * @param lines lines
   * @param widgetLineNumbers number text widget
   * @param widgetText text widget
   * @param widgetHorizontalScrollBar horizontal scrollbar widget
   * @param widgetVerticalScrollBar horizontal scrollbar widget
   */
  private void setText(
      String[] lines,
      StyledText widgetLineNumbers,
      StyledText widgetText,
      ScrollBar widgetHorizontalScrollBar,
      ScrollBar widgetVerticalScrollBar) {
    if (!widgetLineNumbers.isDisposed()
        && !widgetText.isDisposed()
        && !widgetVerticalScrollBar.isDisposed()
        && !widgetHorizontalScrollBar.isDisposed()) {
      StringBuilder lineNumbers = new StringBuilder();
      StringBuilder text = new StringBuilder();
      int lineNb = 1;
      int maxWidth = 0;

      // get text
      for (String line : lines) {
        lineNumbers.append(String.format("%d\n", lineNb));
        lineNb++;
        text.append(line);
        text.append('\n');

        maxWidth = Math.max(maxWidth, line.length());
      }

      // set text
      widgetLineNumbers.setText(lineNumbers.toString());
      widgetText.setText(text.toString());
      widgetText.setCaretOffset(0);

      // set scrollbars
      widgetHorizontalScrollBar.setMinimum(0);
      widgetHorizontalScrollBar.setMaximum(maxWidth);
      widgetVerticalScrollBar.setMinimum(0);
      widgetVerticalScrollBar.setMaximum(lineNb - 1);

      // force redraw (Note: for some reason this is necessary to keep texts and scrollbars in sync)
      widgetLineNumbers.redraw();
      widgetText.redraw();
      widgetLineNumbers.update();
      widgetText.update();

      // show top
      widgetLineNumbers.setTopIndex(0);
      widgetLineNumbers.setSelection(0);
      widgetText.setTopIndex(0);
      widgetText.setCaretOffset(0);
      widgetVerticalScrollBar.setSelection(0);
    }
  }
 @Override
 public void setMode(CommandLineMode mode) {
   if (mode == CommandLineMode.DEFAULT) {
     commandLineText.setEditable(true);
     if (registerModeSelection != null) {
       commandLineText.replaceTextRange(registerModeSelection.x, 1, "");
       commandLineText.setSelection(registerModeSelection);
       registerModeSelection = null;
     } else {
       // Reset any selection made in a readonly mode, otherwise we need to check if
       // cut/copy needs to be enabled.
       commandLineText.setSelection(commandLineText.getCaretOffset());
     }
     readOnly = false;
   } else if (mode == CommandLineMode.REGISTER) {
     if (registerModeSelection == null) {
       Point sel = commandLineText.getSelection();
       int leftOffset = Math.min(sel.x, sel.y);
       commandLineText.replaceTextRange(leftOffset, 0, "\"");
       registerModeSelection = sel;
       readOnly = true;
     }
   } else if (mode == CommandLineMode.MESSAGE || mode == CommandLineMode.MESSAGE_CLIPPED) {
     commandLineText.setEditable(false);
     setPosition(0);
     commandLineText.setTopIndex(0);
     readOnly = true;
     pasteItem.setEnabled(false);
     commandLineText.setWordWrap(mode == CommandLineMode.MESSAGE);
   }
 }
  void executeCommand(String cmdLine) {
    clearStatus();

    IOSGiFrameworkConsole console =
        (IOSGiFrameworkConsole)
            getServer().getOriginal().loadAdapter(IOSGiFrameworkConsole.class, null);

    if (console == null) {
      IStatus status =
          EditorUIPlugin.newErrorStatus("Console editor part is not integrated with the runtime.");
      EditorUIPlugin.log(status);
      setStatus(status);
      return;
    }

    try {
      String result = console.executeCommand(cmdLine);
      manifestText.append("osgi> " + cmdLine + "\n");
      manifestText.append(result + "\n");
      forwardAction.setEnabled(history.canForward());
      backAction.setEnabled(history.canBack());
      toolBarManager.update(true);
      manifestText.setTopIndex(manifestText.getLineCount() - 1);
    } catch (CoreException e) {
      EditorUIPlugin.log(e);
      setStatus(
          EditorUIPlugin.newErrorStatus("Failed to execute command. See Error Log for details."));
    }

    commandText.setText("");
  }
  /**
   * search next text
   *
   * @param widgetText text widget
   * @param widgetFind search text widget
   */
  private void findNext(StyledText widgetText, Text widgetFind) {
    if (!widgetText.isDisposed()) {
      String findText = widgetFind.getText().toLowerCase();
      if (!findText.isEmpty()) {
        // get cursor position
        int cursorIndex = widgetText.getCaretOffset();

        // search
        int offset = -1;
        if (cursorIndex >= 0) {
          String text = widgetText.getText();
          offset =
              (cursorIndex + 1 < text.length())
                  ? text.substring(cursorIndex + 1).toLowerCase().indexOf(findText)
                  : -1;
        }
        if (offset >= 0) {
          int index = cursorIndex + 1 + offset;

          widgetText.setCaretOffset(index);
          widgetText.setSelection(index);
          widgetText.redraw();

          int topIndex = widgetText.getTopIndex();

          widgetLineNumbers.setTopIndex(topIndex);
          widgetVerticalScrollBar.setSelection(topIndex);
        } else {
          Widgets.flash(widgetFind);
        }
      }
    }
  }
 private void scrollToCaret() {
   int caretOffset = currentText.getCaretOffset();
   int lineIndex = currentText.getLineAtOffset(caretOffset);
   int lineHeight = currentText.getLineHeight();
   int linesVisible = currentText.getSize().y / lineHeight;
   int lineMiddle = linesVisible / 2;
   int lineTop = lineIndex - lineMiddle;
   if (lineTop < 0) lineTop = 0;
   currentText.setTopIndex(lineTop);
 }
Example #7
0
  private void scrollToEnd() {

    terminalText.setTopIndex(terminalText.getLineCount() - 1);
  }