
package de.ivu.elect.presentation.exchange;

import java.io.Serializable;

import javax.enterprise.event.Observes;
import javax.enterprise.event.Reception;
import javax.inject.Named;

import org.apache.deltaspike.core.api.scope.ViewAccessScoped;

import de.ivu.elect.business.exchange.control.FileFormat;
import de.ivu.elect.business.wahl.boundary.WahlSelectChangeEvent;
import de.ivu.elect.business.wahl.boundary.WahlterminSelectChangeEvent;

@ViewAccessScoped
@Named(FileFormatViewSelect.COMPONENT_NAME)
public class FileFormatViewSelect implements Serializable {

  public static final String COMPONENT_NAME = "fileFormatViewSelect";

  private static final long serialVersionUID = 1L;

  private FileFormat selectedFileFormat;

  public FileFormatViewSelect() {
    super();
  }

  public boolean isSelected() {
    return getSelectedFileFormat() != null;
  }

  public FileFormat getSelectedFileFormat() {
    return selectedFileFormat;
  }

  public void setSelectedFileFormat(FileFormat selectedFileFormat) {
    this.selectedFileFormat = selectedFileFormat;
  }

  // ELECT-6400.
  public void onWahlSelectChangeEvent(@Observes(notifyObserver = Reception.IF_EXISTS) WahlSelectChangeEvent event) {
    reset();
  }

  // ELECT-6400.
  public void onWahlterminSelectChangeEvent(@Observes(notifyObserver = Reception.IF_EXISTS) WahlterminSelectChangeEvent event) {
    reset();
  }

  private void reset() {
    setSelectedFileFormat(null);
  }
}
