Merged work from HEAD
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java index a035d88..ca4a741 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java
@@ -2281,6 +2281,10 @@ action= new QuickFormatAction(); action.setActionDefinitionId(IJavaEditorActionDefinitionIds.QUICK_FORMAT); setAction(IJavaEditorActionDefinitionIds.QUICK_FORMAT, action); + + action= new RemoveOccurrenceAnnotations(this); + action.setActionDefinitionId(IJavaEditorActionDefinitionIds.REMOVE_OCCURRENCE_ANNOTATIONS); + setAction("RemoveOccurrenceAnnotations", action); //$NON-NLS-1$ // add annotation actions IAction annAction= getAction("AnnotationAction"); //$NON-NLS-1$ @@ -2352,6 +2356,7 @@ fMarkOccurrenceAnnotations= ((Boolean)event.getNewValue()).booleanValue(); if (!fMarkOccurrenceAnnotations) { fComputeCount++; + removeOccurrenceAnnotations(); } } } @@ -2681,7 +2686,21 @@ } } - + void removeOccurrenceAnnotations() { + IDocumentProvider documentProvider= getDocumentProvider(); + if (documentProvider == null) + return; + + IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput()); + if (annotationModel == null) + return; + + synchronized (annotationModel) { + for (int i= 0, size= fOccurrenceAnnotations.size(); i < size; i++) + annotationModel.removeAnnotation((Annotation)fOccurrenceAnnotations.get(i)); + fOccurrenceAnnotations.clear(); + } + } class OccurrencesFinder implements Runnable, IDocumentListener { private int fCount; @@ -2710,35 +2729,23 @@ if (isCancelled()) return; - IDocumentProvider documentProvider= getDocumentProvider(); - if (documentProvider == null) - return; - - IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput()); - if (annotationModel == null) - return; - - // Remove existing occurrence annotations - synchronized (annotationModel) { - for (int i= 0, size= fOccurrenceAnnotations.size(); i < size; i++) - annotationModel.removeAnnotation((Annotation)fOccurrenceAnnotations.get(i)); - fOccurrenceAnnotations.clear(); - } - - if (isCancelled()) - return; - // Find occurrences FindOccurrencesEngine engine= FindOccurrencesEngine.create(getInputJavaElement()); List matches= new ArrayList(); try { matches= engine.findOccurrences(fSelection.getOffset(), fSelection.getLength()); - if (matches == null || matches.isEmpty()) - return; } catch (JavaModelException e) { JavaPlugin.log(e); return; } + + if (matches == null || matches.isEmpty()) + return; + + if (isCancelled()) + return; + + removeOccurrenceAnnotations(); if (isCancelled()) return; @@ -2751,6 +2758,14 @@ if (document == null) return; + IDocumentProvider documentProvider= getDocumentProvider(); + if (documentProvider == null) + return; + + IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput()); + if (annotationModel == null) + return; + // Add occurrence annotations ArrayList annotations= new ArrayList(); ArrayList positions= new ArrayList(); @@ -3241,7 +3256,7 @@ */ protected CompositeRuler createCompositeRuler() { CompositeRuler ruler= new CompositeRuler(); - AnnotationRulerColumn column= new AnnotationRulerColumn(VERTICAL_RULER_WIDTH); + AnnotationRulerColumn column= new AnnotationRulerColumn(VERTICAL_RULER_WIDTH, getAnnotationAccess()); column.setHover(new JavaExpandHover(ruler, new IAnnotationListener() { public void annotationSelected(AnnotationEvent event) {