
package de.ivu.elect.presentation.wahlvorschlag;

import java.util.Collection;
import java.util.List;

import javax.faces.convert.Converter;
import javax.faces.validator.Validator;

import de.ivu.elect.business.gruppe.entity.Gruppe;
import de.ivu.elect.jee.presentation.dynamicform.AbstractEnumProperty;
import de.ivu.elect.jee.presentation.dynamicform.Property;
import de.ivu.elect.jee.presentation.dynamicform.PropertyType;
import de.ivu.elect.presentation.wahlvorschlag.form.WahlvorschlagGruppeFinderProperty;

public abstract class AbstractAutoUpdateWahlvorschlagEnumProperty<E extends Enum<E>> extends AbstractEnumProperty<E> {

  private final AbstractEnumProperty<E> property;

  private final WahlvorschlagGruppeFinderProperty wahlvorschlagGruppeFinderProperty;

  public AbstractAutoUpdateWahlvorschlagEnumProperty(AbstractEnumProperty<E> property, WahlvorschlagGruppeFinderProperty wahlvorschlagGruppeFinderProperty) {
    super();

    this.property = property;

    this.wahlvorschlagGruppeFinderProperty = wahlvorschlagGruppeFinderProperty;
  }

  @Override
  public void onObservedPropertyValueChanged(Property observedProperty) {
    setValue(getValueAusGruppe(wahlvorschlagGruppeFinderProperty.getGruppe()));
  }

  protected abstract E getValueAusGruppe(Gruppe gruppe);

  @Override
  public boolean isRequired() {
    return property.isRequired();
  }

  @Override
  public String getItemLabel(E value) {
    return property.getItemLabel(value);
  }

  @Override
  public E getDefaultValue() {
    return property.getDefaultValue();
  }

  @Override
  public E getValue() {
    return property.getValue();
  }

  @Override
  public void setValue(E value) {
    property.setValue(value);
  }

  @Override
  public List<E> getValues() {
    return property.getValues();
  }

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

  @Override
  public boolean hasNoSelectionItem() {
    return property.hasNoSelectionItem();
  }

  @Override
  public Converter getDefaultConverter() {
    return property.getDefaultConverter();
  }

  @Override
  public Converter getConverter() {
    return property.getConverter();
  }

  @Override
  public void setConverter(Converter converter) {
    property.setConverter(converter);
  }

  @Override
  public String getNoSelectionLabel() {
    return property.getNoSelectionLabel();
  }

  @Override
  public PropertyType getType() {
    return property.getType();
  }

  @Override
  public void setType(PropertyType type) {
    property.setType(type);
  }

  @Override
  public String getDefaultLabel() {
    return property.getDefaultLabel();
  }

  @Override
  public String getLabel() {
    return property.getLabel();
  }

  @Override
  public void setLabel(String label) {
    property.setLabel(label);
  }

  @Override
  public boolean getDefaultRequired() {
    return property.getDefaultRequired();
  }

  @Override
  public void setRequired(boolean required) {
    property.setRequired(required);
  }

  @Override
  public int hashCode() {
    return property.hashCode();
  }

  @Override
  public boolean equals(Object obj) {
    return obj == this;
  }

  @Override
  public boolean isReadonly() {
    return property.isReadonly();
  }

  @Override
  public void setReadonly(boolean readonly) {
    property.setReadonly(readonly);
  }

  @Override
  public String getDefaultTooltip() {
    return property.getDefaultTooltip();
  }

  @Override
  public String getTooltip() {
    return property.getTooltip();
  }

  @Override
  public void setTooltip(String tooltip) {
    property.setTooltip(tooltip);
  }

  @Override
  public Collection<Validator> getValidators() {
    return property.getValidators();
  }
}
