PageRenderTime 15ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
  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. */
  17. package mpv5.utils.renderer;
  18. import javax.swing.JLabel;
  19. import javax.swing.JTable;
  20. import javax.swing.table.TableColumn;
  21. import mpv5.db.common.Context;
  22. import mpv5.ui.beans.LightMPComboBox;
  23. import mpv5.ui.beans.MPCBSelectionChangeReceiver;
  24. /**
  25. *
  26. */
  27. public class CellEditorWithMPComboBox {
  28. private final Context c;
  29. private final JTable table;
  30. private JLabel label = new JLabel();
  31. /**
  32. * Create a new CellRenderer which holds a MPComboBox with the given Context's data as model. Will not assign itself to any column.
  33. * @param c
  34. * @param table
  35. */
  36. public CellEditorWithMPComboBox(Context c, JTable table) {
  37. super();
  38. this.c = c;
  39. this.table = table;
  40. }
  41. /**
  42. * Set this renderer to the given column
  43. * @param column
  44. * @param r
  45. */
  46. public void setEditorTo(int column, MPCBSelectionChangeReceiver r) {
  47. setEditorTo(column, r, true);
  48. }
  49. /**
  50. * Set this renderer to the given column
  51. * @param column
  52. * @param r
  53. * @param editable
  54. */
  55. public void setEditorTo(int column, MPCBSelectionChangeReceiver r, boolean editable) {
  56. TableColumn col = table.getColumnModel().getColumn(column);
  57. LightMPComboBox xc = new LightMPComboBox(c, table);
  58. if (r != null) {
  59. xc.addSelectionChangeReceiver(r);
  60. }
  61. col.setCellEditor(new MPComboBoxEditor(xc));
  62. xc.setEditable(editable);
  63. }
  64. class MPComboBoxEditor extends LazyCellEditor {
  65. private final LightMPComboBox box;
  66. public MPComboBoxEditor(LightMPComboBox b) {
  67. super(b);
  68. this.box = b;
  69. b.setLightWeightPopupEnabled(false);
  70. }
  71. }
  72. }