示例#1
0
 /** Saves the code folding state into the given memento. */
 public void saveCodeFolding(org.eclipse.ui.IMemento memento) {
   java.util.Iterator<?> annotationIt = projectionAnnotationModel.getAnnotationIterator();
   while (annotationIt.hasNext()) {
     org.eclipse.jface.text.source.projection.ProjectionAnnotation annotation =
         (org.eclipse.jface.text.source.projection.ProjectionAnnotation) annotationIt.next();
     org.eclipse.ui.IMemento annotationMemento = memento.createChild(ANNOTATION);
     org.eclipse.jface.text.Position position = projectionAnnotationModel.getPosition(annotation);
     annotationMemento.putBoolean(IS_COLLAPSED, annotation.isCollapsed());
     annotationMemento.putInteger(OFFSET, position.offset);
     annotationMemento.putInteger(LENGTH, position.length);
   }
 }
示例#2
0
  /**
   * Updates the annotations registered with this editor.
   *
   * @param positions
   */
  public void updateFoldingStructure(ArrayList<Position> newPositions) {
    Map<ProjectionAnnotation, Position> saveAllAnnotations =
        new HashMap<ProjectionAnnotation, Position>();
    saveAllAnnotations.putAll(curAnnotations);

    try {
      String setDefaultCollapsedProperty =
          EclipseUtil.getPreferenceStore().getString(PluginConstants.T24_ALWAYS_COLLAPSE_REGION);
      boolean setDefaultCollapsed = Boolean.parseBoolean(setDefaultCollapsedProperty);
      // this will hold the new annotations along
      // with their corresponding positions
      Map<ProjectionAnnotation, Position> newAnnotations =
          new HashMap<ProjectionAnnotation, Position>();
      for (int i = 0; i < newPositions.size(); i++) {
        ProjectionAnnotation an = annotationAlreadyExists((Position) newPositions.get(i));
        ProjectionAnnotation annotation;
        if (an == null) {
          // The annotation doesn't exist yet, so create it brand new.
          annotation = new ProjectionAnnotation();
          annotation.setRangeIndication(false);
          annotation.setText("Annotation " + i);
          if (setDefaultCollapsed) {
            annotation.markCollapsed();
          } else {
            annotation.markExpanded();
          }
          Position pos = newPositions.get(i);
          newAnnotations.put(annotation, pos);
          saveAllAnnotations.put(annotation, pos);
        } else {
          if (setDefaultCollapsed) {
            an.markCollapsed();
          } else {
            an.markExpanded();
          }
          newAnnotations.put(an, newPositions.get(i));
          saveAllAnnotations.put(an, newPositions.get(i));
        }
      }
      Set<ProjectionAnnotation> keys = curAnnotations.keySet();
      Iterator<ProjectionAnnotation> keyIt = keys.iterator();
      Annotation[] annotations = new Annotation[curAnnotations.size()];
      int annotationCount = 0;
      while (keyIt.hasNext()) {
        ProjectionAnnotation an = (ProjectionAnnotation) keyIt.next();
        annotations[annotationCount++] = an;
        saveAllAnnotations.remove(an);
      }
      if (annotationModel != null) {
        annotationModel.modifyAnnotations(annotations, newAnnotations, null);
      } else {
        createAnnotationModel();
      }
      curAnnotations = saveAllAnnotations;
    } catch (Exception e) {
      e.printStackTrace();
    }
  }