1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.xulux.guilayer.swing.models;
17
18 import java.awt.Component;
19
20 import javax.swing.AbstractCellEditor;
21 import javax.swing.JTable;
22 import javax.swing.JTextField;
23 import javax.swing.table.TableCellEditor;
24
25 import org.xulux.api.gui.IWidget;
26
27
28
29
30
31
32
33 public class NyxTableCellEditor extends AbstractCellEditor implements TableCellEditor {
34
35
36
37
38 private IWidget widget;
39
40
41
42
43 public NyxTableCellEditor(IWidget widget) {
44 this.widget = widget;
45 }
46
47
48
49 public Object getCellEditorValue() {
50 return widget.getGuiValue();
51 }
52
53
54
55 public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
56 return (Component) this.widget.getNativeWidget();
57 }
58
59
60
61
62
63 public void stopCellEditing(JTable table) {
64 Component component = table.getEditorComponent();
65 if (component instanceof JTextField) {
66 table.getModel().setValueAt(((JTextField) component).getText(), table.getEditingRow(), table.getEditingColumn());
67 stopCellEditing();
68 }
69 }
70
71
72
73
74 public IWidget getWidget() {
75 return this.widget;
76 }
77
78
79
80
81 public void destroy() {
82 this.widget = null;
83 }
84
85 }