コード例 #1
0
  public void editorDeleted(ContainedEditorManager editor, ContainedEditorProperties props) {

    IEditorStatusLine statusLine =
        (IEditorStatusLine) containingEditor.getAdapter(IEditorStatusLine.class);
    statusLine.setMessage(false, "Editor Deleted", null);

    Position p = removeControl(editor, true);
    if (p != null) {
      try {
        containingEditor.getSelectionProvider().setSelection(new TextSelection(doc, p.offset, 0));
        doc.replace(p.offset, p.length, "");
      } catch (BadLocationException e) {
        // it's OK to ignore this
        // shouldn't happen anyway
      }
    }
    if (editor == moduleEditor) {
      // look for new module editor, or else it becomes null.
      replaceModuleEditor(null);
      for (final ContainedEditorManager contained : editorPositionMap.keySet()) {
        if (contained.editorKind() == CALModuleEditorManager.EDITOR_KIND) {
          replaceModuleEditor((CALModuleEditorManager) contained);
          break;
        }
      }
    }

    // remove this control's annotation
    EmbeddedAnnotation annotation = editorAnnotationMap.remove(editor);
    annotationModel.removeAnnotation(annotation);

    // remove listener
    editor.removeListener(this);
  }
コード例 #2
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;
  }
コード例 #3
0
 public void saveAllEditors() {
   String moduleName = getModuleName();
   if (moduleName != null) {
     for (final ContainedEditorManager editor : editorPositionMap.keySet()) {
       // check to see if the module name is up to date
       if (editor.editorKind() == CALExpressionEditorManager.EDITOR_KIND) {
         CALExpressionEditorProperties exprProps =
             (CALExpressionEditorProperties) editor.getPropertiess();
         if (!exprProps.getModuleName().equals(moduleName)) {
           // module name has changed, must re-serialize this expression editor.
           exprProps.setDirty(true);
         }
       }
       editor.doSave();
     }
   }
 }
コード例 #4
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;
  }