
package de.ivu.elect.presentation.gebietsbaum;

import java.io.Serializable;

import javax.inject.Inject;

import de.ivu.elect.business.gebietsbaum.boundary.GebietChangeEvent;
import de.ivu.elect.business.gebietsbaum.entity.Gebiet;
import de.ivu.elect.jee.exception.ElectCommonException;
import de.ivu.elect.jee.faces.Messages;
import de.ivu.elect.jee.presentation.dynamicform.FormBuilder;

/**
 * Notwendig, da Vererbung und @Named im JBoss 7 notwendig, in Wildfly 8 nicht erlaubt sind...
 */
public class GebietEditBuilder implements Serializable {

  private static final long serialVersionUID = 1L;

  @Inject
  private transient Messages messages;

  @Inject
  private transient GebietChangeEvent gebietChangeEvent;

  public GebietEditBuilder() {
    super();
  }

  public void onGebietChanged() {
    gebietChangeEvent.sendChangeEvent();
  }

  public String getSaveView(String view) {
    onGebietChanged();

    return view;
  }

  public String getCancelView(String view) {
    return view;
  }

  public void addProperties(FormBuilder formBuilder, Gebiet gebiet) {
  }

  public void preRenderView(Gebiet entity) {
  }

  protected void addInfoMessage(String msgKey, Object... params) {
    getMessages().addInfoMessage(msgKey, params);
  }

  protected void addWarningMessage(String msgKey, Object... params) {
    getMessages().addWarnMessage(msgKey, params);
  }

  protected void addErrorMessage(ElectCommonException ex) {
    addErrorMessage(ex.getMessageKey(), ex.getObjects());
  }

  protected void addErrorMessage(String msgKey, Object... params) {
    getMessages().addErrorMessage(msgKey, params);
  }

  public Messages getMessages() {
    return messages;
  }
}
