コード例 #1
0
  /*
   * Adds a control at the given position
   */
  private ContainedEditorManager addControl(int offset, int length) {
    // create the control propoerties
    ContainedEditorProperties props;
    try {
      // get the contents by reading from the editor at the given position
      ASTNode editorExpression = ContainedEditorProperties.toASTNode(doc.get(offset, length));
      props = EditorManagerFactory.createProperties(editorExpression);
    } catch (BadLocationException e) {
      // something about the contents was bad, create an empty editor instead
      EmbeddedCALPlugin.logError(
          "Error trying to create ContainedEditorProperties: offset: "
              + offset
              + " length: "
              + length,
          e);
      props = new CALExpressionEditorProperties();
    }

    ContainedEditorManager contained = EditorManagerFactory.createManager(props);

    if (contained.editorKind() == CALModuleEditorManager.EDITOR_KIND) {
      replaceModuleEditor((CALModuleEditorManager) contained);
    }

    contained.createControl(styledText, containingEditor);
    contained.initializeEditorContents(containingEditor);

    // determine the location of the contained editor
    Position projected = modelToProjected(new Position(offset, 0));
    Point location = styledText.getLocationAtOffset(projected.offset);
    location.x += ContainingEditor.MARGIN;
    location.y += ContainingEditor.MARGIN;
    contained.setLocation(location);

    return contained;
  }