001: /*
002: *
003: * JMoney - A Personal Finance Manager
004: * Copyright (c) 2004 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.model2;
024:
025: import net.sf.jmoney.JMoneyPlugin;
026: import net.sf.jmoney.fields.CheckBoxControlFactory;
027: import net.sf.jmoney.fields.CurrencyControlFactory;
028:
029: /**
030: * This class is a listener class to the net.sf.jmoney.fields
031: * extension point. It implements an extension.
032: * <P>
033: * This extension registers the IncomeExpenseAccount properties. By registering
034: * the properties, every one can know how to display, edit, and store
035: * the properties.
036: * <P>
037: * These properties are supported in the JMoney base code, so everyone
038: * including plug-ins will know about these properties. However, to
039: * follow the Eclipse paradigm (every one should be treated equal,
040: * including oneself), these are registered through the same extension
041: * point that plug-ins must also use to register their properties.
042: *
043: * @author Nigel Westbury
044: */
045: public class IncomeExpenseAccountInfo implements IPropertySetInfo {
046:
047: private static ExtendablePropertySet<IncomeExpenseAccount> propertySet = PropertySet
048: .addDerivedFinalPropertySet(
049: IncomeExpenseAccount.class,
050: "Income or Expense Category",
051: AccountInfo.getPropertySet(),
052: new IExtendableObjectConstructors<IncomeExpenseAccount>() {
053:
054: public IncomeExpenseAccount construct(
055: IObjectKey objectKey, ListKey parentKey) {
056: return new IncomeExpenseAccount(objectKey,
057: parentKey);
058: }
059:
060: public IncomeExpenseAccount construct(
061: IObjectKey objectKey,
062: ListKey parentKey, IValues values) {
063: return new IncomeExpenseAccount(
064: objectKey,
065: parentKey,
066: values.getScalarValue(AccountInfo
067: .getNameAccessor()),
068: values
069: .getListManager(
070: objectKey,
071: IncomeExpenseAccountInfo
072: .getSubAccountAccessor()),
073: values
074: .getScalarValue(IncomeExpenseAccountInfo
075: .getMultiCurrencyAccessor()),
076: values
077: .getReferencedObjectKey(IncomeExpenseAccountInfo
078: .getCurrencyAccessor()),
079: values);
080: }
081: });
082:
083: private static ListPropertyAccessor<IncomeExpenseAccount> subAccountAccessor = null;
084: private static ScalarPropertyAccessor<Boolean> multiCurrencyAccessor = null;
085: private static ReferencePropertyAccessor<Currency> currencyAccessor = null;
086:
087: public PropertySet registerProperties() {
088: IListGetter<IncomeExpenseAccount, IncomeExpenseAccount> accountGetter = new IListGetter<IncomeExpenseAccount, IncomeExpenseAccount>() {
089: public ObjectCollection<IncomeExpenseAccount> getList(
090: IncomeExpenseAccount parentObject) {
091: return parentObject.getSubAccountCollection();
092: }
093: };
094:
095: IReferenceControlFactory<IncomeExpenseAccount, Currency> currencyControlFactory = new CurrencyControlFactory<IncomeExpenseAccount>() {
096: public IObjectKey getObjectKey(
097: IncomeExpenseAccount parentObject) {
098: return parentObject.currencyKey;
099: }
100: };
101:
102: IPropertyDependency<IncomeExpenseAccount> onlyIfSingleCurrency = new IPropertyDependency<IncomeExpenseAccount>() {
103: public boolean isApplicable(IncomeExpenseAccount account) {
104: return !account.isMultiCurrency();
105: }
106: };
107:
108: subAccountAccessor = propertySet.addPropertyList("subAccount",
109: JMoneyPlugin.getResourceString("<not used???>"),
110: IncomeExpenseAccountInfo.getPropertySet(),
111: accountGetter);
112: multiCurrencyAccessor = propertySet
113: .addProperty(
114: "multiCurrency",
115: JMoneyPlugin
116: .getResourceString("AccountPropertiesPanel.multiCurrency"),
117: Boolean.class, 0, 10,
118: new CheckBoxControlFactory(), null);
119: currencyAccessor = propertySet
120: .addProperty(
121: "currency",
122: JMoneyPlugin
123: .getResourceString("AccountPropertiesPanel.currency"),
124: Currency.class, 2, 20, currencyControlFactory,
125: onlyIfSingleCurrency);
126:
127: // We should define something for the implied enumerated value
128: // that is controlled by the derived class type. This has not
129: // been designed yet, so for time being we have nothing to do.
130:
131: propertySet.setIcon("icons/category.gif");
132:
133: return propertySet;
134: }
135:
136: /**
137: * @return
138: */
139: public static ExtendablePropertySet<IncomeExpenseAccount> getPropertySet() {
140: return propertySet;
141: }
142:
143: /**
144: * @return
145: */
146: public static ListPropertyAccessor<IncomeExpenseAccount> getSubAccountAccessor() {
147: return subAccountAccessor;
148: }
149:
150: /**
151: * @return
152: */
153: public static ScalarPropertyAccessor<Boolean> getMultiCurrencyAccessor() {
154: return multiCurrencyAccessor;
155: }
156:
157: /**
158: * @return
159: */
160: public static ReferencePropertyAccessor<Currency> getCurrencyAccessor() {
161: return currencyAccessor;
162: }
163: }
|