/*
 * 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 TableModelPJ extends AbstractTableModel {
    private Vector<PJ> data;
    
    /** Constructeur de la classe.**/
    public TableModelPJ(Vector<PJ> data) {
        super();
        this.data=data;
    }
    public TableModelPJ() {
        this(new Vector<PJ>());
    }
    
    public int getColumnCount(){
        return 3;
    }
    

    public int getRowCount() {
        return data.size();
    }
       
    public Object getValueAt(int row, int col) {
        PJ pj = data.get(row);
        switch (col){
            case 0 : return pj.getNamePJ();
            case 1 : return pj.getTypePJ();
            case 2 : return pj.getIdentifiant();
        }
        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 "Fichier";
            case 1 : return "Domaine";
            case 2 : return "Identifiant";
        }
        return "<error>";
    }

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

    public void add(PJ pj) {
        data.add(pj);
        System.out.println("Pj ajoutée");
        fireTableRowsInserted(0,data.size());
    }
    
    public void remove(int pos) {
        data.removeElementAt(pos);
        fireTableRowsDeleted(0,data.size());
    }
    
    public void refresh(){
        fireTableRowsUpdated(0,data.size());
    }

    public PJ getData(int pos){
        return data.get(pos);
    }
}