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
| public class OrdonnanceurTableModel extends AbstractTableModel {
public static final int COLUMN_PROCESSUS = 0;
public static final int COLUMN_TEMP_ARRIVE = 1;
public static final int COLUMN_DUREE = 2;
public static final int COLUMN_FIN_EXECUTION = 3;
private int nbProcess;
private Map<Integer, Data> map;
public OrdonnanceurTableModel(int nbProcess) {
this.nbProcess=nbProcess;
this.map = new HashMap<Integer,Data>();
}
@Override
public int getRowCount() {
return nbProcess;
}
@Override
public int getColumnCount() {
return 4;
}
@Override
public String getColumnName(int column) {
switch(column) {
case COLUMN_PROCESSUS:
return "processus";
case COLUMN_TEMP_ARRIVE:
return "temp arrive";
case COLUMN_DUREE:
return "duree";
case COLUMN_FIN_EXECUTION:
return "finExecution";
}
return null;
}
public void setData(int process, long tempArrive, long duree) {
map.compute(process, (key, data)-> {
if ( data==null ) {
data = new Data();
}
data.tempArrive = tempArrive;
data.duree = duree;
return data;
});
fireTableRowsUpdated(process,process);
}
public void setTempArrive(int process, long tempArrive) {
map.compute(process, (key, data)-> {
if ( data==null ) {
data = new Data();
}
data.tempArrive = tempArrive;
return data;
});
fireTableRowsUpdated(process,process);
}
public void setDuree(int process, long duree) {
map.compute(process, (key, data)-> {
if ( data==null ) {
data = new Data();
}
data.duree = duree;
return data;
});
fireTableRowsUpdated(process,process);
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
switch(columnIndex) {
case COLUMN_PROCESSUS: // processus
return "p"+rowIndex;
case COLUMN_TEMP_ARRIVE: // tempArrive
return map.getOrDefault(rowIndex, DEFAULT_DATA).tempArrive;
case COLUMN_DUREE: // duree
return map.getOrDefault(rowIndex, DEFAULT_DATA).duree;
case COLUMN_FIN_EXECUTION: // fin exécution
return map.getOrDefault(rowIndex, DEFAULT_DATA).getFinExecution();
}
return null;
}
private final Data DEFAULT_DATA = new Data();
private class Data {
public Long duree;
public Long tempArrive;
public Long getFinExecution() {
if ( duree==null || tempArrive==null ) {
return null;
}
return tempArrive + duree;
}
}
} |
Partager