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 126 127 128 129 130 131
|
package templates.form.mod_int_adm;
import javax.swing.table.AbstractTableModel;
import java.util.*;
import java.sql.*;
@SuppressWarnings("serial")
public class ModeleModifiable extends AbstractTableModel {
private final List<Ami> amis = new ArrayList<Ami>();
private final String[] entetes = {"", "Num Int.", "Date Appel", "Utilisateur", "Juridiction", "Tech", "Objet"};
public ModeleModifiable(String ipserv, String pt, String us, String pw, String nba) {
super();
String pilote = "com.mysql.jdbc.Driver";
try{
Class.forName(pilote).newInstance();
Connection connexion = DriverManager.getConnection("jdbc:mysql://"+ipserv+":"+pt+"/"+nba+"",""+us+"",""+pw+"");
Statement instruction = connexion.createStatement();
ResultSet resultat = instruction.executeQuery("SELECT * FROM tb_intervention WHERE int_statut='Ouvert' ORDER BY int_num DESC");
while(resultat.next()){
amis.add(new Ami("", ""+resultat.getInt("int_num")+"", ""+resultat.getString("int_date_appel")+"", ""+resultat.getString("int_user_nom")+""+resultat.getString("int_user_prenom")+"", ""+resultat.getString("int_user_site")+"", ""+resultat.getString("int_tech")+"", ""+resultat.getString("int_objet")+""));
}
}
catch (Exception e){
System.out.println("echec pilote : "+e);
}
}
public int getRowCount() {
return amis.size();
}
public int getColumnCount() {
return entetes.length;
}
public String getColumnName(int columnIndex) {
return entetes[columnIndex];
}
public Object getValueAt(int rowIndex, int columnIndex) {
switch(columnIndex){
case 0:
return amis.get(rowIndex).getbtn();
case 1:
return amis.get(rowIndex).getNint();
case 2:
return amis.get(rowIndex).getdapp();
case 3:
return amis.get(rowIndex).getUser();
case 4:
return amis.get(rowIndex).getJuri();
case 5:
return amis.get(rowIndex).getTech();
case 6:
return amis.get(rowIndex).getObjet();
default:
return null; //Ne devrait jamais arriver
}
}
@SuppressWarnings("unchecked")
@Override
public Class getColumnClass(int columnIndex){
switch(columnIndex){
case 4 :
return String.class;
default:
return Object.class;
}
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false; //Toutes les cellules éditables
}
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
if(aValue != null){
Ami ami = amis.get(rowIndex);
switch(columnIndex){
case 0:
ami.setbtn((String)aValue);
break;
case 1:
ami.setNint((String)aValue);
break;
case 2:
ami.setdapp((String)aValue);
break;
case 3:
ami.setUser((String)aValue);
break;
case 4:
ami.setJuri((String)aValue);
break;
case 5:
ami.setTech((String)aValue);
break;
case 6:
ami.setObjet((String)aValue);
break;
}
}
}
public void addAmi(Ami ami) {
amis.add(ami);
fireTableRowsInserted(amis.size() -1, amis.size() -1);
}
public void removeAmi(int rowIndex) {
amis.remove(rowIndex);
fireTableRowsDeleted(rowIndex, rowIndex);
}
} |
Partager