package dataScroller;

import java.util.ArrayList;

import javax.faces.event.ActionEvent;

import org.richfaces.component.html.HtmlDatascroller;
import org.richfaces.event.DataScrollerEvent;
import org.richfaces.model.Ordering;

import util.componentInfo.ComponentInfo;

public class DataScroller {
	
	private ArrayList dataTable;
	public Data tD;
	public String align;
	public String fastControls;
	public boolean render;
	public boolean renderIfSinglePage;
	public boolean limitToList; 
	public boolean renderTable;
	public int maxPages;
    private String action;
    private String actionListener;
    private String sortMode;
	private boolean selfSorted;
	private Ordering sortOrder;
	private String filterValue;
	private String currentSortOrder;
	private HtmlDatascroller htmlDataScroller = null;

    public HtmlDatascroller getHtmlDataScroller() {
		return htmlDataScroller;
	}

	public void setHtmlDataScroller(HtmlDatascroller htmlDataScroller) {
		this.htmlDataScroller = htmlDataScroller;
	}
	public String add(){
		ComponentInfo info = ComponentInfo.getInstance();
		info.addField(htmlDataScroller);
		return null;
	}
	public String getSortMode() {
		return sortMode;
	}

	public void setSortMode(String sortMode) {
		this.sortMode = sortMode;
	}

	public boolean isSelfSorted() {
		return selfSorted;
	}

	public void setSelfSorted(boolean selfSorted) {
		this.selfSorted = selfSorted;
	}

	public Ordering getSortOrder() {
		return sortOrder;
	}

	public void setSortOrder(Ordering sortOrder) {
		this.sortOrder = sortOrder;
	}

	public String getFilterValue() {
		return filterValue;
	}

	public void setFilterValue(String filterValue) {
		this.filterValue = filterValue;
	}

	public String getCurrentSortOrder() {
		return currentSortOrder;
	}

	public void setCurrentSortOrder(String currentSortOrder) {
		if("DESCENDING".equals(currentSortOrder)) this.sortOrder = Ordering.DESCENDING;
		else if("UNSORTED".equals(currentSortOrder)) this.sortOrder = Ordering.UNSORTED;
		else if("ASCENDING".equals(currentSortOrder)) this.sortOrder = Ordering.ASCENDING;
		this.currentSortOrder = currentSortOrder;
	}

	public String act() {
		action = "action work!";
		return null;
	}

	public String actListener(ActionEvent e) {
		actionListener = "actionListener work!";
		return null;
	}
    
	public String getAction() {
		return action;
	}

	public String getActionListener() {
		return actionListener;
	}

	public boolean isRenderTable() {
		return renderTable;
	}

	public void setRenderTable(boolean renderTable) {
		this.renderTable = renderTable;
	}

	public String getFastControls() {
		return fastControls;
	}

	public void setFastControls(String fastControls) {
		this.fastControls = fastControls;
	}

	public int getMaxPages() {
		return maxPages;
	}

	public void setMaxPages(int maxPages) {
		this.maxPages = maxPages;
	}

	public DataScroller() {
		action = "---";
		actionListener = "---";
		fastControls = "auto";
		render = true;
		renderIfSinglePage = true;
		align = "left";
		maxPages = 20;
		limitToList = false;
		filterValue = "";
		selfSorted = true;
		sortOrder = Ordering.ASCENDING;
		sortMode = "single";
		currentSortOrder = "ASCENDING";
		dataTable = new ArrayList();
		
		for(int i=0;i<1000;i++)
		{
			dataTable.add(new Data("Random",i));
		}	
				
	}
	
	public void CutArray(){
		int k = dataTable.size()-1;
		for(int i = k ;i > (k+1)/2; i--)
		{
			dataTable.remove(i);						
		}
	}
	
	public void RestoreArray(){
		
		int k = dataTable.size()-1;
		for(int i = k;i < (k+1)*2;i++)
		{
			dataTable.add(new Data("Random",i));
		}	
	}
	
	public ArrayList getDataTable() {
		return dataTable;
	}

	public void setDataTable(ArrayList dataTable) {
		this.dataTable = dataTable;
	}
	
	public void ScrollerListener(DataScrollerEvent e){
		
		System.out.println("NewScrollValue: "+e.getNewScrolVal());
		System.out.println("OldScrollValue: "+e.getOldScrolVal());
	}

	public Data getTD() {
		return tD;
	}

	public void setTD(Data td) {
		tD = td;
	}

	public boolean isRender() {
		return render;
	}

	public void setRender(boolean render) {
		this.render = render;
	}

	public boolean isRenderIfSinglePage() {
		return renderIfSinglePage;
	}

	public void setRenderIfSinglePage(boolean renderIfSinglePage) {
		this.renderIfSinglePage = renderIfSinglePage;
	}

	public String getAlign() {
		return align;
	}

	public void setAlign(String align) {
		this.align = align;
	}

	public boolean isLimitToList() {
		return limitToList;
	}

	public void setLimitToList(boolean limitToList) {
		this.limitToList = limitToList;
	}

	public void bTest1(){
		setAlign("left");
		setFastControls("auto");
		setLimitToList(false);
		setMaxPages(20);
		setRenderIfSinglePage(true);
	}
	
	public void bTest2(){
		setAlign("right");
		setFastControls("show");
		setLimitToList(false);
		setMaxPages(30);
		setRenderIfSinglePage(false);
	}
	
	public void bTest3(){
		setAlign("center");
		setFastControls("hide");
		setLimitToList(false);
		setMaxPages(10);
		setRenderIfSinglePage(true);
	}
	
	public void bTest4(){
		setAlign("center");
		setFastControls("auto");
		setLimitToList(true);
		setMaxPages(30);
		setRenderIfSinglePage(false);
	}
	
	public void bTest5(){
		setAlign("left");
		setFastControls("show");
		setLimitToList(false);
		setMaxPages(40);
		setRenderIfSinglePage(true);
	}
}
