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
| public class CompartimentManager {
public static Compartiment createTempCompartiment() {
return new Compartiment();
}
public static Compartiment loadCompartiment(int uid) {
return CompartimentDao.load(uid);
}
public static List<Compartiment> loadAllCompartiment() {
return CompartimentDao.loadAll();
}
}
public class CompartimentTableModel extends EscrimTableModel {
private List<Compartiment> listeCompartiment = CompartimentManager
.loadAllCompartiment();
private String[] CompartimentColumnName = { "", "Nom", "Hauteur",
"Longueur", "Largeur", "Volume", "Poids", "uid" };
public CompartimentTableModel() {
listeCompartiment = CompartimentManager.loadAllCompartiment();
}
@Override
public String getColumnName(int columnIndex) {
return CompartimentColumnName[columnIndex];
}
@Override
public int getRowCount() {
if (listeCompartiment != null) {
return listeCompartiment.size();
} else {
return 0;
}
}
@Override
public int getColumnCount() {
return 8;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Compartiment compartiment = listeCompartiment.get(rowIndex);
switch (columnIndex) {
case 0:
return null;
case 1:
return compartiment.getNom();
case 2:
return compartiment.getHauteur();
case 3:
return compartiment.getLongueur();
case 4:
return compartiment.getLargeur();
case 5:
return compartiment.getVolume();
case 6:
return compartiment.getPoids();
case 7:
return compartiment.getUid();
}
return null;
}
@Override
public Class<?> getColumnClass(int columnIndex) {
switch (columnIndex) {
case 0:
return String.class;
case 1:
return String.class;
case 2:
return Float.class;
case 3:
return Float.class;
case 4:
return Float.class;
case 5:
return Float.class;
case 6:
return Float.class;
case 7:
return Integer.class;
}
return null;
}
public void addElement() {
listeCompartiment.add(0, CompartimentManager.createTempCompartiment());
fireTableRowsInserted(0, getRowCount());
}
} |
Partager