protected void updateFoldingRegions(boolean allowCollapse, ProjectionAnnotationModel model, Collection<FoldedPosition> foldedPositions, Annotation[] deletions) { Map<ProjectionAnnotation, Position> additionsMap = Maps.newHashMap(); for (FoldedPosition foldedPosition: foldedPositions) { addProjectionAnnotation(allowCollapse, foldedPosition, additionsMap); } if (deletions.length != 0 || additionsMap.size() != 0) { model.modifyAnnotations(deletions, additionsMap, new Annotation[] {}); } }
@SuppressWarnings("unchecked") protected Annotation[] mergeFoldingRegions(Collection<FoldedPosition> foldedPositions, ProjectionAnnotationModel projectionAnnotationModel) { List<Annotation> deletions = new ArrayList<Annotation>(); for (Iterator<Annotation> iterator = projectionAnnotationModel.getAnnotationIterator(); iterator.hasNext();) { Annotation annotation = iterator.next(); if (annotation instanceof ProjectionAnnotation) { Position position = projectionAnnotationModel.getPosition(annotation); if (!foldedPositions.remove(position)) { deletions.add(annotation); } } } return deletions.toArray(new Annotation[deletions.size()]); }
@Override protected IAnnotationModel createVisualAnnotationModel(IAnnotationModel annotationModel) { IAnnotationModel model= super.createVisualAnnotationModel(annotationModel); fProjectionAnnotationModel= new ProjectionAnnotationModel(); return model; }
/** * Collapses all annotations that overlap with the given range and are collapsed. * * @param offset the range offset * @param length the range length * @return <code>true</code> if any annotation has been collapse, <code>false</code> * otherwise * @since 3.2 */ public boolean collapseAll(int offset, int length) { boolean collapsing= false; Iterator<Annotation> iterator= getAnnotationIterator(); while (iterator.hasNext()) { ProjectionAnnotation annotation= (ProjectionAnnotation) iterator.next(); if (!annotation.isCollapsed()) { Position position= getPosition(annotation); if (position != null && position.overlapsWith(offset, length) /* || is a delete at the boundary */ ) { annotation.markCollapsed(); modifyAnnotation(annotation, false); collapsing= true; } } } if (collapsing) fireModelChanged(); return collapsing; }
@Override public void setRangeIndication(int offset, int length, boolean moveCursor) { IRegion rangeIndication= getRangeIndication(); if (moveCursor && fProjectionAnnotationModel != null && (rangeIndication == null || offset != rangeIndication.getOffset() || length != rangeIndication.getLength())) { List<ProjectionAnnotation> expand= new ArrayList<>(2); // expand the immediate affected collapsed regions Iterator<Annotation> iterator= fProjectionAnnotationModel.getAnnotationIterator(); while (iterator.hasNext()) { ProjectionAnnotation annotation= (ProjectionAnnotation)iterator.next(); if (annotation.isCollapsed() && willAutoExpand(fProjectionAnnotationModel.getPosition(annotation), offset, length)) expand.add(annotation); } if (!expand.isEmpty()) { Iterator<ProjectionAnnotation> e= expand.iterator(); while (e.hasNext()) fProjectionAnnotationModel.expand(e.next()); } } super.setRangeIndication(offset, length, moveCursor); }
HeadingProjectionAnnotation annotation = projectionAnnotationById.get(newAnnotation.getHeadingId()); if (annotation != null) { Position position = projectionAnnotationModel.getPosition(annotation); if (newPosition.equals(position)) { newPositionIt.remove(); Iterator<Annotation> annotationIt = projectionAnnotationModel.getAnnotationIterator(); while (annotationIt.hasNext()) { Annotation annotation = annotationIt.next(); projectionAnnotationModel.modifyAnnotations( toDelete.isEmpty() ? null : toDelete.toArray(new Annotation[toDelete.size()]), annotationToPosition, null); } else { projectionAnnotationModel.modifyAnnotations(null, annotationToPosition, null); for (HeadingProjectionAnnotation annotation : annotationToPosition.keySet()) { newProjectionAnnotationById.put(annotation.getHeadingId(), annotation);
Iterator<Annotation> iter= model.getAnnotationIterator(); while (iter.hasNext()) { Object annotation= iter.next(); model.modifyAnnotations(null, null, modified.toArray(new Annotation[modified.size()]));
while (deletionIterator.hasNext()) { JavaProjectionAnnotation deleted= deletionIterator.next(); Position deletedPosition= ctx.getModel().getPosition(deleted); if (deletedPosition == null) continue;
private void collapse() { if (isProjectionMode()) { Position found= null; Annotation bestMatch= null; Point selection= getSelectedRange(); for (Iterator<Annotation> e= fProjectionAnnotationModel.getAnnotationIterator(); e.hasNext();) { ProjectionAnnotation annotation= (ProjectionAnnotation) e.next(); if (!annotation.isCollapsed()) { Position position= fProjectionAnnotationModel.getPosition(annotation); // take the first most fine grained match if (position != null && touches(selection, position)) if (found == null || found.includes(position.offset) && found.includes(position.offset + position.length)) { found= position; bestMatch= annotation; } } } if (bestMatch != null) { fProjectionAnnotationModel.collapse(bestMatch); revealRange(selection.x, selection.y); } } }
/** * Disables the projection mode. */ public final void disableProjection() { if (isProjectionMode()) { removeProjectionAnnotationModel(getVisualAnnotationModel()); fProjectionAnnotationModel.removeAllAnnotations(); fFindReplaceDocumentAdapter= null; fireProjectionDisabled(); } }
/** * Collapses all annotations that overlap with the given range and are collapsed. * * @param offset the range offset * @param length the range length * @return <code>true</code> if any annotation has been collapse, <code>false</code> * otherwise * @since 3.2 */ public boolean collapseAll(int offset, int length) { boolean collapsing= false; Iterator<Annotation> iterator= getAnnotationIterator(); while (iterator.hasNext()) { ProjectionAnnotation annotation= (ProjectionAnnotation) iterator.next(); if (!annotation.isCollapsed()) { Position position= getPosition(annotation); if (position != null && position.overlapsWith(offset, length) /* || is a delete at the boundary */ ) { annotation.markCollapsed(); modifyAnnotation(annotation, false); collapsing= true; } } } if (collapsing) fireModelChanged(); return collapsing; }
@Override public void setRangeIndication(int offset, int length, boolean moveCursor) { IRegion rangeIndication= getRangeIndication(); if (moveCursor && fProjectionAnnotationModel != null && (rangeIndication == null || offset != rangeIndication.getOffset() || length != rangeIndication.getLength())) { List<ProjectionAnnotation> expand= new ArrayList<>(2); // expand the immediate affected collapsed regions Iterator<Annotation> iterator= fProjectionAnnotationModel.getAnnotationIterator(); while (iterator.hasNext()) { ProjectionAnnotation annotation= (ProjectionAnnotation)iterator.next(); if (annotation.isCollapsed() && willAutoExpand(fProjectionAnnotationModel.getPosition(annotation), offset, length)) expand.add(annotation); } if (!expand.isEmpty()) { Iterator<ProjectionAnnotation> e= expand.iterator(); while (e.hasNext()) fProjectionAnnotationModel.expand(e.next()); } } super.setRangeIndication(offset, length, moveCursor); }
ProjectionAnnotationModel annotationModel = viewer.getProjectionAnnotationModel(); List<Annotation> modifications = null; Iterator<Annotation> iterator = annotationModel.getAnnotationIterator(); while (iterator.hasNext()) { Annotation annotation = iterator.next(); Position position = annotationModel.getPosition(projectionAnnotation); iterator = annotationModel.getAnnotationIterator(); while (iterator.hasNext()) { Annotation annotation = iterator.next(); HeadingProjectionAnnotation projectionAnnotation = (HeadingProjectionAnnotation) annotation; if (!projectionAnnotation.isCollapsed()) { Position position = annotationModel.getPosition(projectionAnnotation); if (position != null) { offset = position.offset; annotationModel.modifyAnnotations(null, null, modifications.toArray(new Annotation[modifications.size()]));
Iterator<Annotation> iter= model.getAnnotationIterator(); while (iter.hasNext()) { Object annotation= iter.next(); model.modifyAnnotations(null, null, modified.toArray(new Annotation[modified.size()]));
JavaProjectionAnnotation annotation= (JavaProjectionAnnotation) it.next(); if (tuple.annotation.isComment() == annotation.isComment()) { Position position= positionMap == null ? ctx.getModel().getPosition(annotation) : (Position) positionMap.get(annotation); if (position == null) continue;
private void collapse() { if (isProjectionMode()) { Position found= null; Annotation bestMatch= null; Point selection= getSelectedRange(); for (Iterator<Annotation> e= fProjectionAnnotationModel.getAnnotationIterator(); e.hasNext();) { ProjectionAnnotation annotation= (ProjectionAnnotation) e.next(); if (!annotation.isCollapsed()) { Position position= fProjectionAnnotationModel.getPosition(annotation); // take the first most fine grained match if (position != null && touches(selection, position)) if (found == null || found.includes(position.offset) && found.includes(position.offset + position.length)) { found= position; bestMatch= annotation; } } } if (bestMatch != null) { fProjectionAnnotationModel.collapse(bestMatch); revealRange(selection.x, selection.y); } } }
/** * Disables the projection mode. */ public final void disableProjection() { if (isProjectionMode()) { removeProjectionAnnotationModel(getVisualAnnotationModel()); fProjectionAnnotationModel.removeAllAnnotations(); fFindReplaceDocumentAdapter= null; fireProjectionDisabled(); } }
private Annotation[] computeDifferences(ProjectionAnnotationModel model, Set<?> additions) { List<Object> deletions = new ArrayList<>(); for (Iterator<?> iter = model.getAnnotationIterator(); iter.hasNext();) { Object annotation = iter.next(); if (annotation instanceof ProjectionAnnotation) { Position position = model.getPosition((Annotation) annotation); if (additions.contains(position)) { additions.remove(position); } else { deletions.add(annotation); } } } return deletions.toArray(new Annotation[deletions.size()]); }
/** * Expands all annotations that overlap with the given range and are collapsed. Fires a model change event if * requested. * * @param offset the offset of the range * @param length the length of the range * @param fireModelChanged <code>true</code> if a model change event * should be fired, <code>false</code> otherwise * @return <code>true</code> if any annotation has been expanded, <code>false</code> otherwise */ protected boolean expandAll(int offset, int length, boolean fireModelChanged) { boolean expanding= false; Iterator<Annotation> iterator= getAnnotationIterator(); while (iterator.hasNext()) { ProjectionAnnotation annotation= (ProjectionAnnotation) iterator.next(); if (annotation.isCollapsed()) { Position position= getPosition(annotation); if (position != null && position.overlapsWith(offset, length) /* || is a delete at the boundary */ ) { annotation.markExpanded(); modifyAnnotation(annotation, false); expanding= true; } } } if (expanding && fireModelChanged) fireModelChanged(); return expanding; }
private void expand() { if (isProjectionMode()) { Position found= null; Annotation bestMatch= null; Point selection= getSelectedRange(); for (Iterator<Annotation> e= fProjectionAnnotationModel.getAnnotationIterator(); e.hasNext();) { ProjectionAnnotation annotation= (ProjectionAnnotation) e.next(); if (annotation.isCollapsed()) { Position position= fProjectionAnnotationModel.getPosition(annotation); // take the first most fine grained match if (position != null && touches(selection, position)) if (found == null || position.includes(found.offset) && position.includes(found.offset + found.length)) { found= position; bestMatch= annotation; } } } if (bestMatch != null) { fProjectionAnnotationModel.expand(bestMatch); revealRange(selection.x, selection.y); } } }