@Override public void addHighlights(Match[] matches) { HashMap<Annotation, Position> map= new HashMap<>(matches.length); for (Match match : matches) { 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, null) : new Annotation(SearchPlugin.SEARCH_ANNOTATION_TYPE, true, null); fMatchesToAnnotations.put(match, annotation); map.put(annotation, position); } } } addAnnotations(map); }
public void addHighlights(Match[] matches) { 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); } } } addAnnotations(map); }
public void addHighlights(Match[] matches) { 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); } } } catch (BadLocationException e) { SearchPlugin.log(new Status(IStatus.ERROR, SearchPlugin.getID(), 0, SearchMessages.EditorAccessHighlighter_error_badLocation, e)); } } } for (Iterator maps= mapsByAnnotationModel.keySet().iterator(); maps.hasNext();) { IAnnotationModel model= (IAnnotationModel) maps.next(); Map positionMap= (Map) mapsByAnnotationModel.get(model); addAnnotations(model, positionMap); } }
@Override public void addHighlights(Match[] matches) { Map<IAnnotationModel, HashMap<Annotation, Position>> mapsByAnnotationModel= new HashMap<>(); for (Match match : matches) { int offset= match.getOffset(); int length= match.getLength(); if (offset >= 0 && length >= 0) { try { Position position= createPosition(match); if (position != null) { Map<Annotation, Position> map= getMap(mapsByAnnotationModel, match); if (map != null) { Annotation annotation= match.isFiltered() ? new Annotation(SearchPlugin.FILTERED_SEARCH_ANNOTATION_TYPE, true, null) : new Annotation(SearchPlugin.SEARCH_ANNOTATION_TYPE, true, null); 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)); } } } for (Entry<IAnnotationModel, HashMap<Annotation, Position>> entry : mapsByAnnotationModel.entrySet()) { addAnnotations(entry.getKey(), entry.getValue()); } }
private boolean updateFilterState(Match match) { MatchFilter[] matchFilters= getActiveMatchFilters(); if (matchFilters == null) { return false; // do nothing, no change } boolean oldState= match.isFiltered(); for (int i= 0; i < matchFilters.length; i++) { if (matchFilters[i].filters(match)) { match.setFiltered(true); return !oldState; } } match.setFiltered(false); return oldState; }
private boolean updateFilterState(Match match) { MatchFilter[] matchFilters= getActiveMatchFilters(); if (matchFilters == null) { return false; // do nothing, no change } boolean oldState= match.isFiltered(); for (MatchFilter matchFilter : matchFilters) { if (matchFilter.filters(match)) { match.setFiltered(true); return !oldState; } } match.setFiltered(false); return oldState; }
private boolean updateFilterState(Match match) { MatchFilter[] matchFilters = getActiveMatchFilters(); if (matchFilters == null) { return false; // do nothing, no change } boolean oldState = match.isFiltered(); for (int i = 0; i < matchFilters.length; i++) { if (matchFilters[i].filters(match)) { match.setFiltered(true); return !oldState; } } match.setFiltered(false); return oldState; }
if (matches[i].isFiltered()) matches[i]= null; else
if (matches[i].isFiltered()) matches[i]= null; else
/** * Returns the number of matches that are currently displayed for the given * element. If {@link AbstractTextSearchResult#getActiveMatchFilters()} is not null, only matches * are returned that are not filtered by the match filters. * Any action operating on the visible matches in the * search result page should use this method to get the match count for a * search result (instead of asking the search result directly). * * @param element * The element to get the matches for * @return The number of matches displayed for the given element. If the * current input of this page is <code>null</code>, 0 is * returned * @see AbstractTextSearchResult#getMatchCount(Object) */ public int getDisplayedMatchCount(Object element) { AbstractTextSearchResult result= getInput(); if (result == null) return 0; if (result.getActiveMatchFilters() == null) // default behaviour: filter state not used, all matches shown return result.getMatchCount(element); int count= 0; Match[] matches= result.getMatches(element); for (int i= 0; i < matches.length; i++) { if (!matches[i].isFiltered()) count++; } return count; }
/** * Returns the number of matches that are currently displayed for the given * element. If {@link AbstractTextSearchResult#getActiveMatchFilters()} is not null, only matches * are returned that are not filtered by the match filters. * Any action operating on the visible matches in the * search result page should use this method to get the match count for a * search result (instead of asking the search result directly). * * @param element * The element to get the matches for * @return The number of matches displayed for the given element. If the * current input of this page is <code>null</code>, 0 is * returned * @see AbstractTextSearchResult#getMatchCount(Object) */ public int getDisplayedMatchCount(Object element) { AbstractTextSearchResult result= getInput(); if (result == null) return 0; if (result.getActiveMatchFilters() == null) // default behaviour: filter state not used, all matches shown return result.getMatchCount(element); int count= 0; Match[] matches= result.getMatches(element); for (int i= 0; i < matches.length; i++) { if (!matches[i].isFiltered()) count++; } return count; }
private IMarker createMarker(Match match) throws CoreException { Position position= InternalSearchUI.getInstance().getPositionTracker().getCurrentPosition(match); if (position == null) { if (match.getOffset() < 0 || match.getLength() < 0) return null; position= new Position(match.getOffset(), match.getLength()); } else { // need to clone position, can't have it twice in a document. position= new Position(position.getOffset(), position.getLength()); } IMarker marker= match.isFiltered() ? fFile.createMarker(SearchPlugin.FILTERED_SEARCH_MARKER) : fFile.createMarker(NewSearchUI.SEARCH_MARKER); HashMap<String, Integer> attributes= new HashMap<>(4); if (match.getBaseUnit() == Match.UNIT_CHARACTER) { attributes.put(IMarker.CHAR_START, Integer.valueOf(position.getOffset())); attributes.put(IMarker.CHAR_END, Integer.valueOf(position.getOffset()+position.getLength())); } else { attributes.put(IMarker.LINE_NUMBER, Integer.valueOf(position.getOffset())); } marker.setAttributes(attributes); return marker; }
private IMarker createMarker(Match match) throws CoreException { Position position= InternalSearchUI.getInstance().getPositionTracker().getCurrentPosition(match); if (position == null) { if (match.getOffset() < 0 || match.getLength() < 0) return null; position= new Position(match.getOffset(), match.getLength()); } else { // need to clone position, can't have it twice in a document. position= new Position(position.getOffset(), position.getLength()); } IMarker marker= match.isFiltered() ? fFile.createMarker(SearchPlugin.FILTERED_SEARCH_MARKER) : fFile.createMarker(NewSearchUI.SEARCH_MARKER); HashMap attributes= new HashMap(4); if (match.getBaseUnit() == Match.UNIT_CHARACTER) { attributes.put(IMarker.CHAR_START, new Integer(position.getOffset())); attributes.put(IMarker.CHAR_END, new Integer(position.getOffset()+position.getLength())); } else { attributes.put(IMarker.LINE_NUMBER, new Integer(position.getOffset())); } marker.setAttributes(attributes); return marker; }