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 132 133 134 135 136 137 138 139 140 141 142
|
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import DAO.ContactHasApplicationHome;
import DAO.ContactHome;
import util.Contact;
import util.ContactHasApplication;
public class Table_Contact extends AbstractTableModel {
private static final long serialVersionUID = 1L;
private final List<Contact> List_Contact= new ArrayList<Contact>();
Table_Contact moi = this;
private final String[] entetes = {"Id", "Nom", "Prénom", "Téléphone", "Email", "Entreprise", "Supprimer"};
private boolean[] lignesSelectionnees; // colonne ou y aura les checkbox
public Table_Contact()
{
super();
ContactHome contact = new ContactHome();
List <Contact> list= contact.ListContact();
for(int i =0; i<list.size();i++)
{
Contact cont = list.get(i);
List_Contact.add(cont);
}
lignesSelectionnees = new boolean[List_Contact.size()]; // ajuste la taille de la colonne
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
if (columnIndex == 6) return true; // retourn vrai pour la colonne des checkbox
else return false; // sinon faux
}
public Table_Contact(int id_application, int type)
{
super();
ContactHasApplicationHome contactHasApplication = new ContactHasApplicationHome();
ContactHome contact = new ContactHome();
List <ContactHasApplication> list= contactHasApplication.ListContactHasApplication();
for(int i =0; i<list.size();i++)
{
if((list.get(i).getApplicationIdApplication()==id_application)&&(list.get(i).getTcontactIdTcontact()== type))
{
Contact cont = contact.get_byId(list.get(i).getContactIdContact());
List_Contact.add(cont);
}
}
lignesSelectionnees = new boolean[List_Contact.size()];
}
@Override
public Class<?> getColumnClass(int columnIndex) {
if (columnIndex == 6) return Boolean.class; // pour la colonne checkbox
else return String.class;
}
@Override
public int getColumnCount() {
// TODO Auto-generated method stub
return entetes.length;
}
@Override
public int getRowCount() {
// TODO Auto-generated method stub
return List_Contact.size();
}
public String getColumnName(int columnIndex) {
return entetes[columnIndex];
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
switch(columnIndex){
case 0:
return List_Contact.get(rowIndex).getIdContact();
case 1:
return List_Contact.get(rowIndex).getNom();
case 2:
return List_Contact.get(rowIndex).getPrenom();
case 3:
return List_Contact.get(rowIndex).getTelephone();
case 4:
return List_Contact.get(rowIndex).getEmail();
case 5:
return List_Contact.get(rowIndex).getEntreprise();
case 6:
return lignesSelectionnees[rowIndex];
default:
return null;
}
}
@Override
public void setValueAt(Object value,int rowIndex, int columnIndex) {
switch(columnIndex){
case 0:
List_Contact.get(rowIndex).setIdContact((Integer) value);
case 1:
List_Contact.get(rowIndex).setNom((String) value);
case 2:
List_Contact.get(rowIndex).setPrenom((String) value);
case 3:
List_Contact.get(rowIndex).setTelephone((String) value);
case 4:
List_Contact.get(rowIndex).setEmail((String) value);
case 5:
List_Contact.get(rowIndex).setEntreprise((String) value);
case 6:
lignesSelectionnees[rowIndex]= (Boolean) value;
default:
break;
}
}
public void removeContact(int rowIndex)
{
List_Contact.remove(rowIndex);
fireTableRowsDeleted(rowIndex, rowIndex);
}
public void addContact(Contact C) {
List_Contact.add(C);
fireTableRowsInserted(List_Contact.size() -1, List_Contact.size() -1);
}
public Contact getData(int row)
{
return List_Contact.get(row);
}
public List<Contact> getContact() {
return List_Contact;
}
} |
Partager