Package org.eclipse.jface.text.source.projection

Examples of org.eclipse.jface.text.source.projection.ProjectionAnnotationModel


        final IErlElement de = delta.getElement();
        if (de instanceof IErlModule && de != fModule) {
            return;
        }

        final ProjectionAnnotationModel model = (ProjectionAnnotationModel) fEditor
                .getAdapter(ProjectionAnnotationModel.class);
        if (model == null) {
            return;
        }

        final IDocumentProvider provider = fEditor.getDocumentProvider();

        try {
            fCachedModel = model;
            fCachedDocument = provider.getDocument(fEditor.getEditorInput());
            if (fCachedDocument.getNumberOfLines() > PerformanceTuning.get()
                    .getFoldingLimit()) {
                // disable folding for files larger than this
                model.removeAllAnnotations();
                return;
            }

            final Map<ErlangProjectionAnnotation, Position> additions = new HashMap<ErlangProjectionAnnotation, Position>();
            final List<ErlangProjectionAnnotation> deletions = new ArrayList<ErlangProjectionAnnotation>();
            final List<ErlangProjectionAnnotation> updates = new ArrayList<ErlangProjectionAnnotation>();

            // use a linked map to maintain ordering of comments
            final Map<ErlangProjectionAnnotation, Position> updated = new LinkedHashMap<ErlangProjectionAnnotation, Position>();

            computeAdditions(fModule, updated);
            final Map<Object, List<Tuple>> previous = createAnnotationMap(model);

            for (final Entry<ErlangProjectionAnnotation, Position> entry : updated
                    .entrySet()) {
                final ErlangProjectionAnnotation newAnnotation = entry.getKey();
                final IErlElement element = newAnnotation.getElement();
                final Position newPosition = entry.getValue();

                final List<Tuple> annotations = previous.get(element);
                if (annotations == null) {

                    additions.put(newAnnotation, newPosition);

                } else {
                    final Iterator<Tuple> x = annotations.iterator();
                    boolean matched = false;
                    while (x.hasNext()) {
                        final Tuple tuple = x.next();
                        final ErlangProjectionAnnotation existingAnnotation = tuple.annotation;
                        final Position existingPosition = tuple.position;
                        if (newAnnotation.isComment() == existingAnnotation.isComment()) {
                            if (existingPosition != null
                                    && !newPosition.equals(existingPosition)) {
                                existingPosition.setOffset(newPosition.getOffset());
                                existingPosition.setLength(newPosition.getLength());
                                updates.add(existingAnnotation);
                            }
                            matched = true;
                            x.remove();
                            break;
                        }
                    }
                    if (!matched) {
                        additions.put(newAnnotation, newPosition);
                    }

                    if (annotations.isEmpty()) {
                        previous.remove(element);
                    }
                }
            }

            for (final List<Tuple> l : previous.values()) {
                for (final Tuple t : l) {
                    deletions.add(t.annotation);
                }
            }

            match(deletions, additions, updates);

            final Annotation[] removals = new Annotation[deletions.size()];
            deletions.toArray(removals);
            final Annotation[] changes = new Annotation[updates.size()];
            updates.toArray(changes);
            model.modifyAnnotations(removals, additions, changes);
            fFirstTimeInitialCollapse = false;
        } finally {
            fCachedDocument = null;
            fCachedModel = null;
View Full Code Here


    private void modifyFiltered(final Filter filter, final boolean expand) {
        if (!isInstalled()) {
            return;
        }

        final ProjectionAnnotationModel model = (ProjectionAnnotationModel) fEditor
                .getAdapter(ProjectionAnnotationModel.class);
        if (model == null) {
            return;
        }

        final List<ErlangProjectionAnnotation> modified = new ArrayList<ErlangProjectionAnnotation>();
        final Iterator<?> iter = model.getAnnotationIterator();
        while (iter.hasNext()) {
            final Object annotation = iter.next();
            if (annotation instanceof ErlangProjectionAnnotation) {
                final ErlangProjectionAnnotation epa = (ErlangProjectionAnnotation) annotation;

                if (filter.match(epa)) {
                    if (expand) {
                        epa.markExpanded();
                    } else {
                        epa.markCollapsed();
                    }
                    modified.add(epa);
                }

            }
        }

        model.modifyAnnotations(null, null,
                modified.toArray(new Annotation[modified.size()]));
    }
View Full Code Here

        }
        // fFirstType= null;
        // fHasHeaderComment = false;
        try {

            final ProjectionAnnotationModel model = (ProjectionAnnotationModel) fEditor
                    .getAdapter(ProjectionAnnotationModel.class);
            if (model == null) {
                return;
            }
            fCachedModel = model;
View Full Code Here

    try {
      ProjectionViewer viewer = (ProjectionViewer)getSourceViewer();
      if(viewer==null){
        return;
      }
      ProjectionAnnotationModel model = viewer.getProjectionAnnotationModel();
      if(model==null){
        return;
      }
     
      ArrayList list  = new ArrayList();
View Full Code Here

    try {
      ProjectionViewer viewer = (ProjectionViewer)getSourceViewer();
      if(viewer==null){
        return;
      }
      ProjectionAnnotationModel model = viewer.getProjectionAnnotationModel();
      if(model==null){
        return;
      }
     
      ArrayList list = new ArrayList();
View Full Code Here

    try {
      ProjectionViewer viewer = (ProjectionViewer)getSourceViewer();
      if(viewer==null){
        return;
      }
      ProjectionAnnotationModel model = viewer.getProjectionAnnotationModel();
      if(model==null){
        return;
      }
     
      IDocument doc = getDocumentProvider().getDocument(getEditorInput());
View Full Code Here

        IDocument document = viewer.getDocument();

        try
        {
            ProjectionAnnotationModel projectionAnnotationModel = ( ProjectionAnnotationModel ) editor
                .getAdapter( ProjectionAnnotationModel.class );
            if ( projectionAnnotationModel == null )
                return;

            // create folding regions of current LDIF model; mark comments
            // and
            // folded lines as collapsed
            Map positionToAnnotationMap = createFoldingRegions( editor.getLdifModel(), document );

            // compare with current annotation model (--> toAdd, toDelete)
            List annotationsToDeleteList = new ArrayList();
            Map annotationsToAddMap = new HashMap();
            this.computeDifferences( projectionAnnotationModel, positionToAnnotationMap, annotationsToDeleteList,
                annotationsToAddMap );
            Annotation[] annotationsToDelete = ( Annotation[] ) annotationsToDeleteList
                .toArray( new Annotation[annotationsToDeleteList.size()] );

            // update annotation model
            if ( !annotationsToDeleteList.isEmpty() || !annotationsToAddMap.isEmpty() )
            {
                projectionAnnotationModel.modifyAnnotations( annotationsToDelete, annotationsToAddMap,
                    new Annotation[0] );
            }

        }
        catch ( BadLocationException e )
View Full Code Here

        IDocument document = viewer.getDocument();

        try
        {
            ProjectionAnnotationModel projectionAnnotationModel = ( ProjectionAnnotationModel ) editor
                .getAdapter( ProjectionAnnotationModel.class );
            if ( projectionAnnotationModel == null )
                return;

            // create folding regions of current LDIF model; mark comments
            // and
            // folded lines as collapsed
            Map positionToAnnotationMap = createFoldingRegions( editor.getLdifModel(), document );

            // compare with current annotation model (--> toAdd, toDelete)
            List annotationsToDeleteList = new ArrayList();
            Map annotationsToAddMap = new HashMap();
            this.computeDifferences( projectionAnnotationModel, positionToAnnotationMap, annotationsToDeleteList,
                annotationsToAddMap );
            Annotation[] annotationsToDelete = ( Annotation[] ) annotationsToDeleteList
                .toArray( new Annotation[annotationsToDeleteList.size()] );

            // update annotation model
            if ( !annotationsToDeleteList.isEmpty() || !annotationsToAddMap.isEmpty() )
            {
                projectionAnnotationModel.modifyAnnotations( annotationsToDelete, annotationsToAddMap,
                    new Annotation[0] );
            }

        }
        catch ( BadLocationException e )
View Full Code Here

    myLength += 2;
    return new TypedRegion(region.getOffset(), myLength, region.getType());
  }

  private void updateFoldingStructure(ArrayList<Position> positions) {
    ProjectionAnnotationModel annotationModel = ((ProjectionViewer) sourceViewer)
        .getProjectionAnnotationModel();
    Annotation[] deletions = computeDifferences(positions, annotationModel);
    Map<ProjectionAnnotation, Object> additionsMap = new HashMap<ProjectionAnnotation, Object>();
    for (Iterator<Position> i = positions.iterator(); i.hasNext();) {
      Object position = i.next();
      additionsMap.put(new ProjectionAnnotation(), position);
    }
    if ((deletions.length != 0 || additionsMap.size() != 0))
      annotationModel.modifyAnnotations(deletions, additionsMap,
          new Annotation[] {});
  }
View Full Code Here

    this.viewwer=(ProjectionViewer) viewer;
   
    collapseStrings= new FoldingAction(TurtleFoldingMessages.getResourceBundle(), "Projection.CollapseStrings.") { //$NON-NLS-1$
      private final EClass type=XturtlePackage.Literals.STRING_LITERAL;
      public void run() {
        ProjectionAnnotationModel model = viewwer.getProjectionAnnotationModel();
        Iterator<?> iterator = model.getAnnotationIterator();
        List<Annotation> toCollapse=new ArrayList<Annotation>();
        while (iterator.hasNext()){
          Object next = iterator.next();
          if(next instanceof ProjectionAnnotation){
            ProjectionAnnotation pa = (ProjectionAnnotation) next;
            //foldable regions for strings have been marked by using the TextFoldedRegion class
            //there may indeed be better ways...
            Position position = model.getPosition(pa);
            if(position instanceof TypedFoldedRegion && type==((TypedFoldedRegion) position).getType()){
              pa.markCollapsed();
              toCollapse.add(pa);
            }
          }
        }
        model.modifyAnnotations(null, null, toCollapse.toArray(new Annotation[0]));
      }
    };
    collapseStrings.setActionDefinitionId("org.xtext.example.folding.ui.folding.collapseStrings");
    editor.setAction("FoldingCollapseStrings", collapseStrings); //$NON-NLS-1$
View Full Code Here

TOP

Related Classes of org.eclipse.jface.text.source.projection.ProjectionAnnotationModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.