View | Details | Raw Unified | Return to bug 63381
Collapse All | Expand All

(-)new search/org/eclipse/search2/internal/ui/text/MarkerHighlighter.java (-2 / +2 lines)
Lines 36-42 Link Here
36
		fMatchesToAnnotations= new HashMap();
36
		fMatchesToAnnotations= new HashMap();
37
	}
37
	}
38
38
39
	public void addHighlights(final Match[] matches) {
39
	public void addHighlights(final Match[] matches, String annotationLabel) {
40
		try {
40
		try {
41
			SearchPlugin.getWorkspace().run(new IWorkspaceRunnable() {
41
			SearchPlugin.getWorkspace().run(new IWorkspaceRunnable() {
42
				public void run(IProgressMonitor monitor) throws CoreException {
42
				public void run(IProgressMonitor monitor) throws CoreException {
Lines 109-114 Link Here
109
		Match[] matches= new Match[fMatchesToAnnotations.keySet().size()];
109
		Match[] matches= new Match[fMatchesToAnnotations.keySet().size()];
110
		fMatchesToAnnotations.keySet().toArray(matches);
110
		fMatchesToAnnotations.keySet().toArray(matches);
111
		removeAll();
111
		removeAll();
112
		addHighlights(matches);
112
		addHighlights(matches, null);
113
	}
113
	}
114
}
114
}
(-)new search/org/eclipse/search2/internal/ui/text/EditorAccessHighlighter.java (-22 / +39 lines)
Lines 41-82 Link Here
41
41
42
public class EditorAccessHighlighter extends Highlighter {
42
public class EditorAccessHighlighter extends Highlighter {
43
	private ISearchEditorAccess fEditorAcess;
43
	private ISearchEditorAccess fEditorAcess;
44
	private Map fMatchesToAnnotations;
44
	private HashMap fMatchesToAnnotations;
45
	
45
	
46
	public EditorAccessHighlighter(ISearchEditorAccess editorAccess) {
46
	public EditorAccessHighlighter(ISearchEditorAccess editorAccess) {
47
		fEditorAcess= editorAccess;
47
		fEditorAcess= editorAccess;
48
		fMatchesToAnnotations= new HashMap();
48
		fMatchesToAnnotations= new HashMap();
49
	}
49
	}
50
50
51
	public void addHighlights(Match[] matches) {
51
	public void addHighlights(Match[] matches, String annotationLabel) {
52
		Map mapsByAnnotationModel= new HashMap();
52
		Map mapsByAnnotationModel= new HashMap();
53
		for (int i= 0; i < matches.length; i++) {
53
		for (int i= 0; i < matches.length; i++) {
54
			int offset= matches[i].getOffset();
54
			addHighlight(matches[i], annotationLabel, mapsByAnnotationModel);
55
			int length= matches[i].getLength();
55
		}
56
			if (offset >= 0 && length >= 0) {
56
		for (Iterator maps= mapsByAnnotationModel.keySet().iterator(); maps.hasNext();) {
57
				try {
57
			IAnnotationModel model= (IAnnotationModel) maps.next();
58
					Position position= createPosition(matches[i]);
58
			Map positionMap= (Map) mapsByAnnotationModel.get(model);
59
					if (position != null) {
59
			addAnnotations(model, positionMap);
60
						Map map= getMap(mapsByAnnotationModel, matches[i]);
60
		}		
61
						if (map != null) {
61
	}
62
							Annotation annotation= matches[i].isFiltered() 
62
63
							? new Annotation(SearchPlugin.FILTERED_SEARCH_ANNOTATION_TYPE, true, null)
63
	private void addHighlight(Match match, String annotationLabel, Map mapsByAnnotationModel) {
64
							: new Annotation(SearchPlugin.SEARCH_ANNOTATION_TYPE, true, null);
64
		int offset= match.getOffset();
65
							fMatchesToAnnotations.put(matches[i], annotation);
65
		int length= match.getLength();
66
							map.put(annotation, position);
66
		if (offset >= 0 && length >= 0) {
67
						}
67
			try {
68
				Position position= createPosition(match);
69
				if (position != null) {
70
					Map map= getMap(mapsByAnnotationModel, match);
71
					if (map != null) {
72
						Annotation annotation= match.isFiltered() 
73
						? new Annotation(SearchPlugin.FILTERED_SEARCH_ANNOTATION_TYPE, true, annotationLabel)
74
						: new Annotation(SearchPlugin.SEARCH_ANNOTATION_TYPE, true, annotationLabel);
75
						fMatchesToAnnotations.put(match, annotation);
76
						map.put(annotation, position);
68
					}
77
					}
69
				} catch (BadLocationException e) {
70
					SearchPlugin.log(new Status(IStatus.ERROR, SearchPlugin.getID(), 0, SearchMessages.EditorAccessHighlighter_error_badLocation, e)); 
71
				}
78
				}
79
			} catch (BadLocationException e) {
80
				SearchPlugin.log(new Status(IStatus.ERROR, SearchPlugin.getID(), 0, SearchMessages.EditorAccessHighlighter_error_badLocation, e)); 
72
			}
81
			}
73
		}
82
		}
83
	}
84
85
	public void addHighlights(Map matchesToAnnotations) {
86
		Map mapsByAnnotationModel= new HashMap();
87
		for (Iterator iter= matchesToAnnotations.entrySet().iterator(); iter.hasNext();) {
88
			Map.Entry entry= (Map.Entry) iter.next();
89
			Match match= (Match) entry.getKey();
90
			Annotation oldAnnotation= (Annotation) entry.getValue();
91
			addHighlight(match, oldAnnotation.getText(), mapsByAnnotationModel);
92
		}
74
		for (Iterator maps= mapsByAnnotationModel.keySet().iterator(); maps.hasNext();) {
93
		for (Iterator maps= mapsByAnnotationModel.keySet().iterator(); maps.hasNext();) {
75
			IAnnotationModel model= (IAnnotationModel) maps.next();
94
			IAnnotationModel model= (IAnnotationModel) maps.next();
76
			Map positionMap= (Map) mapsByAnnotationModel.get(model);
95
			Map positionMap= (Map) mapsByAnnotationModel.get(model);
77
			addAnnotations(model, positionMap);
96
			addAnnotations(model, positionMap);
78
		}
97
		}
79
		
80
	}
98
	}
81
99
82
	private Position createPosition(Match match) throws BadLocationException {
100
	private Position createPosition(Match match) throws BadLocationException {
Lines 193-202 Link Here
193
		}
211
		}
194
		
212
		
195
		if (document != null && document.equals(textBuffer.getDocument())) {
213
		if (document != null && document.equals(textBuffer.getDocument())) {
196
			Match[] matches= new Match[fMatchesToAnnotations.keySet().size()];
214
			Map matchesToAnnotations= (Map) fMatchesToAnnotations.clone();
197
			fMatchesToAnnotations.keySet().toArray(matches);
198
			removeAll();
215
			removeAll();
199
			addHighlights(matches);			
216
			addHighlights(matchesToAnnotations);
200
		}
217
		}
201
	}
218
	}
202
}
219
}
(-)new search/org/eclipse/search2/internal/ui/text/AnnotationHighlighter.java (-19 / +31 lines)
Lines 16-22 Link Here
16
import java.util.HashSet;
16
import java.util.HashSet;
17
import java.util.Iterator;
17
import java.util.Iterator;
18
import java.util.Map;
18
import java.util.Map;
19
import java.util.Set;
20
19
21
import org.eclipse.core.filebuffers.IFileBuffer;
20
import org.eclipse.core.filebuffers.IFileBuffer;
22
import org.eclipse.core.filebuffers.ITextFileBuffer;
21
import org.eclipse.core.filebuffers.ITextFileBuffer;
Lines 42-48 Link Here
42
public class AnnotationHighlighter extends Highlighter {
41
public class AnnotationHighlighter extends Highlighter {
43
	private IAnnotationModel fModel;
42
	private IAnnotationModel fModel;
44
	private IDocument fDocument;
43
	private IDocument fDocument;
45
	private Map fMatchesToAnnotations;
44
	private HashMap fMatchesToAnnotations;
46
	
45
	
47
	public AnnotationHighlighter(IAnnotationModel model, IDocument document) {
46
	public AnnotationHighlighter(IAnnotationModel model, IDocument document) {
48
		fModel= model;
47
		fModel= model;
Lines 50-75 Link Here
50
		fMatchesToAnnotations= new HashMap();
49
		fMatchesToAnnotations= new HashMap();
51
	}
50
	}
52
51
53
	public void addHighlights(Match[] matches) {
52
	public void addHighlights(Match[] matches, String annotationLabel) {
54
		HashMap map= new HashMap(matches.length);
53
		HashMap map= new HashMap(matches.length);
55
		for (int i= 0; i < matches.length; i++) {
54
		for (int i= 0; i < matches.length; i++) {
56
			int offset= matches[i].getOffset();
55
			addHighlight(matches[i], annotationLabel, map);
57
			int length= matches[i].getLength();
56
		}
58
			if (offset >= 0 && length >= 0) {
57
		addAnnotations(map);
59
				Position position= createPosition(matches[i]);
58
	}
60
				if (position != null) {
59
61
					Annotation annotation= matches[i].isFiltered() 
60
	private void addHighlight(Match match, String annotationLabel, HashMap map) {
62
						? new Annotation(SearchPlugin.FILTERED_SEARCH_ANNOTATION_TYPE, true, null)
61
		int offset= match.getOffset();
63
						: new Annotation(SearchPlugin.SEARCH_ANNOTATION_TYPE, true, null);
62
		int length= match.getLength();
64
					fMatchesToAnnotations.put(matches[i], annotation);
63
		if (offset >= 0 && length >= 0) {
65
					map.put(annotation, position);
64
			Position position= createPosition(match);
66
				}
65
			if (position != null) {
66
				Annotation annotation= match.isFiltered() 
67
					? new Annotation(SearchPlugin.FILTERED_SEARCH_ANNOTATION_TYPE, true, annotationLabel)
68
					: new Annotation(SearchPlugin.SEARCH_ANNOTATION_TYPE, true, annotationLabel);
69
				fMatchesToAnnotations.put(match, annotation);
70
				map.put(annotation, position);
67
			}
71
			}
68
		}
72
		}
73
	}
74
75
	private void addHighlights(Map matchesToAnnotations) {
76
		HashMap map= new HashMap(matchesToAnnotations.size());
77
		for (Iterator iter= matchesToAnnotations.entrySet().iterator(); iter.hasNext();) {
78
			Map.Entry entry= (Map.Entry) iter.next();
79
			Match match= (Match) entry.getKey();
80
			Annotation oldAnnotation= (Annotation) entry.getValue();
81
			addHighlight(match, oldAnnotation.getText(), map);
82
		}
69
		addAnnotations(map);
83
		addAnnotations(map);
70
		
71
	}
84
	}
72
	
85
73
	private Position createPosition(Match match) {
86
	private Position createPosition(Match match) {
74
		Position position= InternalSearchUI.getInstance().getPositionTracker().getCurrentPosition(match);
87
		Position position= InternalSearchUI.getInstance().getPositionTracker().getCurrentPosition(match);
75
		if (position == null)
88
		if (position == null)
Lines 149-158 Link Here
149
		
162
		
150
		ITextFileBuffer textBuffer= (ITextFileBuffer) buffer;
163
		ITextFileBuffer textBuffer= (ITextFileBuffer) buffer;
151
		if (fDocument != null && fDocument.equals(textBuffer.getDocument())) {
164
		if (fDocument != null && fDocument.equals(textBuffer.getDocument())) {
152
			Set allMatches= fMatchesToAnnotations.keySet();
165
			Map matchesToAnnotations= (Map) fMatchesToAnnotations.clone();
153
			Match[] matchesCopy= (Match[]) allMatches.toArray(new Match[allMatches.size()]);
154
			removeAll();
166
			removeAll();
155
			addHighlights(matchesCopy);
167
			addHighlights(matchesToAnnotations);
156
		}
168
		}
157
	}
169
	}
158
}
170
}
(-)new search/org/eclipse/search2/internal/ui/text/Highlighter.java (-1 / +1 lines)
Lines 55-61 Link Here
55
		FileBuffers.getTextFileBufferManager().addFileBufferListener(fBufferListener);
55
		FileBuffers.getTextFileBufferManager().addFileBufferListener(fBufferListener);
56
	}
56
	}
57
	
57
	
58
	public void addHighlights(Match[] matches) {
58
	public void addHighlights(Match[] matches, String annotationLabel) {
59
	}
59
	}
60
60
61
	public void removeHighlights(Match[] matches) {
61
	public void removeHighlights(Match[] matches) {
(-)new search/org/eclipse/search2/internal/ui/text/EditorAnnotationManager.java (-4 / +4 lines)
Lines 125-131 Link Here
125
					Match[] matchesInEditor= getMatchesInEditor(me.getMatches(), adapter);
125
					Match[] matchesInEditor= getMatchesInEditor(me.getMatches(), adapter);
126
					if (matchesInEditor != null && matchesInEditor.length > 0) {
126
					if (matchesInEditor != null && matchesInEditor.length > 0) {
127
						if (me.getKind() == MatchEvent.ADDED) {
127
						if (me.getKind() == MatchEvent.ADDED) {
128
							addAnnotations(matchesInEditor);
128
							addAnnotations(matchesInEditor, result.getAnnotationText());
129
						} else {
129
						} else {
130
							removeAnnotations(matchesInEditor);
130
							removeAnnotations(matchesInEditor);
131
						}
131
						}
Lines 212-218 Link Here
212
		Match[] matches= matchAdapter.computeContainedMatches(result, fEditor);
212
		Match[] matches= matchAdapter.computeContainedMatches(result, fEditor);
213
		if (matches == null || matches.length == 0)
213
		if (matches == null || matches.length == 0)
214
			return;
214
			return;
215
		addAnnotations(matches);
215
		addAnnotations(matches, result.getAnnotationText());
216
	}
216
	}
217
	
217
	
218
	private void removeAnnotations(AbstractTextSearchResult result) {
218
	private void removeAnnotations(AbstractTextSearchResult result) {
Lines 226-236 Link Here
226
		}
226
		}
227
	}
227
	}
228
228
229
	private void addAnnotations(Match[] matches) {
229
	private void addAnnotations(Match[] matches, String annotationLabel) {
230
		if (fHighlighter == null) {
230
		if (fHighlighter == null) {
231
			fHighlighter= createHighlighter();
231
			fHighlighter= createHighlighter();
232
		}
232
		}
233
		fHighlighter.addHighlights(matches);
233
		fHighlighter.addHighlights(matches, annotationLabel);
234
	}
234
	}
235
235
236
	private void removeAnnotations(Match[] matches) {
236
	private void removeAnnotations(Match[] matches) {
(-)new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java (+11 lines)
Lines 320-323 Link Here
320
	 * @see IFileMatchAdapter
320
	 * @see IFileMatchAdapter
321
	 */
321
	 */
322
	public abstract IFileMatchAdapter getFileMatchAdapter();
322
	public abstract IFileMatchAdapter getFileMatchAdapter();
323
324
	/**
325
	 * Returns a user readable text for the annotations that may be created for
326
	 * the matches of this result. The text of an annotation is for instance shown
327
	 * as a hoover in the editor.
328
	 * 
329
	 * @return an appropriate text or <code>null</code>.
330
	 */
331
	public String getAnnotationText() {
332
		return null;
333
	}
323
}
334
}
(-)search/org/eclipse/search/internal/ui/SearchMessages.properties (+1 lines)
Lines 159-164 Link Here
159
159
160
FileSearchPage_sort_name_label=Name
160
FileSearchPage_sort_name_label=Name
161
FileSearchPage_sort_path_label=Path
161
FileSearchPage_sort_path_label=Path
162
FileSearchResult_annotation_text=matches {0}
162
FileSearchPage_error_marker=Could not create marker
163
FileSearchPage_error_marker=Could not create marker
163
FileSearchPage_sort_by_label=Sort By
164
FileSearchPage_sort_by_label=Sort By
164
FileSearchPage_limited_format={0} (showing {1} of {2} files)
165
FileSearchPage_limited_format={0} (showing {1} of {2} files)
(-)search/org/eclipse/search/internal/ui/SearchMessages.java (+1 lines)
Lines 21-26 Link Here
21
		// Do not instantiate
21
		// Do not instantiate
22
	}
22
	}
