1 7 package com.genimen.djeneric.tools.specifier.base; 8 9 import java.awt.Component ; 10 import java.util.ArrayList ; 11 12 import javax.swing.DefaultComboBoxModel ; 13 import javax.swing.JComboBox ; 14 import javax.swing.JTable ; 15 16 public abstract class BaseComboBoxCellEditor extends BaseCellEditor 17 { 18 JComboBox _comboBox; 19 20 public BaseComboBoxCellEditor() 21 { 22 super(new JComboBox ()); 23 _comboBox = (JComboBox ) _editorComponent; 24 _comboBox.addActionListener(this); 25 } 26 27 public void setValue(Object value) 28 { 29 if (_comboBox.isEditable()) _comboBox.getEditor().setItem(value); 30 else _comboBox.setSelectedItem(value); 31 } 32 33 public Object getCellEditorValue() 34 { 35 if (_comboBox.isEditable()) return _comboBox.getEditor().getItem(); 36 else return _comboBox.getSelectedItem(); 37 } 38 39 public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) 40 { 41 try 42 { 43 ArrayList lst = getList(row, column); 44 45 _comboBox.setModel(new DefaultComboBoxModel (lst.toArray())); 46 } 47 catch (Exception x) 48 { 49 getModel().setStatusMessage(x); 50 } 51 setValue(value); 52 return _comboBox; 53 } 54 55 public abstract ArrayList getList(int row, int column); 56 57 public JComboBox getComboBox() 58 { 59 return _comboBox; 60 } 61 62 } | Popular Tags |