/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.gouv.finances.cp.xemelios.plugin.generatorPesPjs;

/**
 *
 * @author jp.tessier
 */
import java.util.Vector;
import javax.swing.table.AbstractTableModel;

public class TableModelRefCompta extends AbstractTableModel {
    private Vector<RefCompta> data;
    
    /** Constructeur de la classe.**/
    public TableModelRefCompta(Vector<RefCompta> data) {
        super();
        this.data=data;
    }
    public TableModelRefCompta() {
        this(new Vector<RefCompta>());
    }
    
    public int getColumnCount(){
        return 3;
    }
    

    public int getRowCount() {
        return data.size();
    }
       
    public Object getValueAt(int row, int col) {
        RefCompta refCompta = data.get(row);
        switch (col){
            case 0 : return refCompta.getDomaine();
            case 1 : return refCompta.getTypePiece().key;
            case 2 : return refCompta.getNumPiece();
        } 
        return "<error>";
    }
    
    /** Retourne la Class des objets stock�s dans la colonne c */
    public Class getColumnClass(int c){
        return String.class;
        //getValueAt(0, c).getClass();
    }
    
    /** Retourne true si la cellule � la ligne row dans la colonne col est �ditable */
    public boolean isCellEditable(int row, int col) {
        return false;
    }

    public String getColumnName(int columnIndex) {
        switch (columnIndex){
            case 0 : return "Domaine";
            case 1 : return "Type de Pi�ce";
            case 2 : return "Num�ro de Mandat";
        }
        return "<error>";
    }

    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        /*setValueAt(aValue, rowIndex, columnIndex);*/
    }

    public void add(RefCompta rc) {
        data.add(rc);
        System.out.println("RefCompta ajout�e");
        fireTableRowsInserted(0,data.size());
    }
    
    public void remove(int pos) {
        data.removeElementAt(pos);
        fireTableRowsInserted(0,data.size());
    }

    public void refresh(){
        fireTableRowsUpdated(0,data.size());
    }
    
    public RefCompta getData(int pos){
        return data.get(pos);
    }
}
