PageRenderTime 92ms CodeModel.GetById 70ms app.highlight 5ms RepoModel.GetById 15ms app.codeStats 1ms

/src/mpv5/utils/renderer/CellEditorWithMPComboBox.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 85 lines | 37 code | 13 blank | 35 comment | 2 complexity | dee8673e8cb8a4e283d0d3d6874979ce MD5 | raw file
 1/*
 2 *  This file is part of YaBS.
 3 *
 4 *      YaBS is free software: you can redistribute it and/or modify
 5 *      it under the terms of the GNU General Public License as published by
 6 *      the Free Software Foundation, either version 3 of the License, or
 7 *      (at your option) any later version.
 8 *
 9 *      YaBS 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
12 *      GNU General Public License for more details.
13 *
14 *      You should have received a copy of the GNU General Public License
15 *      along with YaBS.  If not, see <http://www.gnu.org/licenses/>.
16 */
17package mpv5.utils.renderer;
18
19import javax.swing.JLabel;
20import javax.swing.JTable;
21import javax.swing.table.TableColumn;
22import mpv5.db.common.Context;
23import mpv5.ui.beans.LightMPComboBox;
24import mpv5.ui.beans.MPCBSelectionChangeReceiver;
25
26/**
27 *
28 */
29public class CellEditorWithMPComboBox  {
30
31    private final Context c;
32    private final JTable table;
33    private JLabel label = new JLabel();
34
35    /**
36     * Create a new CellRenderer which holds a MPComboBox with the given Context's data as model. Will not assign itself to any column.
37     * @param c
38     * @param table
39     */
40    public CellEditorWithMPComboBox(Context c, JTable table) {
41        super();
42        this.c = c;
43        this.table = table;
44    }
45
46    /**
47     * Set this renderer to the given column
48     * @param column
49     * @param r 
50     */
51    public void setEditorTo(int column, MPCBSelectionChangeReceiver r) {
52        setEditorTo(column, r, true);
53    }
54
55    /**
56     * Set this renderer to the given column
57     * @param column
58     * @param r
59     * @param editable 
60     */
61    public void setEditorTo(int column, MPCBSelectionChangeReceiver r, boolean editable) {
62        TableColumn col = table.getColumnModel().getColumn(column);
63        LightMPComboBox xc = new LightMPComboBox(c, table);
64        if (r != null) {
65            xc.addSelectionChangeReceiver(r);
66        }
67        col.setCellEditor(new MPComboBoxEditor(xc));
68        xc.setEditable(editable);
69    }
70
71    class MPComboBoxEditor extends LazyCellEditor {
72
73        private final LightMPComboBox box;
74
75        public MPComboBoxEditor(LightMPComboBox b) {
76            super(b);
77            this.box = b;
78            b.setLightWeightPopupEnabled(false);
79        }
80    }
81}
82
83
84
85