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.SWT;
33: import org.eclipse.swt.layout.GridData;
34: import org.eclipse.swt.widgets.Composite;
35:
36: /**
37: * A control factory to edit multi line text.
38: *
39: * @author Nigel Westbury
40: * @author Johann Gyger
41: */
42: public class MultiTextControlFactory implements
43: IPropertyControlFactory<String> {
44:
45: public IPropertyControl createPropertyControl(Composite parent,
46: ScalarPropertyAccessor<String> propertyAccessor) {
47: IPropertyControl multiText = new TextEditor(parent, SWT.MULTI
48: | SWT.WRAP, propertyAccessor);
49: GridData gridData = new GridData();
50: gridData.verticalAlignment = GridData.FILL;
51: gridData.grabExcessVerticalSpace = true;
52: gridData.horizontalAlignment = GridData.FILL;
53: gridData.grabExcessHorizontalSpace = true;
54: multiText.getControl().setLayoutData(gridData);
55: return multiText;
56: }
57:
58: public String formatValueForMessage(
59: ExtendableObject extendableObject,
60: ScalarPropertyAccessor<? extends String> propertyAccessor) {
61: String value = extendableObject
62: .getPropertyValue(propertyAccessor);
63: if (value == null || value.length() == 0) {
64: return "empty";
65: } else {
66: return "'" + value + "'";
67: }
68: }
69:
70: public String formatValueForTable(
71: ExtendableObject extendableObject,
72: ScalarPropertyAccessor<? extends String> propertyAccessor) {
73: return extendableObject.getPropertyValue(propertyAccessor);
74: }
75:
76: public String getDefaultValue() {
77: return null;
78: }
79:
80: public boolean isEditable() {
81: return true;
82: }
83:
84: public Comparator<String> getComparator() {
85: return null;
86: }
87: }
|