01: /* SwingML
02: * Copyright (C) 2002 SwingML Team
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the
16: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17: * Boston, MA 02111-1307, USA.
18: *
19: * Authors:
20: * Ezequiel Cuellar <ecuellar@crosslogic.com>
21: * Marcelo W. Lopez Cremona <marcelo_java@argentina.com>
22: *
23: */
24:
25: package org.swingml.component;
26:
27: import java.util.Iterator;
28:
29: import javax.swing.DefaultCellEditor;
30: import javax.swing.JComboBox;
31:
32: import org.swingml.model.JTableModel;
33: import org.swingml.model.TableColumnModel;
34:
35: public class TableCellComboDecorator {
36:
37: public TableCellComboDecorator(JTableComponent aTable) {
38: JTableModel theTableModel = (JTableModel) aTable.getModel();
39: Iterator theColumns = theTableModel.getColumns().iterator();
40: TableColumnModel theColumn = null;
41: JComboBox theCombo = null;
42: while (theColumns.hasNext()) {
43: theColumn = (TableColumnModel) theColumns.next();
44: if (theColumn.getType() instanceof JComboBox) {
45: /*
46: Sets the cell editor to show up as a JComboBox for columns of type JComboBox.
47: It is not necesary to set a different cell renderer than the default for this case
48: */
49: if (theColumn.getItems() != null) {
50: theCombo = new JComboBox(theColumn.getItems());
51: aTable.setDefaultEditor(JComboBox.class,
52: new DefaultCellEditor(theCombo));
53: }
54: }
55: }
56: }
57: }
|