
package de.ivu.elect.jee.presentation.dynamicform;

/**
 * Definiert die gültigen Werte eines <code>type</code>-Attributs in <code>/elect-base-war/src/main/webapp/WEB-INF/templates/dyna-form.xhtml</code>.
 */
public enum PropertyType {

  @Deprecated
  ELECT_5339,
  INPUT_CALENDAR,
  INPUT_CALENDAR_BETWEEN,
  INPUT_CALENDAR_TIME,
  INPUT_CALENDAR_TIME_BETWEEN,
  INPUT_CALENDAR_TIME_ONLY,
  INPUT_CALENDAR_TIME_ONLY_BETWEEN,
  INPUT_COLOR,
  INPUT_NUMBER,
  INPUT_MONEY,
  INPUT_PASSWORD,
  INPUT_TEXT,
  INPUT_MASK,
  INPUT_TEXTAREA,
  /**
   * @deprecated WASDE-896
   */
  @Deprecated
  INPUT_TEXT_TOKEN,
  PICK_LIST,
  SELECT_BOOLEAN_CHECKBOX,
  SELECT_ONE_MENU,
  SELECT_ONE_MENU_NO_SELECTION_ITEM,
  SELECT_ONE_RADIO,
  SELECT_MANY_CHECKBOX,
  SELECT_MANY_CHECKBOX_MENU,
  SEPARATOR,
  @Deprecated
  AUTO_COMPLETE_ENTITY,
  AUTO_COMPLETE,
  @Deprecated
  PLATZHALTER,
  @Deprecated // elect-technical-ckeditor einbinden, wenn verwendet
  CKEDITOR,
  IMAGE_READONLY {

    @Override
    protected String getDataTypeNameReadonly() {
      return super.getDataTypeName();
    }
  },
  INPUT_URL;

  public String getDataType(FormBuilderProperty property) {
    if (property.isReadonly()) {
      if (PLATZHALTER.equals(this)) {
        throw new UnsupportedOperationException("PropertyType für 'readonly' Property nicht definert [property =" + property.getProperty() + "]");
      }

      return getDataTypeNameReadonly();
    }

    return getDataTypeName();
  }

  protected String getDataTypeName() {
    return name().toLowerCase();
  }

  protected String getDataTypeNameReadonly() {
    return name().toLowerCase() + "_readonly";
  }
}
