private Widget createValuePairItem(
      final Annotation annotation,
      final AnnotationValuePairDefinition valuePairDefinition,
      final AnnotationSource annotationSource) {
    final Row valuePairRow = new Row();
    final FormGroup formGroup = new FormGroup();
    valuePairRow.add(formGroup);

    final FormLabel formLabel = new FormLabel();
    formLabel.addStyleName(ColumnSize.MD_3.getCssName());
    formLabel.setText(valuePairDefinition.getName());
    formGroup.add(formLabel);

    final Column column = new Column(ColumnSize.MD_9);
    formGroup.add(column);
    final TextBox content = new TextBox();
    column.add(content);
    final String valuePairString =
        getValuePairStringValue(annotation, valuePairDefinition, annotationSource);
    content.setText(valuePairString);
    content.setReadOnly(true);
    content.setTitle(valuePairString);

    final Button editButton =
        new Button(
            Constants.INSTANCE.advanced_domain_annotation_list_editor_action_edit(),
            new ClickHandler() {
              @Override
              public void onClick(ClickEvent event) {
                presenter.onEditValuePair(annotation, valuePairDefinition.getName());
              }
            });
    editButton.setEnabled(!readonly);
    editButton.setIcon(IconType.EDIT);

    final Button clearButton =
        new Button(
            Constants.INSTANCE.advanced_domain_annotation_list_editor_action_clear(),
            new ClickHandler() {
              @Override
              public void onClick(ClickEvent event) {
                presenter.onClearValuePair(annotation, valuePairDefinition.getName());
              }
            });
    clearButton.setEnabled(!readonly);
    clearButton.setIcon(IconType.ERASER);

    final FormGroup formGroupButton = new FormGroup();
    formGroupButton.add(editButton);
    formGroupButton.add(clearButton);
    final Column columnButton = new Column(ColumnSize.MD_9);
    columnButton.setOffset(ColumnOffset.MD_3);
    columnButton.add(formGroupButton);
    valuePairRow.add(columnButton);

    return valuePairRow;
  }
Ejemplo n.º 2
0
  public static String encodeEnumValue(
      AnnotationValuePairDefinition valuePairDefinition, Object value) {
    if (value == null) return null;

    StringBuilder encodedValue = new StringBuilder();
    encodedValue.append(NamingUtils.normalizeClassName(valuePairDefinition.getClassName()));
    encodedValue.append(".");
    encodedValue.append(value.toString());

    return encodedValue.toString();
  }
Ejemplo n.º 3
0
  public static String encodePrimitiveValue(
      AnnotationValuePairDefinition valuePairDefinition, Object value) {

    if (value == null) return null;

    StringBuilder encodedValue = new StringBuilder();

    if (NamingUtils.isCharId(valuePairDefinition.getClassName())
        || Character.class.getName().equals(valuePairDefinition.getClassName())) {
      String strValue = value.toString();
      if (StringEscapeUtils.isSingleQuoted(strValue)) {
        encodedValue.append(strValue);
      } else {
        encodedValue.append("'");
        encodedValue.append(value.toString());
        encodedValue.append("'");
      }
    } else if (NamingUtils.isLongId(valuePairDefinition.getClassName())
        || Long.class.getName().equals(valuePairDefinition.getClassName())) {
      encodedValue.append(value.toString());
      encodedValue.append("L");
    } else if (NamingUtils.isFloatId(valuePairDefinition.getClassName())
        || Float.class.getName().equals(valuePairDefinition.getClassName())) {
      encodedValue.append(value.toString());
      encodedValue.append("f");
    } else if (NamingUtils.isDoubleId(valuePairDefinition.getClassName())
        || Double.class.getName().equals(valuePairDefinition.getClassName())) {
      encodedValue.append(value.toString());
      encodedValue.append("d");
    } else if (NamingUtils.isByteId(valuePairDefinition.getClassName())
        || Byte.class.getName().equals(valuePairDefinition.getClassName())) {
      encodedValue.append("(byte)");
      encodedValue.append(value.toString());
    } else {
      encodedValue.append(value.toString());
    }

    return encodedValue.toString();
  }
  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;
  }