23
23
24
	public static String FileSearchResult_annotation_text;
24
	public static String FileTextSearchScope_scope_empty;
25
	public static String FileTextSearchScope_scope_empty;
25
	public static String FileTextSearchScope_scope_single;
26
	public static String FileTextSearchScope_scope_single;
26
	public static String FileTextSearchScope_scope_double;
27
	public static String FileTextSearchScope_scope_double;
(-)search/org/eclipse/search/internal/ui/text/FileSearchResult.java (+5 lines)
Lines 24-29 Link Here
24
import org.eclipse.search.ui.text.IFileMatchAdapter;
24
import org.eclipse.search.ui.text.IFileMatchAdapter;
25
import org.eclipse.search.ui.text.Match;
25
import org.eclipse.search.ui.text.Match;
26
26
27
import org.eclipse.search.internal.ui.Messages;
28
import org.eclipse.search.internal.ui.SearchMessages;
27
import org.eclipse.search.internal.ui.SearchPluginImages;
29
import org.eclipse.search.internal.ui.SearchPluginImages;
28
30
29
public class FileSearchResult extends AbstractTextSearchResult implements IEditorMatchAdapter, IFileMatchAdapter {
31
public class FileSearchResult extends AbstractTextSearchResult implements IEditorMatchAdapter, IFileMatchAdapter {
Lines 83-86 Link Here
83
	public IEditorMatchAdapter getEditorMatchAdapter() {
85
	public IEditorMatchAdapter getEditorMatchAdapter() {
84
		return this;
86
		return this;
85
	}
87
	}
88
	public String getAnnotationText() {
89
		return Messages.format(SearchMessages.FileSearchResult_annotation_text, fQuery.getSearchString());
90
	}
86
}
91
}

Return to bug 63381