01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.ui;
16:
17: import net.refractions.udig.ui.internal.Messages;
18:
19: import org.eclipse.jface.viewers.ComboBoxCellEditor;
20: import org.eclipse.swt.SWT;
21: import org.eclipse.swt.widgets.Composite;
22:
23: /**
24: * Cell editor for Boolean choices
25: *
26: * @author Jesse
27: * @since 1.1.0
28: */
29: public class BooleanCellEditor extends ComboBoxCellEditor {
30:
31: private static final String FALSE = Messages.BooleanCellEditor_FALSE;
32: private static final String TRUE = Messages.BooleanCellEditor_TRUE;
33:
34: public BooleanCellEditor(Composite control) {
35: super (control, new String[] { TRUE, FALSE }, SWT.READ_ONLY);
36: }
37:
38: @Override
39: protected boolean isCorrect(Object value) {
40: if (value == null)
41: return super .isCorrect(null);
42: return super .isCorrect(Boolean.valueOf(value.equals(Integer
43: .valueOf(0))));
44: }
45:
46: @Override
47: protected Object doGetValue() {
48:
49: Object value = super .doGetValue();
50:
51: if (value == null)
52: return null;
53:
54: return Boolean.valueOf(value.equals(Integer.valueOf(0)));
55: }
56:
57: @Override
58: protected void doSetValue(Object value) {
59: if (value == null) {
60: super .doSetValue(0);
61: } else {
62: Boolean bool = (Boolean) value;
63: if (bool)
64: super .doSetValue(0);
65: else
66: super .doSetValue(1);
67: }
68: }
69: }
|