コード例 #1
0
  @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);
  }
コード例 #2
0
ファイル: NameAccessor.java プロジェクト: pcm32/mdk
 public Object getValue(AnnotatedEntity entity) {
   return entity.getName();
 }
コード例 #3
0
ファイル: AnnotationMapper.java プロジェクト: johnmay/mdk
 @Override
 public boolean handle(AnnotatedEntity entity, Annotation annotation) {
   entity.addAnnotation(annotation);
   return true;
 }