1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
| import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
public class Tableau_stock_articles_model extends AbstractTableModel {
private ArrayList<ArrayList<String>> list_colonnes = new ArrayList<ArrayList<String>>();
private ArrayList<ArrayList<ArrayList<Object>>> list_lignes = new ArrayList<ArrayList<ArrayList<Object>>>();
public Tableau_stock_articles_model(){
initTableau();
}
private void initTableau() {
list_colonnes.add(0, new ArrayList<String>());
list_colonnes.get(0).add(0, "Numero");
list_colonnes.add(1, new ArrayList<String>());
list_colonnes.get(1).add(0, "Article");
list_colonnes.add(2, new ArrayList<String>());
list_colonnes.get(2).add(0, "Doses");
list_colonnes.add(3, new ArrayList<String>());
list_colonnes.get(3).add(0, "Lots");
list_colonnes.add(4, new ArrayList<String>());
list_colonnes.get(4).add(0, "Quantités par lots");
list_colonnes.add(5, new ArrayList<String>());
list_colonnes.get(5).add(0, "Prix réel par lots");
list_colonnes.add(6, new ArrayList<String>());
list_colonnes.get(6).add(0, "Quantités totales");
list_colonnes.add(7, new ArrayList<String>());
list_colonnes.get(7).add(0, "Montant");
list_colonnes.add(8, new ArrayList<String>());
list_colonnes.get(8).add(0, "Filtre");
list_colonnes.add(9, new ArrayList<String>());
list_colonnes.get(9).add(0, "Sous-filtre");
list_colonnes.add(10, new ArrayList<String>());
list_colonnes.get(10).add(0, "Commentaires");
}
@Override
public int getColumnCount() {
// TODO Auto-generated method stub
return list_colonnes.size();
}
@Override
public int getRowCount() {
// TODO Auto-generated method stub
return list_lignes.size();
}
@Override
public String getColumnName(int col) {
// TODO Auto-generated method stub
return list_colonnes.get(col).get(0);
}
public Object getValueAt(int row, int col) {
return list_lignes.get(row).get(col).get(0);
}
public boolean isCellEditable(int row, int col){
if(col==1 || col==2 || col==3 || col==4 || col==5 || col==8 || col==9 || col==10){
return true;
}
else{
return false;
}
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
public void setValueAt(Object value, int row, int col) {
list_lignes.get(row).get(col).add(0, value);
if(col>=2 && col<=4){// On met a jour la quantitée
System.out.println("type: t"+list_lignes.get(row).get(2).get(1)+"t :"+ row);
Float col_coef_doses= (Float) ((list_lignes.get(row).get(2).get(1).toString()==null || list_lignes.get(row).get(2).get(1).toString().isEmpty())? 0: (Float.valueOf((String)list_lignes.get(row).get(2).get(1)))) ;
int col_nb_doses= (Integer) ((list_lignes.get(row).get(2).get(2)!="") ? list_lignes.get(row).get(2).get(2): 0);
int col_lots=(list_lignes.get(row).get(3).get(0).toString().isEmpty())? 0 : Integer.parseInt(list_lignes.get(row).get(3).get(0).toString());
int col_quantites=(list_lignes.get(row).get(4).get(0).toString()!="")? Integer.parseInt(list_lignes.get(row).get(4).get(0).toString()): 0 ;
int somme_total_doses= (int) ((col_nb_doses==0.f || col_coef_doses.intValue()==0.0)? 0 : Math.floor(col_coef_doses*col_nb_doses));
int col_quantite_totales=col_lots*col_quantites+somme_total_doses*col_quantites;
//int somme=(Integer) Integer.parseInt(list_lignes.get(row).get(3).get(0).toString());
list_lignes.get(row).get(6).add(0, col_quantite_totales);
fireTableCellUpdated(row, 6);
}
fireTableCellUpdated(row, col);
}
public void setValueAt(Object value, int indice, int row, int col) {
list_lignes.get(row).get(col).add(indice, value);
fireTableCellUpdated(row, col);
System.out.println("table model : row: "+row+" col: "+col+" indice: "+ indice+" Valeur: "+value);
System.out.println("table model : "+ list_lignes.get(row).get(col).get(indice));
}
public void addNewRow() {
int n_ligne = (list_lignes.size()==0) ? 0 : list_lignes.size();
System.out.println(n_ligne);
list_lignes.add(n_ligne, new ArrayList<ArrayList<Object>>());
list_lignes.get(n_ligne).add(0, new ArrayList<Object>());
list_lignes.get(n_ligne).get(0).add(0, String.valueOf(n_ligne+1));
list_lignes.get(n_ligne).add(1, new ArrayList<Object>());
list_lignes.get(n_ligne).get(1).add(0, "");
list_lignes.get(n_ligne).add(2, new ArrayList<Object>());
list_lignes.get(n_ligne).get(2).add(0, "");
list_lignes.get(n_ligne).add(3, new ArrayList<Object>());
list_lignes.get(n_ligne).get(3).add(0, "");
list_lignes.get(n_ligne).add(4, new ArrayList<Object>());
list_lignes.get(n_ligne).get(4).add(0, "");
list_lignes.get(n_ligne).add(5, new ArrayList<Object>());
list_lignes.get(n_ligne).get(5).add(0, "");
list_lignes.get(n_ligne).add(6, new ArrayList<Object>());
list_lignes.get(n_ligne).get(6).add(0, "");
list_lignes.get(n_ligne).add(7, new ArrayList<Object>());
list_lignes.get(n_ligne).get(7).add(0, "");
list_lignes.get(n_ligne).add(8, new ArrayList<Object>());
list_lignes.get(n_ligne).get(8).add(0, "");
list_lignes.get(n_ligne).add(9, new ArrayList<Object>());
list_lignes.get(n_ligne).get(9).add(0, "");
list_lignes.get(n_ligne).add(10, new ArrayList<Object>());
list_lignes.get(n_ligne).get(10).add(0, "");
}
} |