
package de.ivu.elect.presentation.wahl;

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

import de.ivu.elect.business.wahl.entity.Wahl;
import de.ivu.elect.business.wahl.entity.WahlConstants;
import de.ivu.elect.jee.presentation.dynamicform.PropertyType;
import de.ivu.elect.presentation.AbstractEntitySelectManyProperty;

public class WahlSelectManyProperty extends AbstractEntitySelectManyProperty<Wahl> {

  private final List<Wahl> selection;

  public WahlSelectManyProperty(List<Wahl> values, List<Wahl> selection, PropertyType propertyType) {
    super(values, propertyType);

    this.selection = selection;
  }

  @Override
  public boolean getDefaultRequired() {
    return true;
  }

  @Override
  protected String getMessageKeyEntityMehrzahl() {
    return WahlConstants.MESSAGE_KEY_ENTITY_MEHRZAHL;
  }

  @Override
  protected Collection<Wahl> getValueAsCollection() {
    return selection;
  }

  @Override
  protected void setValueAsCollection(Collection<Wahl> collection) {
    selection.clear();
    selection.addAll(collection);
  }

  @Override
  public String getItemLabel(Wahl wahlart) {
    return wahlart.getName();
  }
}
