### Eclipse Workspace Patch 1.0 #P org.eclipse.search Index: new search/org/eclipse/search2/internal/ui/text/MarkerHighlighter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/MarkerHighlighter.java,v retrieving revision 1.10 diff -u -r1.10 MarkerHighlighter.java --- new search/org/eclipse/search2/internal/ui/text/MarkerHighlighter.java 17 Jun 2005 15:50:14 -0000 1.10 +++ new search/org/eclipse/search2/internal/ui/text/MarkerHighlighter.java 11 Apr 2006 14:24:30 -0000 @@ -36,7 +36,7 @@ fMatchesToAnnotations= new HashMap(); } - public void addHighlights(final Match[] matches) { + public void addHighlights(final Match[] matches, String annotationLabel) { try { SearchPlugin.getWorkspace().run(new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { @@ -109,6 +109,6 @@ Match[] matches= new Match[fMatchesToAnnotations.keySet().size()]; fMatchesToAnnotations.keySet().toArray(matches); removeAll(); - addHighlights(matches); + addHighlights(matches, null); } } Index: new search/org/eclipse/search2/internal/ui/text/EditorAccessHighlighter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/EditorAccessHighlighter.java,v retrieving revision 1.11 diff -u -r1.11 EditorAccessHighlighter.java --- new search/org/eclipse/search2/internal/ui/text/EditorAccessHighlighter.java 28 Mar 2006 16:34:57 -0000 1.11 +++ new search/org/eclipse/search2/internal/ui/text/EditorAccessHighlighter.java 11 Apr 2006 14:24:29 -0000 @@ -41,42 +41,60 @@ public class EditorAccessHighlighter extends Highlighter { private ISearchEditorAccess fEditorAcess; - private Map fMatchesToAnnotations; + private HashMap fMatchesToAnnotations; public EditorAccessHighlighter(ISearchEditorAccess editorAccess) { fEditorAcess= editorAccess; fMatchesToAnnotations= new HashMap(); } - public void addHighlights(Match[] matches) { + public void addHighlights(Match[] matches, String annotationLabel) { Map mapsByAnnotationModel= new HashMap(); for (int i= 0; i < matches.length; i++) { - int offset= matches[i].getOffset(); - int length= matches[i].getLength(); - if (offset >= 0 && length >= 0) { - try { - Position position= createPosition(matches[i]); - if (position != null) { - Map map= getMap(mapsByAnnotationModel, matches[i]); - if (map != null) { - Annotation annotation= matches[i].isFiltered() - ? new Annotation(SearchPlugin.FILTERED_SEARCH_ANNOTATION_TYPE, true, null) - : new Annotation(SearchPlugin.SEARCH_ANNOTATION_TYPE, true, null); - fMatchesToAnnotations.put(matches[i], annotation); - map.put(annotation, position); - } + addHighlight(matches[i], annotationLabel, mapsByAnnotationModel); + } + for (Iterator maps= mapsByAnnotationModel.keySet().iterator(); maps.hasNext();) { + IAnnotationModel model= (IAnnotationModel) maps.next(); + Map positionMap= (Map) mapsByAnnotationModel.get(model); + addAnnotations(model, positionMap); + } + } + + private void addHighlight(Match match, String annotationLabel, Map mapsByAnnotationModel) { + int offset= match.getOffset(); + int length= match.getLength(); + if (offset >= 0 && length >= 0) { + try { + Position position= createPosition(match); + if (position != null) { + Map map= getMap(mapsByAnnotationModel, match); + if (map != null) { + Annotation annotation= match.isFiltered() + ? new Annotation(SearchPlugin.FILTERED_SEARCH_ANNOTATION_TYPE, true, annotationLabel) + : new Annotation(SearchPlugin.SEARCH_ANNOTATION_TYPE, true, annotationLabel); + fMatchesToAnnotations.put(match, annotation); + map.put(annotation, position); } - } catch (BadLocationException e) { - SearchPlugin.log(new Status(IStatus.ERROR, SearchPlugin.getID(), 0, SearchMessages.EditorAccessHighlighter_error_badLocation, e)); } + } catch (BadLocationException e) { + SearchPlugin.log(new Status(IStatus.ERROR, SearchPlugin.getID(), 0, SearchMessages.EditorAccessHighlighter_error_badLocation, e)); } } + } + + public void addHighlights(Map matchesToAnnotations) { + Map mapsByAnnotationModel= new HashMap(); + for (Iterator iter= matchesToAnnotations.entrySet().iterator(); iter.hasNext();) { + Map.Entry entry= (Map.Entry) iter.next(); + Match match= (Match) entry.getKey(); + Annotation oldAnnotation= (Annotation) entry.getValue(); + addHighlight(match, oldAnnotation.getText(), mapsByAnnotationModel); + } for (Iterator maps= mapsByAnnotationModel.keySet().iterator(); maps.hasNext();) { IAnnotationModel model= (IAnnotationModel) maps.next(); Map positionMap= (Map) mapsByAnnotationModel.get(model); addAnnotations(model, positionMap); } - } private Position createPosition(Match match) throws BadLocationException { @@ -193,10 +211,9 @@ } if (document != null && document.equals(textBuffer.getDocument())) { - Match[] matches= new Match[fMatchesToAnnotations.keySet().size()]; - fMatchesToAnnotations.keySet().toArray(matches); + Map matchesToAnnotations= (Map) fMatchesToAnnotations.clone(); removeAll(); - addHighlights(matches); + addHighlights(matchesToAnnotations); } } } Index: new search/org/eclipse/search2/internal/ui/text/AnnotationHighlighter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/AnnotationHighlighter.java,v retrieving revision 1.14 diff -u -r1.14 AnnotationHighlighter.java --- new search/org/eclipse/search2/internal/ui/text/AnnotationHighlighter.java 28 Mar 2006 16:34:57 -0000 1.14 +++ new search/org/eclipse/search2/internal/ui/text/AnnotationHighlighter.java 11 Apr 2006 14:24:29 -0000 @@ -16,7 +16,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Map; -import java.util.Set; import org.eclipse.core.filebuffers.IFileBuffer; import org.eclipse.core.filebuffers.ITextFileBuffer; @@ -42,7 +41,7 @@ public class AnnotationHighlighter extends Highlighter { private IAnnotationModel fModel; private IDocument fDocument; - private Map fMatchesToAnnotations; + private HashMap fMatchesToAnnotations; public AnnotationHighlighter(IAnnotationModel model, IDocument document) { fModel= model; @@ -50,26 +49,40 @@ fMatchesToAnnotations= new HashMap(); } - public void addHighlights(Match[] matches) { + public void addHighlights(Match[] matches, String annotationLabel) { HashMap map= new HashMap(matches.length); for (int i= 0; i < matches.length; i++) { - int offset= matches[i].getOffset(); - int length= matches[i].getLength(); - if (offset >= 0 && length >= 0) { - Position position= createPosition(matches[i]); - if (position != null) { - Annotation annotation= matches[i].isFiltered() - ? new Annotation(SearchPlugin.FILTERED_SEARCH_ANNOTATION_TYPE, true, null) - : new Annotation(SearchPlugin.SEARCH_ANNOTATION_TYPE, true, null); - fMatchesToAnnotations.put(matches[i], annotation); - map.put(annotation, position); - } + addHighlight(matches[i], annotationLabel, map); + } + addAnnotations(map); + } + + private void addHighlight(Match match, String annotationLabel, HashMap map) { + int offset= match.getOffset(); + int length= match.getLength(); + if (offset >= 0 && length >= 0) { + Position position= createPosition(match); + if (position != null) { + Annotation annotation= match.isFiltered() + ? new Annotation(SearchPlugin.FILTERED_SEARCH_ANNOTATION_TYPE, true, annotationLabel) + : new Annotation(SearchPlugin.SEARCH_ANNOTATION_TYPE, true, annotationLabel); + fMatchesToAnnotations.put(match, annotation); + map.put(annotation, position); } } + } + + private void addHighlights(Map matchesToAnnotations) { + HashMap map= new HashMap(matchesToAnnotations.size()); + for (Iterator iter= matchesToAnnotations.entrySet().iterator(); iter.hasNext();) { + Map.Entry entry= (Map.Entry) iter.next(); + Match match= (Match) entry.getKey(); + Annotation oldAnnotation= (Annotation) entry.getValue(); + addHighlight(match, oldAnnotation.getText(), map); + } addAnnotations(map); - } - + private Position createPosition(Match match) { Position position= InternalSearchUI.getInstance().getPositionTracker().getCurrentPosition(match); if (position == null) @@ -149,10 +162,9 @@ ITextFileBuffer textBuffer= (ITextFileBuffer) buffer; if (fDocument != null && fDocument.equals(textBuffer.getDocument())) { - Set allMatches= fMatchesToAnnotations.keySet(); - Match[] matchesCopy= (Match[]) allMatches.toArray(new Match[allMatches.size()]); + Map matchesToAnnotations= (Map) fMatchesToAnnotations.clone(); removeAll(); - addHighlights(matchesCopy); + addHighlights(matchesToAnnotations); } } } Index: new search/org/eclipse/search2/internal/ui/text/Highlighter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/Highlighter.java,v retrieving revision 1.5 diff -u -r1.5 Highlighter.java --- new search/org/eclipse/search2/internal/ui/text/Highlighter.java 28 Mar 2006 16:34:57 -0000 1.5 +++ new search/org/eclipse/search2/internal/ui/text/Highlighter.java 11 Apr 2006 14:24:30 -0000 @@ -55,7 +55,7 @@ FileBuffers.getTextFileBufferManager().addFileBufferListener(fBufferListener); } - public void addHighlights(Match[] matches) { + public void addHighlights(Match[] matches, String annotationLabel) { } public void removeHighlights(Match[] matches) { Index: new search/org/eclipse/search2/internal/ui/text/EditorAnnotationManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/EditorAnnotationManager.java,v retrieving revision 1.7 diff -u -r1.7 EditorAnnotationManager.java --- new search/org/eclipse/search2/internal/ui/text/EditorAnnotationManager.java 28 Mar 2006 16:34:57 -0000 1.7 +++ new search/org/eclipse/search2/internal/ui/text/EditorAnnotationManager.java 11 Apr 2006 14:24:29 -0000 @@ -125,7 +125,7 @@ Match[] matchesInEditor= getMatchesInEditor(me.getMatches(), adapter); if (matchesInEditor != null && matchesInEditor.length > 0) { if (me.getKind() == MatchEvent.ADDED) { - addAnnotations(matchesInEditor); + addAnnotations(matchesInEditor, result.getAnnotationText()); } else { removeAnnotations(matchesInEditor); } @@ -212,7 +212,7 @@ Match[] matches= matchAdapter.computeContainedMatches(result, fEditor); if (matches == null || matches.length == 0) return; - addAnnotations(matches); + addAnnotations(matches, result.getAnnotationText()); } private void removeAnnotations(AbstractTextSearchResult result) { @@ -226,11 +226,11 @@ } } - private void addAnnotations(Match[] matches) { + private void addAnnotations(Match[] matches, String annotationLabel) { if (fHighlighter == null) { fHighlighter= createHighlighter(); } - fHighlighter.addHighlights(matches); + fHighlighter.addHighlights(matches, annotationLabel); } private void removeAnnotations(Match[] matches) { Index: new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java,v retrieving revision 1.18 diff -u -r1.18 AbstractTextSearchResult.java --- new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java 28 Mar 2006 16:34:57 -0000 1.18 +++ new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java 11 Apr 2006 14:24:29 -0000 @@ -320,4 +320,15 @@ * @see IFileMatchAdapter */ public abstract IFileMatchAdapter getFileMatchAdapter(); + + /** + * Returns a user readable text for the annotations that may be created for + * the matches of this result. The text of an annotation is for instance shown + * as a hoover in the editor. + * + * @return an appropriate text or null. + */ + public String getAnnotationText() { + return null; + } } Index: search/org/eclipse/search/internal/ui/SearchMessages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.properties,v retrieving revision 1.121 diff -u -r1.121 SearchMessages.properties --- search/org/eclipse/search/internal/ui/SearchMessages.properties 10 Apr 2006 13:36:05 -0000 1.121 +++ search/org/eclipse/search/internal/ui/SearchMessages.properties 11 Apr 2006 14:24:30 -0000 @@ -159,6 +159,7 @@ FileSearchPage_sort_name_label=Name FileSearchPage_sort_path_label=Path +FileSearchResult_annotation_text=matches {0} FileSearchPage_error_marker=Could not create marker FileSearchPage_sort_by_label=Sort By FileSearchPage_limited_format={0} (showing {1} of {2} files) Index: search/org/eclipse/search/internal/ui/SearchMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.java,v retrieving revision 1.23 diff -u -r1.23 SearchMessages.java --- search/org/eclipse/search/internal/ui/SearchMessages.java 11 Apr 2006 07:16:50 -0000 1.23 +++ search/org/eclipse/search/internal/ui/SearchMessages.java 11 Apr 2006 14:24:30 -0000 @@ -21,6 +21,7 @@ // Do not instantiate } + public static String FileSearchResult_annotation_text; public static String FileTextSearchScope_scope_empty; public static String FileTextSearchScope_scope_single; public static String FileTextSearchScope_scope_double; Index: search/org/eclipse/search/internal/ui/text/FileSearchResult.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchResult.java,v retrieving revision 1.9 diff -u -r1.9 FileSearchResult.java --- search/org/eclipse/search/internal/ui/text/FileSearchResult.java 12 May 2005 13:22:39 -0000 1.9 +++ search/org/eclipse/search/internal/ui/text/FileSearchResult.java 11 Apr 2006 14:24:30 -0000 @@ -24,6 +24,8 @@ import org.eclipse.search.ui.text.IFileMatchAdapter; import org.eclipse.search.ui.text.Match; +import org.eclipse.search.internal.ui.Messages; +import org.eclipse.search.internal.ui.SearchMessages; import org.eclipse.search.internal.ui.SearchPluginImages; public class FileSearchResult extends AbstractTextSearchResult implements IEditorMatchAdapter, IFileMatchAdapter { @@ -83,4 +85,7 @@ public IEditorMatchAdapter getEditorMatchAdapter() { return this; } + public String getAnnotationText() { + return Messages.format(SearchMessages.FileSearchResult_annotation_text, fQuery.getSearchString()); + } }