/*
 * DataScrollerBean.java		Date created: 29.09.2008
 * Last modified by: $Author$
 * $Revision$	$Date$
 */

package org.ajax4jsf.bean;

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

import javax.faces.event.ActionEvent;

/**
 * Bean class for dataScroller component testing
 * @author Andrey Markavtsov
 *
 */
@SuppressWarnings("unchecked")
public class DataScrollerBean {
	
	
	private List data;
	
	private Integer tableRows = 1;
	
	private Integer totalRows = 10;
	
	private Integer maxPages = 10;
	
	private Integer page;
	
	private String onpagechange = "EventQueue.fire('onpagechange')";
	
	private String reRender;
	

	public DataScrollerBean() {
		init();
	}
	
	public String maxPages() {
		maxPages = 5;
		return null;
	}
	
	public String onpagechange() {
		onpagechange = "return false;";
		return null;
	}
	
	public String pageVars() {
		reRender = "activePage, pagesCount";
		return null;
	}
	
	
	private void init() {
		data = new ArrayList();
		for (int i = 0; i < totalRows; i++) {
			String content = "Page " + (i / tableRows + 1);
			data.add(new Object [] {i + 1, content});
		}
	}
	
	public void reset() {
		tableRows = 1;
		totalRows = 10;
		maxPages = 10;
		page = null;
		data = null;
		onpagechange = "EventQueue.fire('onpagechange')";
	}
	
	public void apply(ActionEvent event) {
		init();
	}
	
	public String getTime() {
		return String.valueOf(new Date().getTime());
	}

	/**
	 * @return the data
	 */
	public List getData() {
		if (data == null) {
			init();
		}
		return data;
	}

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

	/**
	 * @return the tableRows
	 */
	public Integer getTableRows() {
		return tableRows;
	}

	/**
	 * @param tableRows the tableRows to set
	 */
	public void setTableRows(Integer tableRows) {
		this.tableRows = tableRows;
	}

	/**
	 * @return the totalRows
	 */
	public Integer getTotalRows() {
		return totalRows;
	}

	/**
	 * @param totalRows the totalRows to set
	 */
	public void setTotalRows(Integer totalRows) {
		this.totalRows = totalRows;
	}

	/**
	 * @return the maxPages
	 */
	public Integer getMaxPages() {
		return maxPages;
	}

	/**
	 * @param maxPages the maxPages to set
	 */
	public void setMaxPages(Integer maxPages) {
		this.maxPages = maxPages;
	}

	/**
	 * @return the page
	 */
	public Integer getPage() {
		return page;
	}

	/**
	 * @param page the page to set
	 */
	public void setPage(Integer page) {
		this.page = page;
	}

	/**
	 * @return the onpagechange
	 */
	public String getOnpagechange() {
		return onpagechange;
	}

	/**
	 * @param onpagechange the onpagechange to set
	 */
	public void setOnpagechange(String onpagechange) {
		this.onpagechange = onpagechange;
	}

	/**
	 * @return the reRender
	 */
	public String getReRender() {
		return reRender;
	}

	/**
	 * @param reRender the reRender to set
	 */
	public void setReRender(String reRender) {
		this.reRender = reRender;
	}

	
}
