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
|
public class ComboEditor extends JComboBox implements TableCellEditor, TableModelListener {
private JComboBox combo;
private JTable jTable;
private Ihm frame;
protected EventListenerList listenerList;
public ComboEditor(Ihm frame)
{
combo = new JComboBox();
this.frame = frame;
/** instanciation nécessaire : (à faire dans son constructeur
* ou dans une méthode appelée par le constructeur)
*/
this.listenerList = new EventListenerList ();
}
public Component getTableCellEditorComponent(JTable jTable, Object contenuCell,
boolean isSelected, int numLigne, int numCol)
{
JComboBox combo = new JComboBox();
this.jTable = jTable;
// TODO Auto-generated method stub
// Générer la liste du comboBox
String nomColonne = jTable.getColumnName(numCol);
if ("NomDelegation".equals(nomColonne))
{
String requete = "SELECT NomDelegation FROM Delegation ORDER BY NomDelegation ASC";
String requeteCompte = "SELECT COUNT('NomDelegation') FROM Delegation";
combo = getListe(requete, requeteCompte);
}
else if("Sexe".equals(nomColonne))
{
combo.addItem("F");
combo.addItem("M");
}
else if("NomLogement".equals(nomColonne))
{
String requete = "SELECT NomLogement FROM Logement ORDER BY NomLogement ASC";
String requeteCompte = "SELECT COUNT('NomLogement') FROM Delegation";
combo = getListe(requete, requeteCompte);
}
this.combo = combo;
return this.combo;
}
public Object getCellEditorValue() {
// TODO Auto-generated method stub
return combo.getSelectedItem();
}
public boolean shouldSelectCell(EventObject evt) {
// TODO Auto-generated method stub
if (evt instanceof MouseEvent) {
MouseEvent e = (MouseEvent)evt;
return e.getID() != MouseEvent.MOUSE_DRAGGED;
}
return true;
}
public boolean isCellEditable(EventObject evt)
{
// TODO Auto-generated method stub
return true;
}
public boolean stopCellEditing() {
// TODO Auto-generated method stub
/*if (combo.isEditable()) {
// Commit edited value.
combo.actionPerformed(new ActionEvent(
this, 0, ""));
}*/
return true;
}
public void cancelCellEditing() {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.swing.CellEditor#addCellEditorListener(javax.swing.event.CellEditorListener)
*/
public void addCellEditorListener(CellEditorListener l) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.swing.CellEditor#removeCellEditorListener(javax.swing.event.CellEditorListener)
*/
public void removeCellEditorListener(CellEditorListener l) {
// TODO Auto-generated method stub
}
public void addCellEditorListener(EditorListener el) {
// TODO Auto-generated method stub
this.listenerList.add(EditorListener.class, el);
}
public void removeCellEditorListener(EditorListener el) {
// TODO Auto-generated method stub
this.listenerList.remove(EditorListener.class, el);
}
public void fireEditorStopped()
{
EditorListener [] listeners = (EditorListener []) listenerList.getListeners( EditorListener.class);
EventObject e = new EventObject (this);
for (int i = listeners.length-1; i>=0; i--) {
listeners [i].editorStopped(e);
}
}
public void fireEditorCanceled()
{
EditorListener [] listeners = (EditorListener []) listenerList.getListeners( EditorListener.class);
EventObject e = new EventObject (this);
for (int i = listeners.length-1; i>=0; i--) {
listeners [i].editorCanceled(e);
}
}... |
Partager