package org.ajax4jsf.bean;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.faces.event.ActionEvent;

import org.ajax4jsf.model.Column;
import org.richfaces.model.Ordering;

@SuppressWarnings("unchecked")
public class DataTableBean {

	private int rows = 20;

	private int column = 3;
	
	private int begin = 1;
	
	private int end = 10;

	private List model;

	private List columns;
	
	private Ordering ordering;
	
	public DataTableBean() {
		init();
	}
	
	public void init(ActionEvent event) {
		init();
	}
	
	public void reset(ActionEvent event) {
		rows = 20;
		column = 3;
		begin = 1;
		end = 10;
		init();
	}
	
	public String getDate() {
		return new Date().toLocaleString();
	}

	private void init() {
		model = new ArrayList();
		for (int i = 0; i < rows; i++) {
			String [] m = new String[column];
			for (int j = 0; j < column; j++) {
				m[j] = String.valueOf(i + j);
			}
			model.add(m);
		}
		
		columns = new ArrayList();
		for (int i = 0; i < column; i++) {
			columns.add(new Column("header","footer", i));
		}
	}

	/**
	 * @return the columns
	 */
	public int getColumn() {
		return column;
	}

	/**
	 * @param columns
	 *            the columns to set
	 */
	public void setColumn(int column) {
		this.column = column;
	}

	/**
	 * @return the rows
	 */
	public int getRows() {
		return rows;
	}

	/**
	 * @param rows
	 *            the rows to set
	 */
	public void setRows(int rows) {
		this.rows = rows;
	}

	/**
	 * @return the model
	 */
	public List getModel() {
		return model;
	}

	/**
	 * @param model
	 *            the model to set
	 */
	public void setModel(List model) {
		this.model = model;
	}

	/**
	 * @return the columns
	 */
	public List getColumns() {
		return columns;
	}

	/**
	 * @param columns
	 *            the columns to set
	 */
	public void setColumns(List columns) {
		this.columns = columns;
	}

	/**
	 * @return the ordering
	 */
	public Ordering getOrdering() {
		return ordering;
	}

	/**
	 * @param ordering the ordering to set
	 */
	public void setOrdering(Ordering ordering) {
		this.ordering = ordering;
	}

	/**
	 * @return the begin
	 */
	public int getBegin() {
		return begin;
	}

	/**
	 * @param begin the begin to set
	 */
	public void setBegin(int begin) {
		this.begin = begin;
	}

	/**
	 * @return the end
	 */
	public int getEnd() {
		return end;
	}

	/**
	 * @param end the end to set
	 */
	public void setEnd(int end) {
		this.end = end;
	}

}
