
package de.ivu.elect.presentation.staat;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;

import de.ivu.elect.business.staat.boundary.StaatenGruppeBoundaryCreate;
import de.ivu.elect.business.staat.boundary.StaatenGruppeFactory;
import de.ivu.elect.business.staat.entity.StaatenGruppe;
import de.ivu.elect.business.staat.entity.StaatenGruppeMeta;
import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.business.security.UseCaseSecure;
import de.ivu.elect.presentation.View;
import de.ivu.elect.jee.presentation.redirect.Redirect;

@Named(AbstractStaatenGruppeCreateNoScopeView.COMPONENT_NAME)
@View(viewId = AbstractStaatenGruppeCreateNoScopeView.VIEW_ID, useCase = UseCasePermission.STAATEN_GRUPPE_CREATE)
public abstract class AbstractStaatenGruppeCreateNoScopeView extends de.ivu.elect.presentation.AbstractElectCreateView<StaatenGruppe> {

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "staatenGruppeCreateView";

  public static final String VIEW_ID = "/staat/staaten-gruppe-create.xhtml";

  public static final String PARENT_VIEW_ID = "/staat/staaten-gruppe-search.xhtml";

  @Inject
  protected transient StaatenGruppeBoundaryCreate create;

  protected StaatenGruppe entity;

  @Inject
  protected transient StaatenGruppeMeta entityMeta;

  
  @Inject
  protected transient StaatenGruppeFactory factory;

  public AbstractStaatenGruppeCreateNoScopeView() {
    super();
  }

  @PostConstruct
  public void init() {
    setEntity(factory.create());
  }

  

  public StaatenGruppe getEntity() {
    return entity;
  }

  protected void setEntity(StaatenGruppe entity) {
    this.entity = entity;
  }

  @Redirect
  @UseCaseSecure(UseCasePermission.STAATEN_GRUPPE_CREATE)
  public String save() {
    callSave(getEntity());

    addMessageSaveSuccess(getEntity());

    resetStateAfterAction();

    return goBack(getParentViewId());
  }

  protected void callSave(StaatenGruppe entity) {
    create.save(entity);
  }

  protected void addMessageSaveSuccess(StaatenGruppe entity) {
    addInfoMessage("entity.create.action.save.success.message", entityMeta.getEinzahlMessage());
  }

  public boolean isBtnSaveRendered() {
    return hasPermission(UseCasePermission.STAATEN_GRUPPE_CREATE);
  }

  @Redirect
  public String reset() {
    resetStateAfterAction();

    init();

    return getViewId();
  }

  public boolean isBtnResetRendered() {
    return true;
  }

  @Redirect
  public String cancel() {
    resetStateAfterAction();

    return goBack(getParentViewId());
  }

  public boolean isBtnCancelRendered() {
    return true;
  }

  protected String getViewId() {
    return VIEW_ID;
  }

  protected String getParentViewId() {
    return PARENT_VIEW_ID;
  }

  protected void resetStateAfterAction() {
    // Do nothing.
  }
}
