/*
 * 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.facelets.component.table.autosort;

import com.icesoft.faces.facelets.component.table.BaseTableBean;
import java.io.Serializable;

import java.util.List;
import java.util.logging.Logger;

public class AutoSortTableBean extends BaseTableBean {

    private String defaultSortCol;
    private List list;
    private SortableDataModel sortableDataModel;
    
    private static final Logger LOG = Logger.getLogger(AutoSortTableBean.class.getName());

    public AutoSortTableBean(List list, String defaultSortCol) {
        this.defaultSortCol = defaultSortCol;
        this.list = list;
        initializeSortableDataModel();
    }
    
    @Override
    public SortableDataModel getData(){
    	if( sortableDataModel == null ){
    		initializeSortableDataModel();
    	}
    	return sortableDataModel;
    }
    
    private void initializeSortableDataModel(){
    	this.sortableDataModel = new SortableDataModel(list, defaultSortCol);
    }

    public Object clone() {
        AutoSortTableBean newObj = new AutoSortTableBean(list, defaultSortCol);
        ((SortableDataModel) newObj.getData()).setAscending(getData().isAscending());
        ((SortableDataModel) newObj.getData()).setSort(getData().getSort());
        newObj.setDisplayedRows(displayedRows);
        return newObj;
    }

    public boolean isSortAscending() {
        return getData().isAscending();
    }

    public void setSortAscending(boolean sortAscending) {
    	getData().setAscending(sortAscending);
    }

    public String getSortColumn() {
        return getData().getSort();
    }

    public void setSortColumn(String sortColumn) {
    	getData().setSort(sortColumn);
    }
   

}
