/*
 * ControlBackingBean.java
 *
 * Created on May 2, 2007, 2:00 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package control.test;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.faces.event.ActionEvent;

import org.ajax4jsf.component.html.HtmlAjaxRepeat;

/**
 *
 * @author Administrador
 */
public class ControlBackingBean {
    
    private List<Data> companyData;
    
    private List<Data> agencyData;
    
    private List<Data> selectData;
    
    private Data selectedCompany;
    
    private Data selectedAgency;
    
    private HtmlAjaxRepeat selectDataList = new HtmlAjaxRepeat();
    
    private Set<Integer> keys;
    
    /** Creates a new instance of ControlBackingBean */
    public ControlBackingBean() {
        setCompanyData(new ArrayList<Data>());
        getCompanyData().add(new Data("01","Company 01"));
        getCompanyData().add(new Data("02","Company 02"));
        getCompanyData().add(new Data("03","Company 03"));
        
        setSelectedCompany(getCompanyData().get(0));
        
        setAgencyData(new ArrayList<Data>());
        getAgencyData().add(new Data("04","Agency 01"));
        getAgencyData().add(new Data("05","Agency 02"));
        getAgencyData().add(new Data("06","Agency 03"));
        
        setSelectedAgency(getAgencyData().get(0));
    }
    
    public String commandAction() {
        System.out.println("<<< commandAction >>>");
        return null;
    }
    
    public void commandActionListener(ActionEvent event) {
        setSelectData(new ArrayList<Data>());
        setKeys(new HashSet<Integer>());
        String component = event.getComponent().getId();
        if (component.indexOf("company") >= 0) {
            setSelectData(this.companyData);
        } else {
            setSelectData(this.agencyData);
        }
        
        for (int i=0; i < getSelectData().size(); i++) {
            getKeys().add(i);
        }
    }
    
    public String selectAction() {
        System.out.println("<<< selectAction >>>");
        return null;
    }
    
    public void selectActionListener(ActionEvent event) {
        System.out.println("<<< selectActionListener >>>");
    }

    public List<Data> getCompanyData() {
        return companyData;
    }

    public void setCompanyData(List<Data> companyData) {
        this.companyData = companyData;
    }

    public List<Data> getAgencyData() {
        return agencyData;
    }

    public void setAgencyData(List<Data> agencyData) {
        this.agencyData = agencyData;
    }

    public Data getSelectedCompany() {
        return selectedCompany;
    }

    public void setSelectedCompany(Data selectedCompany) {
        this.selectedCompany = selectedCompany;
    }

    public Data getSelectedAgency() {
        return selectedAgency;
    }

    public void setSelectedAgency(Data selectedAgency) {
        this.selectedAgency = selectedAgency;
    }

    public HtmlAjaxRepeat getSelectDataList() {
        return selectDataList;
    }

    public void setSelectDataList(HtmlAjaxRepeat selectDataList) {
        this.selectDataList = selectDataList;
    }

    public Set<Integer> getKeys() {
        return keys;
    }

    public void setKeys(Set<Integer> keys) {
        this.keys = keys;
    }

    public List<Data> getSelectData() {
        return selectData;
    }

    public void setSelectData(List<Data> selectData) {
        this.selectData = selectData;
    }
    
}
