@Override public void process() { // put all the edits together CompoundEdit edit = new CompoundEdit(); boolean removeAnnotation = removeMatched.isSelected(); Pattern pattern = caseInsensitive.isSelected() ? Pattern.compile(patternField.getText(), Pattern.CASE_INSENSITIVE) : Pattern.compile(patternField.getText()); BasicPatternMatcher<Note> matcher = new BasicPatternMatcher<Note>(Note.class, pattern); Annotation target = (Annotation) annotationComboBox.getSelectedItem(); List<Annotation> createdAnnotations = new ArrayList<Annotation>(); List<Annotation> removedAnnotations = new ArrayList<Annotation>(); for (AnnotatedEntity entity : getSelectionController().getSelection().getEntities()) { for (Annotation annotation : entity.getAnnotations()) { String matched = annotation.accept(matcher); if (!matched.isEmpty()) { if (target instanceof StringAnnotation) { createdAnnotations.add(((StringAnnotation) target).getInstance(matched)); if (removeAnnotation) { removedAnnotations.add(annotation); } } else if (target.getClass().equals(Charge.class)) { Charge charge = (Charge) target.newInstance(); charge.setValue(Double.parseDouble(matched)); createdAnnotations.add(charge); if (removeAnnotation) { removedAnnotations.add(annotation); } } } } edit.addEdit(new AddAnnotationEdit(entity, createdAnnotations)); for (Annotation a : removedAnnotations) { edit.addEdit(new RemoveAnnotationEdit(entity, a)); entity.removeAnnotation(a); } entity.addAnnotations(createdAnnotations); createdAnnotations.clear(); removedAnnotations.clear(); } // inform the compound edit that we've finished editing edit.end(); addEdit(edit); }
public Object getValue(AnnotatedEntity entity) { return entity.getName(); }
@Override public boolean handle(AnnotatedEntity entity, Annotation annotation) { entity.addAnnotation(annotation); return true; }