/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.inbio.ara.germplasm;
import com.sun.rave.web.ui.appbase.AbstractPageBean;
import com.sun.webui.jsf.component.Label;
import com.sun.webui.jsf.model.Option;
import com.sun.webui.jsf.model.SingleSelectOptionsList;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import javax.faces.FacesException;
import org.inbio.ara.statistics.StatisticsSessionBean;
import org.inbio.ara.admin.ProfileSessionBean;
import org.inbio.ara.admin.PersonSessionBean;
import org.inbio.ara.admin.AdminGeographicLayersSessionBean;
import org.inbio.ara.taxonomy.TaxonomySessionBean;
import org.inbio.ara.inventory.GatheringDetailSessionBean;
import org.inbio.ara.inventory.SpecimenSessionBean;
import org.inbio.ara.gis.MapController;
import org.inbio.ara.taxonomy.SpeciesSessionBean;
import org.inbio.ara.inventory.GatheringSessionBean;
import org.inbio.ara.SessionManager;
import org.inbio.ara.inventory.IdentificationSessionBean;
import org.inbio.ara.reports.SnapshotSessionBean;
import org.inbio.ara.admin.CollectionSessionBean;
import org.inbio.ara.admin.AudienceSessionBean;
import org.inbio.ara.AraSessionBean;
import org.inbio.ara.dto.inventory.PersonDTO;
import org.inbio.ara.dto.inventory.SelectionListDTO;
import org.inbio.ara.dto.inventory.SelectionListEntity;
import org.inbio.ara.util.BundleHelper;
import org.inbio.ara.util.MessageBean;
import org.inbio.ara.util.ValidatorBean;
/**
* <p>Page bean that corresponds to a similarly named JSP page. This
* class contains component definitions (and initialization code) for
* all components that you have defined on this page, as well as
* lifecycle methods and event handlers where you may add behavior
* to respond to incoming events.</p>
*
* @version NewAccessionMovement.java
* @version Created on 11/03/2010, 03:18:20 PM
* @author dasolano
*/
public class NewAccessionMovement extends AbstractPageBean {
// <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
/**
* <p>Automatically managed component initialization. <strong>WARNING:</strong>
* This method is automatically generated, so any user-specified code inserted
* here is subject to being replaced.</p>
*/
private void _init() throws Exception {
}
// </editor-fold>
private SingleSelectOptionsList responsablePerson = new SingleSelectOptionsList();
private SingleSelectOptionsList accessionMovementType = new SingleSelectOptionsList();
private Label lbTitle = new Label();
/**
* <p>Construct a new Page bean instance.</p>
*/
public NewAccessionMovement() {
}
/**
* <p>Callback method that is called whenever a page is navigated to,
* either directly via a URL, or indirectly via page navigation.
* Customize this method to acquire resources that will be needed
* for event handlers and lifecycle methods, whether or not this
* page is performing post back processing.</p>
*
* <p>Note that, if the current request is a postback, the property
* values of the components do <strong>not</strong> represent any
* values submitted with this request. Instead, they represent the
* property values that were saved for this view when it was rendered.</p>
*/
@Override
public void init() {
// Perform initializations inherited from our superclass
super.init();
// Perform application initialization that must complete
// *before* managed components are initialized
// TODO - add your own initialiation code here
// <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
// Initialize automatically managed components
// *Note* - this logic should NOT be modified
try {
_init();
} catch (Exception e) {
log("NewAccessionMovement Initialization Failure", e);
throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
}
// </editor-fold>
// Perform application initialization that must complete
// *after* managed components are initialized
// TODO - add your own initialization code here
}
/**
* <p>Callback method that is called after the component tree has been
* restored, but before any event processing takes place. This method
* will <strong>only</strong> be called on a postback request that
* is processing a form submit. Customize this method to allocate
* resources that will be required in your event handlers.</p>
*/
@Override
public void preprocess() {
}
/**
* <p>Callback method that is called just before rendering takes place.
* This method will <strong>only</strong> be called for the page that
* will actually be rendered (and not, for example, on a page that
* handled a postback and then navigated to a different page). Customize
* this method to allocate resources that will be required for rendering
* this page.</p>
*/
@Override
public void prerender() {
if(getgermplasm$AccessionMovementSessionBean().
getAccessionDTO().getAccessionNumber() != null)
getLbTitle().setText(BundleHelper.getDefaultBundleValue("new_accession_movement", this.getMyLocale()) + " " +
getgermplasm$AccessionMovementSessionBean().getAccessionDTO().getAccessionNumber());
this.responsablePerson.setOptions(SetResponsibleDropDownData());
this.accessionMovementType.setOptions(getSelectionListDropDownData(
SelectionListEntity.ACCESSION_MOVEMENT_TYPE.getId()));
}
/**
* <p>Callback method that is called after rendering is completed for
* this request, if <code>init()</code> was called (regardless of whether
* or not this was the page that was actually rendered). Customize this
* method to release resources acquired in the <code>init()</code>,
* <code>preprocess()</code>, or <code>prerender()</code> methods (or
* acquired during execution of an event handler).</p>
*/
@Override
public void destroy() {
}
/**
* Obtener los datos del drop down de responsables
*/
public Option[] SetResponsibleDropDownData(){
List<PersonDTO> personDTOList = this.getgermplasm$AccessionMovementSessionBean().
getGermplasmFacadeRemote().getResponsablePersons();
ArrayList<Option> allOptions = new ArrayList<Option>();
Option[] allOptionsInArray;
Option option;
//Crear opcion titulo
option = new Option(null," -- "+BundleHelper.getDefaultBundleValue("drop_down_default",getMyLocale())+" --");
allOptions.add(option);
//Crear todas las opciones del drop down
for(PersonDTO perDTO : personDTOList){
option = new Option(perDTO.getPersonKey(), perDTO.getNaturalLongName().trim());
allOptions.add(option);
}
//Sets the elements in the SingleSelectedOptionList Object
allOptionsInArray = new Option[allOptions.size()];
return allOptions.toArray(allOptionsInArray);
}
/**
* Metodo para obtener los datos a mostrar en los drop downs de la
* ventana de generacion que pertenecen a listas de seleccion
* @param selectionListEntityId que es el id del enum de listas de seleccion
* @return
*/
public Option[] getSelectionListDropDownData(Long selectionListEntityId) {
//getAllSelectionListElementsByCollection
List<SelectionListDTO> DTOList = this.getgermplasm$AccessionMovementSessionBean().
getInventoryFacadeRemote().
getAllSelectionListElementsByCollection(selectionListEntityId, getAraSessionBean().getGlobalCollectionId());
/*List<SelectionListDTO> DTOList = this.getPassportSessionBean().
getGermplasmFacadeRemote().getElementsForSelectionList(selectionListEntityId);*/
ArrayList<Option> allOptions = new ArrayList<Option>();
Option[] allOptionsInArray;
Option option;
//Crear opcion titulo
option = new Option(null, " -- " + BundleHelper.getDefaultBundleValue("drop_down_default", getMyLocale()) + " --");
allOptions.add(option);
//Crear todas las opciones del drop down
for (SelectionListDTO slDTO : DTOList) {
option = new Option(slDTO.getValueId(), slDTO.getValueName());
allOptions.add(option);
}
allOptionsInArray = new Option[allOptions.size()];
return allOptions.toArray(allOptionsInArray);
}
public String saveAccessionMovement_button_action()
{
try
{
getgermplasm$AccessionMovementSessionBean().
getAccessionMovementDTO().setUserName(
getAraSessionBean().getGlobalUserName());
getgermplasm$AccessionMovementSessionBean().
getAccessionMovementDTO().setAccessionId(
getgermplasm$AccessionMovementSessionBean().
getAccessionDTO().getAccessionId());
getgermplasm$AccessionMovementSessionBean().
getGermplasmFacadeRemote().
saveAccessionMovement(
getgermplasm$AccessionMovementSessionBean().
getAccessionMovementDTO());
getgermplasm$AccessionMovementSessionBean().getAccessionDTO().
setCurrentWeigth(
getgermplasm$AccessionMovementSessionBean().getAccessionDTO().
getCurrentWeigth() - getgermplasm$AccessionMovementSessionBean().
getAccessionMovementDTO().getWeight());
//Refrescar la lista de accessiones y movimientos
this.getgermplasm$AccessionMovementSessionBean().getPagination().refreshList();
this.getgermplasm$AccessionSessionBean().getPagination().refreshList();
MessageBean.setSuccessMessageFromBundle("create_accession_movement_succces", this.getMyLocale());
}
catch(Exception e)
{
MessageBean.setErrorMessageFromBundle("error_not_enough_weight", this.getMyLocale());
}
return null;
}
/**
* @return the myLocale
*/
public Locale getMyLocale() {
return this.getAraSessionBean().getCurrentLocale();
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected StatisticsSessionBean getstatistics$StatisticsSessionBean() {
return (StatisticsSessionBean) getBean("statistics$StatisticsSessionBean");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected ProfileSessionBean getadmin$ProfileSessionBean() {
return (ProfileSessionBean) getBean("admin$ProfileSessionBean");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected PersonSessionBean getadmin$PersonSessionBean() {
return (PersonSessionBean) getBean("admin$PersonSessionBean");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected AdminGeographicLayersSessionBean getadmin$AdminGeographicLayersSessionBean() {
return (AdminGeographicLayersSessionBean) getBean("admin$AdminGeographicLayersSessionBean");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected TaxonomySessionBean gettaxonomy$TaxonomySessionBean() {
return (TaxonomySessionBean) getBean("taxonomy$TaxonomySessionBean");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected PassportListSessionBean getgermplasm$PassportListSessionBean() {
return (PassportListSessionBean) getBean("germplasm$PassportListSessionBean");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected GatheringDetailSessionBean getinventory$GatheringDetailSessionBean() {
return (GatheringDetailSessionBean) getBean("inventory$GatheringDetailSessionBean");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected SpecimenSessionBean getinventory$SpecimenSessionBean() {
return (SpecimenSessionBean) getBean("inventory$SpecimenSessionBean");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected MapController getgis$MapController() {
return (MapController) getBean("gis$MapController");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected SpeciesSessionBean gettaxonomy$SpeciesSessionBean() {
return (SpeciesSessionBean) getBean("taxonomy$SpeciesSessionBean");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected GatheringSessionBean getinventory$GatheringSessionBean() {
return (GatheringSessionBean) getBean("inventory$GatheringSessionBean");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected SessionManager getSessionManager() {
return (SessionManager) getBean("SessionManager");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected IdentificationSessionBean getinventory$IdentificationSessionBean() {
return (IdentificationSessionBean) getBean("inventory$IdentificationSessionBean");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected SnapshotSessionBean getreports$SnapshotSessionBean() {
return (SnapshotSessionBean) getBean("reports$SnapshotSessionBean");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected CollectionSessionBean getadmin$CollectionSessionBean() {
return (CollectionSessionBean) getBean("admin$CollectionSessionBean");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected AccessionMovementSessionBean getgermplasm$AccessionMovementSessionBean() {
return (AccessionMovementSessionBean) getBean("germplasm$AccessionMovementSessionBean");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected AccessionSessionBean getgermplasm$AccessionSessionBean() {
return (AccessionSessionBean) getBean("germplasm$AccessionSessionBean");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected AudienceSessionBean getadmin$AudienceSessionBean() {
return (AudienceSessionBean) getBean("admin$AudienceSessionBean");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected AraSessionBean getAraSessionBean() {
return (AraSessionBean) getBean("AraSessionBean");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected PassportSessionBean getgermplasm$PassportSessionBean() {
return (PassportSessionBean) getBean("germplasm$PassportSessionBean");
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected ValidatorBean getutil$ValidatorBean() {
return (ValidatorBean) getBean("util$ValidatorBean");
}
/**
* @return the responsablePerson
*/
public SingleSelectOptionsList getResponsablePerson() {
return responsablePerson;
}
/**
* @param responsablePerson the responsablePerson to set
*/
public void setResponsablePerson(SingleSelectOptionsList responsablePerson) {
this.responsablePerson = responsablePerson;
}
/**
* @return the accessionMovementType
*/
public SingleSelectOptionsList getAccessionMovementType() {
return accessionMovementType;
}
/**
* @param accessionMovementType the accessionMovementType to set
*/
public void setAccessionMovementType(SingleSelectOptionsList accessionMovementType) {
this.accessionMovementType = accessionMovementType;
}
/**
* @return the lbTitle
*/
public Label getLbTitle() {
return lbTitle;
}
/**
* @param lbTitle the lbTitle to set
*/
public void setLbTitle(Label lbTitle) {
this.lbTitle = lbTitle;
}
}