@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);
   }
 }
 /** Moves caret to the position of currently active pair. */
 public boolean matchPair() {
   if (currentPair == null) return false;
   int caret = text.getCaretOffset();
   int lno = text.getLineAtOffset(caret);
   PairMatch cp = baseEditor.getPairMatch(lno, caret - text.getOffsetAtLine(lno));
   baseEditor.searchGlobalPair(cp);
   if (cp.end == null) return false;
   if (cp.topPosition) text.setSelection(text.getOffsetAtLine(cp.eline) + cp.end.end);
   else text.setSelection(text.getOffsetAtLine(cp.eline) + cp.end.start);
   return true;
 }
  /**
   * This method is used to set the cell editors text
   *
   * @param toEdit String to be set in the cell editor
   */
  public void setEditText(String toEdit) {

    // Get the cell editor
    CellEditor cellEditor = getCellEditor();

    // IF the cell editor doesn't exist yet...
    if (cellEditor == null) {
      // Do nothing
      return;
    }

    // Get the Text Compartment Edit Part
    IXtextAwareEditPart textEP = (IXtextAwareEditPart) getEditPart();

    // Get the Text control
    StyledText textControl = (StyledText) cellEditor.getControl();

    // Set the Figures text
    textEP.setLabelText(toEdit);

    // See RATLC00522324
    if (cellEditor instanceof TextCellEditorEx) {
      ((TextCellEditorEx) cellEditor).setValueAndProcessEditOccured(toEdit);
    } else {
      cellEditor.setValue(toEdit);
    }

    // Set the controls text and position the caret at the end of the text
    textControl.setSelection(toEdit.length());
  }
  /**
   * 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);
        }
      }
    }
  }
 @Override
 public void resetContents(String newContents) {
   commandLineText.replaceTextRange(
       contentsOffset, commandLineText.getCharCount() - contentsOffset, newContents);
   // Clear selection, set caret position to end of widget.
   commandLineText.setCaret(endCharCaret);
   commandLineText.setSelection(commandLineText.getCharCount());
 }
Example #6
0
  /**
   * Inputs in the view the selected PO whose pretty code is recorded in the Goal class
   *
   * @throws IOException
   */
  public void inputPO() throws IOException {

    // we want to see a context, not the goal
    if (!POMode) {
      return;
    }

    if (ttext > 0) // if we've a title text
    setPartName(IConstants.PO_VIEW_TITLE + " : po " + ttext); // put it in the view
    else setPartName(IConstants.PO_VIEW_TITLE); // else, put the view title only

    // gets the PO pretty text
    String container = "";
    container = Goal.getGoal();

    // if the Goal is empty, we can return
    if (container.equals("")) {
      text.setText(container);
      return;
    }

    // get the style ranges
    Vector<StyleRange> range = Goal.getStyleRanges();
    int w = range.size() - 1;
    // keep the ranges which can be applied in the text area
    while (((StyleRange) range.get(w)).start >= container.length()) {
      w--;
    }

    // put the bar between the goal and the arrow result excerpted from this same goal
    container += "\n_______________________________________________\n\n";
    container += Goal.getResult();
    text.setText(container);

    // apply style ranges to the first part of the goal (before the bar)
    for (int e = 0; e <= w; e++) {
      text.setStyleRange((StyleRange) range.get(e));
    }

    // puts a style range to color the bar in black
    StyleRange srg = new StyleRange();
    srg.start += Goal.getGoal().length();
    srg.length = 50;
    srg.foreground = new Color(null, 0, 0, 0);
    text.setStyleRange(srg);

    // puts a style range to color the end of the goal in blue
    srg = new StyleRange();
    srg.start += Goal.getGoal().length() + 50;
    srg.length = Goal.getResult().length();
    srg.foreground = new Color(null, 0, 0, 255);
    text.setStyleRange(srg);

    // sets the cursor at the end of the code
    text.setSelection(text.getText().length(), text.getText().length());
  }
 /** Makes sure that the prompt characters don't get erased when selected. */
 protected void clipSelection() {
   if (commandLineText.getSelectionCount() > 0) {
     Point sel = commandLineText.getSelection();
     int leftOffset = Math.min(sel.x, sel.y);
     int rightOffset = Math.max(sel.x, sel.y);
     if (leftOffset < contentsOffset) {
       leftOffset = contentsOffset;
     }
     if (rightOffset < contentsOffset) {
       rightOffset = contentsOffset;
     }
     commandLineText.setSelection(new Point(leftOffset, rightOffset));
   }
 }
  /**
   * 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);
    }
  }
 public void setSelection(int start, int end) {
   fStyledText.setSelection(start, end);
 }
 /*
  * (non-Javadoc)
  *
  * @see
  * org.eclipse.jface.fieldassist.IControlContentAdapter2#setSelection(org.eclipse.swt
  * .widgets.Control, org.eclipse.swt.graphics.Point)
  */
 @Override
 public void setSelection(Control control, Point range) {
   ((StyledText) control).setSelection(range);
 }