@Override protected IAnnotationModel createAnnotationModel(Object element) throws CoreException { return new org.eclipse.jface.text.source.AnnotationModel(); }
/** * Removes the given annotation from the annotation model. * If requested inform all model change listeners about this change. * * @param annotation the annotation to be removed * @param fireModelChanged indicates whether to notify all model listeners */ protected void removeAnnotation(Annotation annotation, boolean fireModelChanged) { if (fAnnotations.containsKey(annotation)) { Position p= null; p= fAnnotations.get(annotation); if (fDocument != null) { removePosition(fDocument, p); // p.delete(); } fAnnotations.remove(annotation); fPositions.remove(p); synchronized (getLockObject()) { getAnnotationModelEvent().annotationRemoved(annotation, p); } if (fireModelChanged) fireModelChanged(); } }
@Override public Iterator<Annotation> getAnnotationIterator() { return getAnnotationIterator(true, true); }
/** * Informs all annotation model listeners that this model has been changed. */ protected void fireModelChanged() { AnnotationModelEvent modelEvent= null; synchronized(getLockObject()) { if (fModelEvent != null) { modelEvent= fModelEvent; fModelEvent= null; } } if (modelEvent != null) fireModelChanged(modelEvent); }
/** * Modifies the given annotation if the annotation is managed by this * annotation model. * <p> * If requested, all annotation model change listeners will be informed * about the change. * * @param annotation the annotation to be modified * @param fireModelChanged indicates whether to notify all model listeners * @since 3.0 */ protected void modifyAnnotation(Annotation annotation, boolean fireModelChanged) { if (fAnnotations.containsKey(annotation)) { synchronized (getLockObject()) { getAnnotationModelEvent().annotationChanged(annotation); } if (fireModelChanged) fireModelChanged(); } }
/** * Removes the given annotations from this model. If requested all * annotation model listeners will be informed about this change. * <code>modelInitiated</code> indicates whether the deletion has * been initiated by this model or by one of its clients. * * @param annotations the annotations to be removed * @param fireModelChanged indicates whether to notify all model listeners * @param modelInitiated indicates whether this changes has been initiated by this model */ protected void removeAnnotations(List<? extends Annotation> annotations, boolean fireModelChanged, boolean modelInitiated) { if (annotations.size() > 0) { Iterator<? extends Annotation> e= annotations.iterator(); while (e.hasNext()) removeAnnotation(e.next(), false); if (fireModelChanged) fireModelChanged(); } }
removeAnnotation(annotation, fireModelChanged); } else { Position p= fAnnotations.get(annotation); synchronized (getLockObject()) { getAnnotationModelEvent().annotationChanged(annotation); fireModelChanged(); addAnnotation(annotation, position, fireModelChanged); } catch (BadLocationException x) {
/** * Adds the given annotation to this model. Associates the * annotation with the given position. If requested, all annotation * model listeners are informed about this model change. If the annotation * is already managed by this model nothing happens. * * @param annotation the annotation to add * @param position the associate position * @param fireModelChanged indicates whether to notify all model listeners * @throws BadLocationException if the position is not a valid document position */ protected void addAnnotation(Annotation annotation, Position position, boolean fireModelChanged) throws BadLocationException { if (!fAnnotations.containsKey(annotation)) { addPosition(fDocument, position); fAnnotations.put(annotation, position); fPositions.put(position, annotation); synchronized (getLockObject()) { getAnnotationModelEvent().annotationAdded(annotation); } if (fireModelChanged) fireModelChanged(); } }
Object annotationLockObject = annotationModel.getLockObject(); if (annotationLockObject == null) { annotationLockObject = annotationModel; Iterator<Annotation> iterator = annotationModel.getAnnotationIterator(); while (iterator.hasNext()) { Annotation annotation = iterator.next(); Position position = annotationModel.getPosition(annotation); String widgetText = viewer.getTextWidget().getText(); Font font = null; annotationModel.modifyAnnotationPosition(annotation, new Position(position.offset, originalNewlines));
@Override public void run() { fireModelChanged(); } }.start();
/** * Replaces the given annotations in this model and if advised fires a * model change event. * * @param annotationsToRemove the annotations to be removed * @param annotationsToAdd the annotations to be added * @param fireModelChanged <code>true</code> if a model change event * should be fired, <code>false</code> otherwise * @throws BadLocationException in case an annotation should be added at an * invalid position * @since 3.0 */ protected void replaceAnnotations(Annotation[] annotationsToRemove, Map<? extends Annotation, ? extends Position> annotationsToAdd, boolean fireModelChanged) throws BadLocationException { if (annotationsToRemove != null) { for (Annotation element : annotationsToRemove) removeAnnotation(element, false); } if (annotationsToAdd != null) { Iterator<? extends Entry<? extends Annotation, ? extends Position>> iter= annotationsToAdd.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<? extends Annotation, ? extends Position> mapEntry= iter.next(); Annotation annotation= mapEntry.getKey(); Position position= mapEntry.getValue(); addAnnotation(annotation, position, false); } } if (fireModelChanged) fireModelChanged(); }
Iterator<Annotation> e= getAnnotationMap().keySetIterator(); while (e.hasNext()) { Annotation a= e.next(); removeAnnotations(deleted, false, false); synchronized (getLockObject()) { if (fModelEvent != null) new Thread() { removeAnnotations(deleted, fireModelChanged, false);
/** * Returns the current annotation model event. This is the event that will be sent out * when calling <code>fireModelChanged</code>. * * @return the current annotation model event * @since 3.0 */ protected final AnnotationModelEvent getAnnotationModelEvent() { synchronized (getLockObject()) { if (fModelEvent == null) { fModelEvent= createAnnotationModelEvent(); fModelEvent.markWorldChange(false); fModificationStamp= new Object(); } return fModelEvent; } }
/** * Returns an iterator as specified in {@link IAnnotationModelExtension2#getAnnotationIterator(int, int, boolean, boolean)} * * @param offset region start * @param length region length * @param canStartBefore position can start before region * @param canEndAfter position can end after region * @return an iterator to iterate over annotations in region * @see IAnnotationModelExtension2#getAnnotationIterator(int, int, boolean, boolean) * @since 3.4 */ private Iterator<Annotation> getRegionAnnotationIterator(int offset, int length, boolean canStartBefore, boolean canEndAfter) { if (!(fDocument instanceof AbstractDocument)) return new RegionIterator(getAnnotationIterator(true), this, offset, length, canStartBefore, canEndAfter); AbstractDocument document= (AbstractDocument) fDocument; cleanup(true); try { Position[] positions= document.getPositions(IDocument.DEFAULT_CATEGORY, offset, length, canStartBefore, canEndAfter); return new AnnotationsInterator(positions, fPositions); } catch (BadPositionCategoryException e) { // can happen if e.g. the document doesn't contain such a category, or when removed in a different thread return Collections.<Annotation>emptyList().iterator(); } }
@Override public void modifyAnnotationPosition(Annotation annotation, Position position) { modifyAnnotationPosition(annotation, position, true); }
removeAnnotation(annotation, fireModelChanged); } else { Position p= fAnnotations.get(annotation); synchronized (getLockObject()) { getAnnotationModelEvent().annotationChanged(annotation); fireModelChanged(); addAnnotation(annotation, position, fireModelChanged); } catch (BadLocationException x) {
/** * Adds the given annotation to this model. Associates the * annotation with the given position. If requested, all annotation * model listeners are informed about this model change. If the annotation * is already managed by this model nothing happens. * * @param annotation the annotation to add * @param position the associate position * @param fireModelChanged indicates whether to notify all model listeners * @throws BadLocationException if the position is not a valid document position */ protected void addAnnotation(Annotation annotation, Position position, boolean fireModelChanged) throws BadLocationException { if (!fAnnotations.containsKey(annotation)) { addPosition(fDocument, position); fAnnotations.put(annotation, position); fPositions.put(position, annotation); synchronized (getLockObject()) { getAnnotationModelEvent().annotationAdded(annotation); } if (fireModelChanged) fireModelChanged(); } }
/** * Modifies the given annotation if the annotation is managed by this * annotation model. * <p> * If requested, all annotation model change listeners will be informed * about the change. * * @param annotation the annotation to be modified * @param fireModelChanged indicates whether to notify all model listeners * @since 3.0 */ protected void modifyAnnotation(Annotation annotation, boolean fireModelChanged) { if (fAnnotations.containsKey(annotation)) { synchronized (getLockObject()) { getAnnotationModelEvent().annotationChanged(annotation); } if (fireModelChanged) fireModelChanged(); } }
@Override public void modelChanged(AnnotationModelEvent event) { AnnotationModel.this.fireModelChanged(event); } }
/** * Replaces the given annotations in this model and if advised fires a * model change event. * * @param annotationsToRemove the annotations to be removed * @param annotationsToAdd the annotations to be added * @param fireModelChanged <code>true</code> if a model change event * should be fired, <code>false</code> otherwise * @throws BadLocationException in case an annotation should be added at an * invalid position * @since 3.0 */ protected void replaceAnnotations(Annotation[] annotationsToRemove, Map<? extends Annotation, ? extends Position> annotationsToAdd, boolean fireModelChanged) throws BadLocationException { if (annotationsToRemove != null) { for (int i= 0, length= annotationsToRemove.length; i < length; i++) removeAnnotation(annotationsToRemove[i], false); } if (annotationsToAdd != null) { Iterator<? extends Entry<? extends Annotation, ? extends Position>> iter= annotationsToAdd.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<? extends Annotation, ? extends Position> mapEntry= iter.next(); Annotation annotation= mapEntry.getKey(); Position position= mapEntry.getValue(); addAnnotation(annotation, position, false); } } if (fireModelChanged) fireModelChanged(); }