01: /*
02: *
03: * JMoney - A Personal Finance Manager
04: * Copyright (c) 2004 Nigel Westbury <westbury@users.sourceforge.net>
05: *
06: *
07: * This program is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU General Public License as published by
09: * the Free Software Foundation; either version 2 of the License, or
10: * (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20: *
21: */
22:
23: package net.sf.jmoney.fields;
24:
25: import java.util.Comparator;
26:
27: import net.sf.jmoney.model2.ExtendableObject;
28: import net.sf.jmoney.model2.IPropertyControl;
29: import net.sf.jmoney.model2.IPropertyControlFactory;
30: import net.sf.jmoney.model2.ScalarPropertyAccessor;
31:
32: import org.eclipse.swt.widgets.Composite;
33:
34: /**
35: * A control factory to edit boolean values using a check box.
36: *
37: * @author Nigel Westbury
38: */
39: public class CheckBoxControlFactory implements
40: IPropertyControlFactory<Boolean> {
41:
42: public CheckBoxControlFactory() {
43: }
44:
45: public IPropertyControl createPropertyControl(Composite parent,
46: ScalarPropertyAccessor<Boolean> propertyAccessor) {
47: return new CheckMarkEditor(parent, propertyAccessor);
48: }
49:
50: public String formatValueForMessage(
51: ExtendableObject extendableObject,
52: ScalarPropertyAccessor<? extends Boolean> propertyAccessor) {
53: Boolean value = extendableObject
54: .getPropertyValue(propertyAccessor);
55: if (value == null) {
56: return "N/A";
57: } else {
58: return value.toString();
59: }
60: }
61:
62: public String formatValueForTable(
63: ExtendableObject extendableObject,
64: ScalarPropertyAccessor<? extends Boolean> propertyAccessor) {
65: Boolean value = extendableObject
66: .getPropertyValue(propertyAccessor);
67: if (value == null) {
68: return "";
69: } else {
70: return value.toString();
71: }
72: }
73:
74: public Boolean getDefaultValue() {
75: return false;
76: }
77:
78: public boolean isEditable() {
79: return true;
80: }
81:
82: public Comparator<Boolean> getComparator() {
83: return new Comparator<Boolean>() {
84: public int compare(Boolean flag1, Boolean flag2) {
85: return flag1.compareTo(flag2);
86: }
87: };
88: }
89: }
|