replaceAnnotations(toRemove.toArray(new Annotation[0]), toAdd, false);
/** * 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); }
/** * 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); }
replaceAnnotations(toRemove.toArray(new Annotation[0]), toAdd, false);