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

import javax.faces.convert.BooleanConverter;
import javax.faces.convert.Converter;

public abstract class AbstractBooleanProperty extends AbstractProperty {

  protected AbstractBooleanProperty() {
    super();

    // NOTE ELECT-1204.
    setRequired(false);
  }

  @Override
  protected boolean mustBeAccessableOnPageLoadByValue() {
    if (super.mustBeAccessableOnPageLoadByValue()) {
      return true;
    }

    return notAllEqual(getDefaultValue(), getValue());
  }

  @Override
  public Converter getDefaultConverter() {
    return new BooleanConverter();
  }

  @Override
  public PropertyType getDefaultType() {
    return PropertyType.SELECT_BOOLEAN_CHECKBOX;
  }

  @Override
  protected boolean hasDefaultValue() {
    return notNullOrBlank(getDefaultValue());
  }

  public Boolean getDefaultValue() {
    return null;
  }

  @Override
  public boolean hasValue() {
    return notNullOrBlank(getValue());
  }

  public abstract Boolean getValue();

  public abstract void setValue(Boolean value);
}
