01: /*
02: *
03: * JMoney - A Personal Finance Manager
04: * Copyright (c) 2007 Nigel Westbury <westbury@users.sf.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.entrytable;
24:
25: import net.sf.jmoney.model2.Entry;
26: import net.sf.jmoney.model2.IPropertyControl;
27: import net.sf.jmoney.model2.ScalarPropertyAccessor;
28:
29: import org.eclipse.swt.events.FocusListener;
30: import org.eclipse.swt.widgets.Composite;
31: import org.eclipse.swt.widgets.Control;
32:
33: /**
34: * Represents a property that can be displayed in the entries table,
35: * edited by the user, or used in the filter.
36: * <P>
37: * Only properties where a single value exists in the cell are supported
38: * by this class.
39: * <P>
40: * The credit, debit, and balance columns are hard coded at the end
41: * of the table and are not represented by objects of this class.
42: *
43: * @author Nigel Westbury
44: */
45: public class SingleOtherEntryPropertyBlock extends
46: IndividualBlock<Entry, SplitEntryRowControl> {
47: private ScalarPropertyAccessor<?> accessor;
48:
49: public SingleOtherEntryPropertyBlock(ScalarPropertyAccessor accessor) {
50: super (accessor.getDisplayName(), accessor.getMinimumWidth(),
51: accessor.getWeight());
52:
53: this .accessor = accessor;
54: }
55:
56: public SingleOtherEntryPropertyBlock(
57: ScalarPropertyAccessor accessor, String displayName) {
58: super (displayName, accessor.getMinimumWidth(), accessor
59: .getWeight());
60:
61: this .accessor = accessor;
62: }
63:
64: public String getId() {
65: return accessor.getName();
66: }
67:
68: @Override
69: public ICellControl<Entry> createCellControl(Composite parent,
70: SplitEntryRowControl rowControl) {
71: final IPropertyControl propertyControl = accessor
72: .createPropertyControl(parent);
73:
74: return new ICellControl<Entry>() {
75:
76: public Control getControl() {
77: return propertyControl.getControl();
78: }
79:
80: public void load(Entry entry) {
81: propertyControl.load(entry);
82: }
83:
84: public void save() {
85: propertyControl.save();
86: }
87:
88: public void setFocusListener(
89: FocusListener controlFocusListener) {
90: // Nothing to do
91: }
92: };
93: }
94: }
|