001: /*
002: *
003: * JMoney - A Personal Finance Manager
004: * Copyright (c) 2006 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.reconciliation;
024:
025: import net.sf.jmoney.model2.CurrencyAccountExtension;
026: import net.sf.jmoney.model2.ExtendableObject;
027: import net.sf.jmoney.model2.IListManager;
028: import net.sf.jmoney.model2.IObjectKey;
029: import net.sf.jmoney.model2.IncomeExpenseAccount;
030: import net.sf.jmoney.model2.ObjectCollection;
031:
032: /**
033: * An extension object that extends BankAccount objects.
034: * This extension object maintains the values of the properties
035: * that have been added by this plug-in.
036: *
037: * @author Nigel Westbury
038: */
039: public class ReconciliationAccount extends CurrencyAccountExtension {
040:
041: protected boolean reconcilable = false;
042:
043: protected IListManager<MemoPattern> patterns;
044:
045: IObjectKey defaultCategoryKey = null;
046:
047: /**
048: * A default constructor is mandatory for all extension objects.
049: * The default constructor sets the extension properties to
050: * appropriate default values.
051: */
052: public ReconciliationAccount(ExtendableObject extendedObject) {
053: super (extendedObject);
054: this .patterns = extendedObject
055: .getObjectKey()
056: .constructListManager(
057: ReconciliationAccountInfo.getPatternsAccessor());
058: }
059:
060: /**
061: * A Full constructor is mandatory for all extension objects.
062: * This constructor is called by the datastore to construct
063: * the extension objects when loading data.
064: *
065: */
066: public ReconciliationAccount(ExtendableObject extendedObject,
067: boolean reconcilable, IListManager<MemoPattern> patterns,
068: IObjectKey defaultCategoryKey) {
069: super (extendedObject);
070: this .reconcilable = reconcilable;
071: this .patterns = patterns;
072: this .defaultCategoryKey = defaultCategoryKey;
073: }
074:
075: /**
076: * Indicates if an account is reconcilable. If it is not then none
077: * of the other properties are applicable.
078: */
079: public boolean isReconcilable() {
080: return reconcilable;
081: }
082:
083: /**
084: * Returns the default income and expense account.
085: *
086: * @return the income and expense account to be given initially
087: * to all entries imported for this account
088: */
089: public IncomeExpenseAccount getDefaultCategory() {
090: return defaultCategoryKey == null ? null
091: : (IncomeExpenseAccount) defaultCategoryKey.getObject();
092: }
093:
094: /**
095: * Sets the reconcilable flag.
096: */
097: public void setReconcilable(boolean reconcilable) {
098: boolean oldReconcilable = this .reconcilable;
099: this .reconcilable = reconcilable;
100: processPropertyChange(ReconciliationAccountInfo
101: .getReconcilableAccessor(),
102: new Boolean(oldReconcilable), new Boolean(reconcilable));
103: }
104:
105: /**
106: * Sets the default category.
107: */
108: public void setDefaultCategory(IncomeExpenseAccount defaultCategory) {
109: IncomeExpenseAccount oldDefaultCategory = getDefaultCategory();
110: this .defaultCategoryKey = defaultCategory == null ? null
111: : defaultCategory.getObjectKey();
112:
113: // Notify the change manager.
114: processPropertyChange(ReconciliationAccountInfo
115: .getDefaultCategoryAccessor(), oldDefaultCategory,
116: defaultCategory);
117: }
118:
119: public ObjectCollection<MemoPattern> getPatternCollection() {
120: return new ObjectCollection<MemoPattern>(patterns,
121: getBaseObject(), ReconciliationAccountInfo
122: .getPatternsAccessor());
123: }
124: }
|