コード例 #1
0
  /**
   * Creates and adds a single control at the given position
   *
   * @param offset
   * @param length
   * @return pair of style ranges that covers this embedded editor
   */
  public StyleRange[] createAndAddControl(int offset, int length) {
    StyleRange[] styles = null;
    Position pos = new Position(offset, length);
    if (!editorPositionMap.containsValue(pos)) {
      ContainedEditorManager newContainedEditor = addControl(offset, length);
      newContainedEditor.addListener(this);
      styles = createStyleRange(newContainedEditor, pos);
      newContainedEditor.registerActions(containingEditor);
      editorPositionMap.put(newContainedEditor, pos);
      ppManager.managePosition(pos);

      // add the annotation in the gutter
      EmbeddedAnnotation annotation = new EmbeddedAnnotation(newContainedEditor);
      if (newContainedEditor.editorKind() == CALExpressionEditorManager.EDITOR_KIND) {
        annotation.setType("org.openquark.cal.eclipse.embedded.expressionAnnotation");
      } else {
        annotation.setType("org.openquark.cal.eclipse.embedded.moduleAnnotation");
      }
      annotation.setText(newContainedEditor.getCalContents());

      // must create a new position otherwise the document object is tracking the same position
      // in two partitions
      annotationModel.addAnnotation(annotation, new Position(offset, length));
      //            annotationModel.collapse(annotation);
      editorAnnotationMap.put(newContainedEditor, annotation);
    } else {
      for (final ContainedEditorManager c : editorPositionMap.keySet()) {
        if (editorPositionMap.get(c).equals(pos)) {
          styles = createStyleRange(c, pos);
          break;
        }
      }
    }
    return styles;
  }