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.jdbcdatastore.actions;
24:
25: import net.sf.jmoney.JMoneyPlugin;
26: import net.sf.jmoney.jdbcdatastore.JDBCDatastorePlugin;
27: import net.sf.jmoney.jdbcdatastore.SessionManager;
28:
29: import org.eclipse.jface.action.IAction;
30: import org.eclipse.jface.viewers.ISelection;
31: import org.eclipse.ui.IWorkbenchWindow;
32: import org.eclipse.ui.IWorkbenchWindowActionDelegate;
33:
34: /**
35: * Our sample action implements workbench action delegate.
36: * The action proxy will be created by the workbench and
37: * shown in the UI. When the user tries to use the action,
38: * this delegate will be created and execution will be
39: * delegated to it.
40: * @see IWorkbenchWindowActionDelegate
41: */
42: public class OpenSessionAction implements
43: IWorkbenchWindowActionDelegate {
44: private IWorkbenchWindow window;
45:
46: /**
47: * The constructor.
48: */
49: public OpenSessionAction() {
50: }
51:
52: /**
53: * The action has been activated. The argument of the
54: * method represents the 'real' action sitting
55: * in the workbench UI.
56: * @see IWorkbenchWindowActionDelegate#run
57: */
58: public void run(IAction action) {
59: if (JMoneyPlugin.getDefault().saveOldSession(window)) {
60: SessionManager sessionManager = JDBCDatastorePlugin
61: .getDefault().readSession(/*sessionFile,*/window);
62: if (sessionManager != null) {
63: JMoneyPlugin.getDefault().setSessionManager(
64: sessionManager);
65: }
66: }
67: }
68:
69: /**
70: * Selection in the workbench has been changed. We
71: * can change the state of the 'real' action here
72: * if we want, but this can only happen after
73: * the delegate has been created.
74: * @see IWorkbenchWindowActionDelegate#selectionChanged
75: */
76: public void selectionChanged(IAction action, ISelection selection) {
77: }
78:
79: /**
80: * We can use this method to dispose of any system
81: * resources we previously allocated.
82: * @see IWorkbenchWindowActionDelegate#dispose
83: */
84: public void dispose() {
85: }
86:
87: /**
88: * We will cache window object in order to
89: * be able to provide parent shell for the message dialog.
90: * @see IWorkbenchWindowActionDelegate#init
91: */
92: public void init(IWorkbenchWindow window) {
93: this.window = window;
94: }
95: }
|