01: /*
02: * Created on Mar 27, 2003
03: *
04: * Dbmjui is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU General Public License version 2 as
06: * published by the Free Software Foundation.
07: *
08: * Dbmjui is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * General Public License for more details.
12: *
13: * You should have received a copy of the GNU General Public
14: * License along with dbmjui; see the file COPYING. If not,
15: * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16: * Boston, MA 02111-1307, USA.
17: *
18: */
19: package fr.aliacom.form.swt.ui;
20:
21: import org.eclipse.swt.SWT;
22: import org.eclipse.swt.widgets.Label;
23: import org.eclipse.swt.widgets.Table;
24:
25: import fr.aliacom.bean.BeanUtils;
26: import fr.aliacom.common.ui.table.CellEditorSupport;
27: import fr.aliacom.common.ui.table.ICellEditor;
28: import fr.aliacom.common.ui.table.ICellEditorListener;
29:
30: /**
31: * @author tom
32: *
33: * (c) 2001, 2003 Thomas Cataldo
34: */
35: public final class SWTCheckBoxEditor implements ICellEditor {
36:
37: private Label lbl;
38: private String property;
39: private CellEditorSupport ces;
40:
41: public SWTCheckBoxEditor(Table t, String property) {
42: lbl = new Label(t, SWT.NULL);
43: lbl.setBackground(lbl.getDisplay().getSystemColor(
44: SWT.COLOR_LIST_BACKGROUND));
45: this .property = property;
46: ces = new CellEditorSupport();
47: }
48:
49: public Object clone() {
50: return new SWTCheckBoxEditor((Table) lbl.getParent(), property);
51: }
52:
53: public void reset() {
54: }
55:
56: public void setValueBean(Object bean) {
57: boolean value = !((Boolean) BeanUtils.getValue(bean, property))
58: .booleanValue();
59: BeanUtils.setValue(bean, property, new Boolean(value));
60: ces.fireEditingStopped();
61: }
62:
63: public Object getNativeWidget() {
64: return lbl;
65: }
66:
67: /**
68: * @param icel
69: */
70: public void addCellEditorListener(ICellEditorListener icel) {
71: ces.addCellEditorListener(icel);
72: }
73:
74: /**
75: * @param icel
76: */
77: public void removeCellEditorListener(ICellEditorListener icel) {
78: ces.removeCellEditorListener(icel);
79: }
80:
81: }
|