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 org.eclipse.swt.SWT;
26: import org.eclipse.swt.events.FocusListener;
27: import org.eclipse.swt.events.SelectionEvent;
28: import org.eclipse.swt.events.SelectionListener;
29: import org.eclipse.swt.graphics.Image;
30: import org.eclipse.swt.layout.GridData;
31: import org.eclipse.swt.layout.GridLayout;
32: import org.eclipse.swt.widgets.Button;
33: import org.eclipse.swt.widgets.Composite;
34: import org.eclipse.swt.widgets.Control;
35:
36: abstract public class ButtonCellControl implements
37: ICellControl<EntryData> {
38:
39: private Button button;
40:
41: protected abstract void run(EntryRowControl rowControl);
42:
43: public ButtonCellControl(final EntryRowControl parent, Image image,
44: String toolTipText) {
45: /*
46: * Create a button, but override the preferred size to be 10 (by default
47: * it is 64). This prevents the button from making the lines too high.
48: * Unfortunately will need to wrap the button in a composite in order to
49: * override the preferred size. If anyone knows a better way, please change
50: * this code.
51: */
52: Composite composite = new Composite(parent, SWT.NONE);
53: GridLayout layout = new GridLayout();
54: layout.marginHeight = 0;
55: layout.marginWidth = 0;
56: composite.setLayout(layout);
57: button = new Button(composite, SWT.PUSH);
58: button.setLayoutData(new GridData(10, 10));
59: button.setImage(image);
60: button.setToolTipText(toolTipText);
61:
62: button.addSelectionListener(new SelectionListener() {
63: public void widgetDefaultSelected(SelectionEvent e) {
64: run(parent);
65: }
66:
67: public void widgetSelected(SelectionEvent e) {
68: run(parent);
69: }
70: });
71: }
72:
73: public Control getControl() {
74: return button;
75: }
76:
77: public void load(EntryData data) {
78: /*
79: * The button is always the same, so nothing to do here. Note that the
80: * entryData can be obtained from the RowControl object, so the
81: * entryData is available to the run method in the button's action.
82: */
83: }
84:
85: public void save() {
86: // Nothing to do
87: }
88:
89: public void setFocusListener(FocusListener controlFocusListener) {
90: // Nothing to do
91: }
92: }
|