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 |
} |