001: /*
002: *
003: * JMoney - A Personal Finance Manager
004: * Copyright (c) 2007 Nigel Westbury <westbury@users.sourceforge.net>
005: *
006: *
007: * This program is free software; you can redistribute it and/or modify
008: * it under the terms of the GNU General Public License as published by
009: * the Free Software Foundation; either version 2 of the License, or
010: * (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
020: *
021: */
022:
023: package net.sf.jmoney.wizards;
024:
025: import net.sf.jmoney.isolation.TransactionManager;
026: import net.sf.jmoney.isolation.UncommittedObjectKey;
027: import net.sf.jmoney.model2.Account;
028: import net.sf.jmoney.model2.AccountInfo;
029: import net.sf.jmoney.model2.CapitalAccount;
030: import net.sf.jmoney.model2.ExtendablePropertySet;
031: import net.sf.jmoney.model2.IncomeExpenseAccount;
032: import net.sf.jmoney.model2.IncomeExpenseAccountInfo;
033: import net.sf.jmoney.model2.Session;
034:
035: import org.eclipse.jface.wizard.Wizard;
036: import org.eclipse.jface.wizard.WizardPage;
037: import org.eclipse.swt.SWT;
038: import org.eclipse.swt.layout.GridData;
039: import org.eclipse.swt.layout.GridLayout;
040: import org.eclipse.swt.widgets.Composite;
041: import org.eclipse.swt.widgets.Label;
042: import org.eclipse.swt.widgets.MessageBox;
043:
044: public class NewAccountWizard extends Wizard {
045:
046: private ExtendablePropertySet<? extends Account> accountPropertySet;
047:
048: private TransactionManager transactionManager;
049:
050: private Account newUncommittedAccount;
051:
052: /**
053: * This is set when 'finish' is pressed and the new account is committed.
054: */
055: private Account newCommittedAccount;
056:
057: /**
058: *
059: * @param finalPropertySet the property set object of the class
060: * of account to create
061: * @param parentAccount the parent account or null if this is to be
062: * a top level account
063: */
064: public NewAccountWizard(Session session,
065: IncomeExpenseAccount parentAccount) {
066: this .accountPropertySet = IncomeExpenseAccountInfo
067: .getPropertySet();
068:
069: this .setWindowTitle("Create a New Category");
070: this .setHelpAvailable(true);
071:
072: transactionManager = new TransactionManager(session
073: .getDataManager());
074:
075: IncomeExpenseAccount parentAccount2 = transactionManager
076: .getCopyInTransaction(parentAccount);
077: if (parentAccount2 == null) {
078: Session session2 = transactionManager.getSession();
079: newUncommittedAccount = session2
080: .createAccount(accountPropertySet);
081: } else {
082: newUncommittedAccount = parentAccount2.createSubAccount();
083: }
084: }
085:
086: /**
087: *
088: * @param finalPropertySet the property set object of the class
089: * of account to create
090: * @param parentAccount the parent account or null if this is to be
091: * a top level account
092: */
093: public NewAccountWizard(
094: Session session,
095: CapitalAccount parentAccount,
096: ExtendablePropertySet<? extends CapitalAccount> accountPropertySet) {
097: this .accountPropertySet = accountPropertySet;
098:
099: this .setWindowTitle("Create a New Account");
100: this .setHelpAvailable(true);
101:
102: transactionManager = new TransactionManager(session
103: .getDataManager());
104:
105: CapitalAccount parentAccount2 = transactionManager
106: .getCopyInTransaction(parentAccount);
107: if (parentAccount2 == null) {
108: Session session2 = transactionManager.getSession();
109: newUncommittedAccount = session2
110: .createAccount(accountPropertySet);
111: } else {
112: newUncommittedAccount = parentAccount2
113: .createSubAccount(accountPropertySet);
114: }
115: // PlatformUI.getWorkbench().getHelpSystem().setHelp(this.getContainer(), "com.toutvirtual.help.locationDialogId");
116: }
117:
118: @Override
119: public void addPages() {
120: // Show the page that prompts for all the property values.
121: WizardPage propertyPage = new WizardPropertyPage(
122: "propertyPage", "Account Properties",
123: "Enter values for the account properties",
124: newUncommittedAccount, accountPropertySet, AccountInfo
125: .getNameAccessor());
126: addPage(propertyPage);
127:
128: WizardPage summaryPage = new SummaryPage("summaryPage");
129: addPage(summaryPage);
130: }
131:
132: @Override
133: public boolean performFinish() {
134: // TODO: verify properties are valid.
135:
136: transactionManager.commit("Add New Account");
137:
138: newCommittedAccount = (Account) ((UncommittedObjectKey) newUncommittedAccount
139: .getObjectKey()).getCommittedObjectKey().getObject();
140:
141: return true;
142: }
143:
144: class SummaryPage extends WizardPage {
145:
146: SummaryPage(String pageName) {
147: super (pageName);
148: setTitle("Summary");
149: setMessage("");
150: }
151:
152: public void createControl(Composite parent) {
153: Composite container = new Composite(parent, SWT.NONE);
154:
155: GridLayout layout = new GridLayout();
156: layout.marginWidth = 10;
157: layout.marginHeight = 10;
158: container.setLayout(layout);
159:
160: GridData gd1 = new GridData();
161: gd1.grabExcessHorizontalSpace = true;
162: gd1.horizontalAlignment = SWT.FILL;
163: gd1.widthHint = 300;
164:
165: Label introText = new Label(container, SWT.WRAP);
166: introText
167: .setText("The account has been setup. To view the account, double click on the account in the navigation view.");
168: introText.setLayoutData(gd1);
169:
170: setControl(container);
171: }
172:
173: @Override
174: public void performHelp() {
175: MessageBox messageBox = new MessageBox(getShell(),
176: SWT.ICON_WARNING | SWT.OK);
177: messageBox
178: .setMessage("No help is available for this page.");
179: messageBox.open();
180: }
181: }
182:
183: public Account getNewAccount() {
184: return newCommittedAccount;
185: }
186: }
|