/*
 * TestConfig.java
 *
 * Created on October 20, 2006, 1:31 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package usda.weru.util.table.test;

import com.klg.jclass.table.EditableTableDataModel;
import com.klg.jclass.table.data.AbstractDataSource;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Vector;

/**
 * Config datasource, property | value
 * @author Joseph Levin
 */
public class TestConfig extends AbstractDataSource implements EditableTableDataModel{
    private static final long serialVersionUID = 1L;
    
    Map <String, Object> c_data;
    List <Property> c_properties;
    /** Creates a new instance of TestConfig */
    public TestConfig() {
        c_data = new Hashtable <String, Object> ();
        c_properties = new Vector <Property> ();
        
        //Default data
        c_properties.add(new Property("Some string", "some_string"));
        c_data.put("some_string", "Hello World");
    }

    @Override
    public int getNumRows() {
        return c_properties.size();
    }

    @Override
    public int getNumColumns() {
        return 2;
    }

    @Override
    public Object getTableRowLabel(int row) {
        return row;
    }

    @Override
    public Object getTableColumnLabel(int column) {
        switch (column){
            case 0:
                return "property";
            case 1:
                return "value";
            default:
                return null;
        }
    }
    
    @Override
    public Object getTableDataItem(int row, int column) {        
        Property prop = c_properties.get(row);
        if (column == 0){
            return prop.getName();
        }
        else{
            Object value = c_data.get(prop.getKey());
            return value;
        }
    }

    @Override
    public boolean setTableDataItem(Object o, int row, int column) {
        return true;
    }
    
    static class Property {
        private final String c_name;
        private final String c_key;
       
        public Property(String name, String key){
            c_name = name;
            c_key = key;
        }
        public String getName(){
            return c_name;
        }
        
        public String getKey(){
            return c_key;
        }
        
    }
    
    
    
}
