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.JMoneyPlugin;
026: import net.sf.jmoney.fields.AccountControlFactory;
027: import net.sf.jmoney.fields.CheckBoxControlFactory;
028: import net.sf.jmoney.model2.CurrencyAccountInfo;
029: import net.sf.jmoney.model2.ExtendableObject;
030: import net.sf.jmoney.model2.ExtensionPropertySet;
031: import net.sf.jmoney.model2.IExtensionObjectConstructors;
032: import net.sf.jmoney.model2.IListGetter;
033: import net.sf.jmoney.model2.IObjectKey;
034: import net.sf.jmoney.model2.IPropertySetInfo;
035: import net.sf.jmoney.model2.IValues;
036: import net.sf.jmoney.model2.IncomeExpenseAccount;
037: import net.sf.jmoney.model2.ListPropertyAccessor;
038: import net.sf.jmoney.model2.ObjectCollection;
039: import net.sf.jmoney.model2.PropertySet;
040: import net.sf.jmoney.model2.ReferencePropertyAccessor;
041: import net.sf.jmoney.model2.ScalarPropertyAccessor;
042:
043: /**
044: * Provides the metadata for the extra properties added to each
045: * currency account by this plug-in.
046: *
047: * @author Nigel Westbury
048: */
049: public class ReconciliationAccountInfo implements IPropertySetInfo {
050:
051: private static ExtensionPropertySet<ReconciliationAccount> propertySet = PropertySet
052: .addExtensionPropertySet(
053: ReconciliationAccount.class,
054: CurrencyAccountInfo.getPropertySet(),
055: new IExtensionObjectConstructors<ReconciliationAccount>() {
056:
057: public ReconciliationAccount construct(
058: ExtendableObject extendedObject) {
059: return new ReconciliationAccount(
060: extendedObject);
061: }
062:
063: public ReconciliationAccount construct(
064: ExtendableObject extendedObject,
065: IValues values) {
066: return new ReconciliationAccount(
067: extendedObject,
068: values
069: .getScalarValue(getReconcilableAccessor()),
070: values.getListManager(
071: extendedObject
072: .getObjectKey(),
073: getPatternsAccessor()),
074: values
075: .getReferencedObjectKey(getDefaultCategoryAccessor()));
076: }
077: });
078:
079: private static ScalarPropertyAccessor<Boolean> reconcilableAccessor = null;
080: private static ReferencePropertyAccessor<IncomeExpenseAccount> defaultCategoryAccessor = null;
081: private static ListPropertyAccessor<MemoPattern> patternsAccessor = null;
082:
083: public PropertySet registerProperties() {
084: AccountControlFactory<ReconciliationAccount, IncomeExpenseAccount> accountControlFactory = new AccountControlFactory<ReconciliationAccount, IncomeExpenseAccount>() {
085: public IObjectKey getObjectKey(
086: ReconciliationAccount parentObject) {
087: return parentObject.defaultCategoryKey;
088: }
089: };
090:
091: IListGetter<ReconciliationAccount, MemoPattern> patternListGetter = new IListGetter<ReconciliationAccount, MemoPattern>() {
092: public ObjectCollection<MemoPattern> getList(
093: ReconciliationAccount parentObject) {
094: return parentObject.getPatternCollection();
095: }
096: };
097:
098: reconcilableAccessor = propertySet
099: .addProperty("reconcilable", ReconciliationPlugin
100: .getResourceString("Account.isReconcilable"),
101: Boolean.class, 1, 5,
102: new CheckBoxControlFactory(), null);
103: patternsAccessor = propertySet.addPropertyList("patterns",
104: JMoneyPlugin.getResourceString("<not used???>"),
105: MemoPatternInfo.getPropertySet(), patternListGetter);
106: defaultCategoryAccessor = propertySet.addProperty(
107: "defaultCategory", ReconciliationPlugin
108: .getResourceString("Account.defaultCategory"),
109: IncomeExpenseAccount.class, 1, 20,
110: accountControlFactory, null);
111:
112: return propertySet;
113: }
114:
115: /**
116: * @return
117: */
118: public static ExtensionPropertySet<ReconciliationAccount> getPropertySet() {
119: return propertySet;
120: }
121:
122: /**
123: * @return
124: */
125: public static ScalarPropertyAccessor<Boolean> getReconcilableAccessor() {
126: return reconcilableAccessor;
127: }
128:
129: /**
130: * @return
131: */
132: public static ListPropertyAccessor<MemoPattern> getPatternsAccessor() {
133: return patternsAccessor;
134: }
135:
136: /**
137: * @return
138: */
139: public static ReferencePropertyAccessor<IncomeExpenseAccount> getDefaultCategoryAccessor() {
140: return defaultCategoryAccessor;
141: }
142: }
|