/** * Sets the positions that should be highlighted as the target positions, i.e. * as the positions that can be jumped to in a linked set up. * * @param positions the new target positions, or <code>null</code> if no target positions are to be set * @throws BadLocationException in case any of the given positions is invalid */ private void setTargetPositions(List<Position> positions) throws BadLocationException { if (!fMarkTargets) return; // remove all positions which are already there // Algorithm: toRemove contains all mappings at first, but all that are in // positions get removed -> toRemove contains the difference set of previous - new // toAdd are the new positions, which don't exist in previous = new - previous List<Annotation> toRemove= new ArrayList<>(fTargetAnnotations.values()); Map<Annotation, Position> toAdd= new HashMap<>(); if (positions != null) { for (Position p : positions) { if (fTargetAnnotations.containsKey(p)) { toRemove.remove(fTargetAnnotations.get(p)); } else { Annotation a= new Annotation(TARGET_ANNOTATION_TYPE, false, ""); //$NON-NLS-1$ toAdd.put(a, p); fTargetAnnotations.put(p, a); } } } fTargetAnnotations.values().removeAll(toRemove); replaceAnnotations(toRemove.toArray(new Annotation[0]), toAdd, false); }
toRemove.remove(fTargetAnnotations.get(p)); } else { Annotation a= new Annotation(TARGET_ANNOTATION_TYPE, false, ""); //$NON-NLS-1$ toAdd.put(a, p); fTargetAnnotations.put(p, a);
toRemove.remove(fGroupAnnotations.get(p)); } else { Annotation a= new Annotation(SLAVE_ANNOTATION_TYPE, false, ""); //$NON-NLS-1$ toAdd.put(a, p); fGroupAnnotations.put(p, a);
/** * Sets the positions that should be highlighted as the slave positions, i.e. * as the positions that are linked to the focus position. * * @param positions the new slave positions, or <code>null</code> if no slave positions are to be set * @throws BadLocationException in case any of the given positions is invalid */ private void setGroupPositions(List<Position> positions) throws BadLocationException { if (!fMarkSlaves) return; // remove all positions which are already there // Algorithm: toRemove contains all mappings at first, but all that are in // positions get removed -> toRemove contains the difference set of previous - new // toAdd are the new positions, which don't exist in previous = new - previous List<Annotation> toRemove= new ArrayList<>(fGroupAnnotations.values()); Map<Annotation, Position> toAdd= new HashMap<>(); if (positions != null) { for (Position p : positions) { if (fGroupAnnotations.containsKey(p)) { toRemove.remove(fGroupAnnotations.get(p)); } else { Annotation a= new Annotation(SLAVE_ANNOTATION_TYPE, false, ""); //$NON-NLS-1$ toAdd.put(a, p); fGroupAnnotations.put(p, a); } } } fGroupAnnotations.values().removeAll(toRemove); replaceAnnotations(toRemove.toArray(new Annotation[0]), toAdd, false); }
private static int computeLayer(String annotationType, AnnotationPreferenceLookup lookup) { Annotation annotation= new Annotation(annotationType, false, null); AnnotationPreference preference= lookup.getAnnotationPreference(annotation); if (preference != null) return preference.getPresentationLayer() + 1; else return IAnnotationAccessExtension.DEFAULT_LAYER + 1; }
private static int computeLayer(String annotationType, AnnotationPreferenceLookup lookup) { Annotation annotation= new Annotation(annotationType, false, null); AnnotationPreference preference= lookup.getAnnotationPreference(annotation); if (preference != null) return preference.getPresentationLayer() + 1; else return IAnnotationAccessExtension.DEFAULT_LAYER + 1; }
private static int computeLayer(String annotationType, AnnotationPreferenceLookup lookup) { Annotation annotation= new Annotation(annotationType, false, null); AnnotationPreference preference= lookup.getAnnotationPreference(annotation); if (preference != null) return preference.getPresentationLayer() + 1; else return IAnnotationAccessExtension.DEFAULT_LAYER + 1; }
@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()); } }
protected void addOccurrenceAnnotation(String type, IDocument document, ITextRegion textRegion, Map<Annotation, Position> annotationMap) { try { if (textRegion != null && textRegion.getLength() > 0) { Annotation annotation = new Annotation(type, false, document.get(textRegion.getOffset(), textRegion.getLength())); annotationMap.put(annotation, new Position(textRegion.getOffset(), textRegion.getLength())); } } catch (BadLocationException e) { LOG.error("Error creating occurrence annotation", e); } }
/** * Sets the position that should be highlighted as the exit position, i.e. * as the position whose changes are propagated to all its linked positions * by the linked environment. * * @param position the new exit position, or <code>null</code> if no focus is set. * @throws BadLocationException in case <code>position</code> is invalid */ private void setExitPosition(Position position) throws BadLocationException { if (fMarkExitTarget && getPosition(fExitAnnotation) != position) { removeAnnotation(fExitAnnotation, false); if (position != null) { fExitAnnotation= new Annotation(EXIT_ANNOTATION_TYPE, false, ""); //$NON-NLS-1$ addAnnotation(fExitAnnotation, position, false); } else fExitAnnotation= null; } }
/** * Sets the position that should be highlighted as the exit position, i.e. * as the position whose changes are propagated to all its linked positions * by the linked environment. * * @param position the new exit position, or <code>null</code> if no focus is set. * @throws BadLocationException in case <code>position</code> is invalid */ private void setExitPosition(Position position) throws BadLocationException { if (fMarkExitTarget && getPosition(fExitAnnotation) != position) { removeAnnotation(fExitAnnotation, false); if (position != null) { fExitAnnotation= new Annotation(EXIT_ANNOTATION_TYPE, false, ""); //$NON-NLS-1$ addAnnotation(fExitAnnotation, position, false); } else fExitAnnotation= null; } }
/** * Sets the position that should be highlighted as the focus position, i.e. * as the position whose changes are propagated to all its linked positions * by the linked environment. * * @param position the new focus position, or <code>null</code> if no focus is set. * @throws BadLocationException if <code>position</code> is invalid */ private void setFocusPosition(Position position) throws BadLocationException { if (fMarkFocus && getPosition(fFocusAnnotation) != position) { removeAnnotation(fFocusAnnotation, false); if (position != null) { fFocusAnnotation= new Annotation(FOCUS_ANNOTATION_TYPE, false, ""); //$NON-NLS-1$ addAnnotation(fFocusAnnotation, position, false); } else fFocusAnnotation= null; } }
/** * Sets the position that should be highlighted as the focus position, i.e. * as the position whose changes are propagated to all its linked positions * by the linked environment. * * @param position the new focus position, or <code>null</code> if no focus is set. * @throws BadLocationException if <code>position</code> is invalid */ private void setFocusPosition(Position position) throws BadLocationException { if (fMarkFocus && getPosition(fFocusAnnotation) != position) { removeAnnotation(fFocusAnnotation, false); if (position != null) { fFocusAnnotation= new Annotation(FOCUS_ANNOTATION_TYPE, false, ""); //$NON-NLS-1$ addAnnotation(fFocusAnnotation, position, false); } else fFocusAnnotation= null; } }
String annotationType= (location.getFlags() == IOccurrencesFinder.F_WRITE_OCCURRENCE) ? "org.eclipse.jdt.ui.occurrences.write" : "org.eclipse.jdt.ui.occurrences"; //$NON-NLS-1$ //$NON-NLS-2$ annotationMap.put(new Annotation(annotationType, false, description), position);
String annotationType= (location.getFlags() == IOccurrencesFinder.F_WRITE_OCCURRENCE) ? "org.eclipse.jdt.ui.occurrences.write" : "org.eclipse.jdt.ui.occurrences"; //$NON-NLS-1$ //$NON-NLS-2$ annotationMap.put(new Annotation(annotationType, false, description), position);
public void highlightElement(int id) { if (myAnnotations != null && !myAnnotations.isEmpty()) { removeAnnotations(myAnnotations.keySet()); } RutaSelectionParser parser = new RutaSelectionParser(); ISourceModule unit = (ISourceModule) getInputModelElement(); ModuleDeclaration parsed = parser.parse(unit); RutaRuleIdVisitor visitor = new RutaRuleIdVisitor(id); try { parsed.traverse(visitor); } catch (Exception e) { } RutaRule rule = visitor.getResult(); myAnnotations = new HashMap<Annotation, Position>(); if (rule != null) { Annotation annotation = new Annotation(SearchPlugin.SEARCH_ANNOTATION_TYPE, true, null); int sourceStart = rule.sourceStart(); int sourceEnd = rule.sourceEnd(); Position position = new Position(sourceStart, sourceEnd - sourceStart); getSourceViewer().revealRange(sourceStart, sourceEnd - sourceStart); myAnnotations.put(annotation, position); } addAnnotations(myAnnotations); }
annotationMap.put(new Annotation("org.eclipse.jdt.ui.occurrences", false, message), //$NON-NLS-1$ position);