/*
 * ICESOFT COMMERCIAL SOURCE CODE LICENSE V 1.1
 *
 * The contents of this file are subject to the ICEsoft Commercial Source
 * Code License Agreement V1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of the
 * License at
 * http://www.icesoft.com/license/commercial-source-v1.1.html
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations under
 * the License.
 *
 * Copyright 2009-2015 ICEsoft Technologies Canada, Corp. All Rights Reserved.
 */
package com.icesoft.faces.application.showcase.view.bean.examples.component.dataTable;

import com.icesoft.faces.application.showcase.model.entity.Employee;
import com.icesoft.faces.application.showcase.model.service.EmployeeService;
import com.icesoft.faces.application.showcase.view.bean.BaseBean;

import java.util.List;

/**
 * <p>The class DataTableBase is the base implementation for all DataTable
 * related examples.  This class should be extended for any dataTable example
 * to insure that the example has easy access to common example data.</p>
 *
 * @since 1.7
 */
public class DataTableBase extends BaseBean {

    // mock service that retreives employee data
    protected EmployeeService employeeService;

    // internal list of retreived records.
    protected List<Employee> employees;

    protected void init() {
        // build employee list form employee service.
        employees = employeeService.getEmployees(50, true,
                Employee.DEPARTMENT_NAME_COLUMN);
    }

    /**
     * Gets list of employee records retrieved from service layer.
     *
     * @return list of employees from service layer
     */
    public List<Employee> getEmployees() {
        return employees;
    }

    /**
     * Sets the EmployeService reference.  Once the service has been set the
     * init method is called on this class to get the initial data for the
     * example.
     *
     * @param employeeService set the employeeService reference at which time
     *                        the init method is called on the class.
     */
    public void setEmployeeService(EmployeeService employeeService) {
        this.employeeService = employeeService;
        init();
    }
}