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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
| JComboBox combo = null;
String nomEIL = Combo_EIL.getSelectedItem().toString();
nomEIL = nomEIL.replace("'", "''");
String[] listeInitiale = Planification.listeInitialHabilitation(base.connect(), nomEIL);
ArrayList listeDate = FichierExcelPlanification.listeDatePlanificationSelonEIL(base.connect(), nomEIL, annee.getText());
int nombreAnalyse = listeDate.size();
int colNo = 2;
Object[][] data = new Object[nombreAnalyse][colNo];
String initiale = null;
for(int j=0;j<listeInitiale.length;j++)
{
for (int indexAnalyse = 0; indexAnalyse < nombreAnalyse; indexAnalyse++)
{
String[] donnees = listeDate.get(indexAnalyse).toString().split(" ");
String date = donnees[0];
String nomT = donnees[1];
String prenomT = donnees[2];
initiale=Technicien.initial(base.connect(), nomT, prenomT);
String ini=listeInitiale[j];
data[indexAnalyse][0] = ini;
combo = new JComboBox(listeInitiale);
data[indexAnalyse][1] = date;
index=listeInitiale[j].indexOf(initiale);
combo.setSelectedIndex(index);
System.out.println("combo : "+combo.getSelectedItem()+" index "+ combo.getSelectedIndex());
}
}
//titre du tableau
String[] title = {"Initiale", "Date"};
//Combo \'e0 utiliser
//Nous devons utiliser un mod\'e8le d'affichage sp\'e9cifique afin de pallier aux bugs d'affichage !
ZModel zModel = new ZModel(data, title);
table.setModel(zModel);
table.setRowHeight(30);
// this.tableau.getColumn("Age").setCellRenderer(new ButtonRenderer());
// this.tableau.getColumn("Age").setCellEditor(new ButtonEditor(new JCheckBox()));
//On d\'e9finit l'\'e9diteur par d\'e9faut pour la cellule
//en lui sp\'e9cifiant quel type d'affichage prendre en compte
table.getColumn("Initiale").setCellEditor(new DefaultCellEditor(combo));
DefaultTableCellRenderer dcr = new DefaultTableCellRenderer();
table.getColumn("Initiale").setCellRenderer(dcr);
//On d\'e9finit un \'e9diteur pour la colonne "supprimer"
// this.tableau.getColumn("Suppression").setCellEditor(new DeleteButtonEditor(new JCheckBox()));
//On ajoute le tableau
// table.add(new JScrollPane(table), BorderLayout.CENTER);
JButton ajouter = new JButton("Ajouter une ligne");
// ajouter.addActionListener(new MoreListener());
table.add(ajouter, BorderLayout.SOUTH);
} catch (SQLException ex) {
Logger.getLogger(panel_modifier_planification.class.getName()).log(Level.SEVERE, null, ex);
}
}
class ZModel extends AbstractTableModel{
private Object[][] data;
private String[] title;
private boolean DEBUG;
/**
* Constructeur
* @param data
* @param title
*/
public ZModel(Object[][] data, String[] title){
this.data = data;
this.title = title;
}
/**
* Retourne le titre de la colonne \'e0 l'indice sp\'e9cif\'e9
*/
public String getColumnName(int col) {
return this.title[col];
}
/**
* Retourne le nombre de colonnes
*/
public int getColumnCount() {
return this.title.length;
}
/**
* Retourne le nombre de lignes
*/
public int getRowCount() {
return this.data.length;
}
/**
* Retourne la valeur \'e0 l'emplacement sp\'e9cifi\'e9
*/
public Object getValueAt(int row, int col) {
return this.data[row][col];
}
/**
* D\'e9fini la valeur \'e0 l'emplacement sp\'e9cifi\'e9
*/
public void setValueAt(Object value, int row, int col) {
//On interdit la modification sur certaine colonne !
// this.data[row][col] = value;
if (DEBUG) {
System.out.println("Setting value at " + row + "," + col
+ " to " + value
+ " (an instance of "
+ value.getClass() + ")");
}
data[row][col] = value;
fireTableCellUpdated(row, col);
if (DEBUG) {
System.out.println("New value of data:");
}
}
/**
* Retourne la classe de la donn\'e9e de la colonne
* @param col
*/
public Class getColumnClass(int col){
//On retourne le type de la cellule \'e0 la colonne demand\'e9e
//On se moque de la ligne puisque les donn\'e9es sur chaque ligne sont les m\'eames
//On choisit donc la premi\'e8re ligne
return this.data[0][col].getClass();
}
/**
* M\'e9thode permettant de retirer une ligne du tableau
* @param position
*/
public void removeRow(int position){
int indice = 0, indice2 = 0, nbRow = this.getRowCount()-1, nbCol = this.getColumnCount();
Object temp[][] = new Object[nbRow][nbCol];
for(Object[] value : this.data){
if(indice != position){
temp[indice2++] = value;
}
System.out.println("Indice = " + indice);
indice++;
}
this.data = temp;
temp = null;
//Cette m\'e9thode permet d'avertir le tableau que les donn\'e9es ont \'e9t\'e9 modifi\'e9es
//Ce qui permet une mise \'e0 jours compl\'e8te du tableau
this.fireTableDataChanged();
}
/**
* Permet d'ajouter une ligne dans le tableau
* @param data
*/
public void addRow(Object[] data){
int indice = 0, nbRow = this.getRowCount(), nbCol = this.getColumnCount();
Object temp[][] = this.data;
this.data = new Object[nbRow+1][nbCol];
for(Object[] value : temp)
this.data[indice++] = value;
this.data[indice] = data;
temp = null;
//Cette m\'e9thode permet d'avertir le tableau que les donn\'e9es ont \'e9t\'e9 modifi\'e9es
//Ce qui permet une mise \'e0 jours compl\'e8te du tableau
this.fireTableDataChanged();
}
public boolean isCellEditable(int row, int col){
return true;
}
} |
Partager