private void addAnnotations(
      final DataObject dataObject, final List<AnnotationMetaModel> annotationMetaModelList) {
    for (AnnotationMetaModel annotationMetaModel : annotationMetaModelList) {
      final String name = annotationMetaModel.name;
      final Map<String, String> values = annotationMetaModel.values;

      Annotation annotation;
      String key = DroolsDomainAnnotations.VALUE_PARAM;
      String value = "";

      if (values.size() > 0) {
        key = values.keySet().iterator().next();
        value = values.values().iterator().next();
      }

      if ("Role".equals(name)) {
        annotation =
            new AnnotationImpl(annotationDefinitions.get(DroolsDomainAnnotations.ROLE_ANNOTATION));
        annotation.setValue(key, value);
        dataObject.addAnnotation(annotation);
      } else if ("Position".equals(name)) {
        annotation =
            new AnnotationImpl(
                annotationDefinitions.get(DroolsDomainAnnotations.POSITION_ANNOTATION));
        annotation.setValue(key, value);
        dataObject.addAnnotation(annotation);
      } else if ("Equals".equals(name)) {
        annotation =
            new AnnotationImpl(annotationDefinitions.get(DroolsDomainAnnotations.KEY_ANNOTATION));
        annotation.setValue(key, value);
        dataObject.addAnnotation(annotation);
      }
    }
  }
  public String resolveAnnotationType(Annotation annotation) {
    StringBuffer type = new StringBuffer();
    AnnotationDefinition annotationDefinition = annotation.getAnnotationDefinition();

    if (annotationDefinition == null) {
      logger.warn("Annotation definition for annotation: " + annotation + " is not defined.");
      return type.toString();
    }

    if (annotationDefinition.isMarker()) {
      return type.toString();
    }

    // finally we can process annotation members.
    Object memberValue;
    int memberCount = 0;
    for (AnnotationMemberDefinition memberDefinition :
        annotationDefinition.getAnnotationMembers()) {
      if ((memberValue = annotation.getValue(memberDefinition.getName())) != null) {
        // a value has been set for this member.
        if (memberCount == 0) type.append("(");
        if (memberCount > 0) type.append(", ");
        type.append(resolveMemberType(memberDefinition, memberValue));
        memberCount++;
      }
    }
    if (memberCount > 0) type.append(")");

    return type.toString();
  }
 @Override
 public void loadAnnotations(
     List<Annotation> annotations, Map<String, AnnotationSource> annotationSources) {
   if (annotations != null) {
     for (Annotation annotation : annotations) {
       createAnnotationAccordionGroup(
           annotation,
           annotationSources != null ? annotationSources.get(annotation.getClassName()) : null);
     }
   }
 }
  private void createAnnotationAccordionGroup(
      final Annotation annotation, final AnnotationSource annotationSource) {

    final Panel container = new Panel();
    final PanelHeader header = new PanelHeader();
    final PanelCollapse collapse = new PanelCollapse();
    final PanelBody body = new PanelBody();

    container.add(header);
    collapse.add(body);
    container.add(collapse);

    final Button remove = new Button();
    remove.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(final ClickEvent clickEvent) {
            presenter.onDeleteAnnotation(annotation);
          }
        });
    remove.setPull(Pull.RIGHT);
    remove.setIcon(IconType.TRASH);
    remove.setType(ButtonType.DANGER);
    remove.setSize(ButtonSize.SMALL);
    remove.getElement().getStyle().setMarginTop(-4, Style.Unit.PX);
    header.add(remove);

    final Heading heading = new Heading(HeadingSize.H4);
    final Anchor anchor = new Anchor();
    anchor.setText(accordionHeading(annotation));
    anchor.setDataToggle(Toggle.COLLAPSE);
    anchor.setDataParent(accordionsContainer.getId());
    anchor.setDataTargetWidget(collapse);
    anchor.addStyleName("collapsed");
    heading.add(anchor);
    header.add(heading);

    accordionsContainer.add(container);

    if (annotation.getAnnotationDefinition() != null
        && annotation.getAnnotationDefinition().getValuePairs() != null) {
      for (AnnotationValuePairDefinition valuePairDefinition :
          annotation.getAnnotationDefinition().getValuePairs()) {
        body.add(createValuePairItem(annotation, valuePairDefinition, annotationSource));
      }
    }
  }
  private String getValuePairStringValue(
      Annotation annotation,
      AnnotationValuePairDefinition valuePairDefinition,
      AnnotationSource annotationSource) {

    Object value = annotation.getValue(valuePairDefinition.getName());
    String strValue;

    if (value == null) {
      strValue = Constants.INSTANCE.advanced_domain_annotation_list_editor_message_value_not_set();
    } else {
      strValue =
          annotationSource != null
              ? annotationSource.getValuePairSource(valuePairDefinition.getName())
              : null;
      if (strValue == null) {
        strValue =
            Constants.INSTANCE
                .advanced_domain_annotation_list_editor_message_source_code_not_available();
      }
    }

    return strValue;
  }
 private String accordionHeading(final Annotation annotation) {
   return "@" + annotation.getClassName();
 }