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.CurrencyControlFactory;
027:
028: /**
029: * This class is a listener class to the net.sf.jmoney.fields
030: * extension point. It implements an extension.
031: * <P>
032: * This extension registers the Entry properties. By registering
033: * the properties, every one can know how to display, edit, and store
034: * the properties.
035: * <P>
036: * These properties are supported in the JMoney base code, so everyone
037: * including plug-ins will know about these properties. However, to
038: * follow the Eclipse paradigm (every one should be treated equal,
039: * including oneself), these are registered through the same extension
040: * point that plug-ins must also use to register their properties.
041: *
042: * @author Nigel Westbury
043: * @author Johann Gyger
044: */
045: public class SessionInfo implements IPropertySetInfo {
046:
047: private static ExtendablePropertySet<Session> propertySet = PropertySet
048: .addBaseFinalPropertySet(Session.class, "JMoney Session",
049: new IExtendableObjectConstructors<Session>() {
050:
051: public Session construct(IObjectKey objectKey,
052: ListKey parentKey) {
053: return new Session(objectKey, parentKey);
054: }
055:
056: public Session construct(IObjectKey objectKey,
057: ListKey parentKey, IValues values) {
058: return new Session(
059: objectKey,
060: parentKey,
061: values
062: .getListManager(
063: objectKey,
064: SessionInfo
065: .getCommoditiesAccessor()),
066: values
067: .getListManager(
068: objectKey,
069: SessionInfo
070: .getAccountsAccessor()),
071: values
072: .getListManager(
073: objectKey,
074: SessionInfo
075: .getTransactionsAccessor()),
076: values
077: .getReferencedObjectKey(SessionInfo
078: .getDefaultCurrencyAccessor()),
079: values);
080: }
081: });
082:
083: private static ListPropertyAccessor<Commodity> commoditiesAccessor = null;
084: private static ListPropertyAccessor<Account> accountsAccessor = null;
085: private static ListPropertyAccessor<Transaction> transactionsAccessor = null;
086: private static ReferencePropertyAccessor<Currency> defaultCurrencyAccessor = null;
087:
088: public PropertySet registerProperties() {
089: IListGetter<Session, Commodity> commodityGetter = new IListGetter<Session, Commodity>() {
090: public ObjectCollection<Commodity> getList(
091: Session parentObject) {
092: return parentObject.getCommodityCollection();
093: }
094: };
095:
096: IListGetter<Session, Account> accountGetter = new IListGetter<Session, Account>() {
097: public ObjectCollection<Account> getList(
098: Session parentObject) {
099: return parentObject.getAccountCollection();
100: }
101: };
102:
103: IListGetter<Session, Transaction> transactionGetter = new IListGetter<Session, Transaction>() {
104: public ObjectCollection<Transaction> getList(
105: Session parentObject) {
106: return parentObject.getTransactionCollection();
107: }
108: };
109:
110: IReferenceControlFactory<Session, Currency> currencyControlFactory = new CurrencyControlFactory<Session>() {
111: public IObjectKey getObjectKey(Session parentObject) {
112: return parentObject.defaultCurrencyKey;
113: }
114: };
115:
116: commoditiesAccessor = propertySet.addPropertyList("commodity",
117: JMoneyPlugin.getResourceString("<not used???>"),
118: CommodityInfo.getPropertySet(), commodityGetter);
119: accountsAccessor = propertySet.addPropertyList("account",
120: JMoneyPlugin.getResourceString("<not used???>"),
121: AccountInfo.getPropertySet(), accountGetter);
122: transactionsAccessor = propertySet.addPropertyList(
123: "transaction", JMoneyPlugin
124: .getResourceString("<not used???>"),
125: TransactionInfo.getPropertySet(), transactionGetter);
126:
127: defaultCurrencyAccessor = propertySet.addProperty(
128: "defaultCurrency", JMoneyPlugin
129: .getResourceString("Session.defaultCurrency"),
130: Currency.class, 2, 20, currencyControlFactory, null);
131:
132: return propertySet;
133: }
134:
135: /**
136: * @return
137: */
138: public static ExtendablePropertySet<Session> getPropertySet() {
139: return propertySet;
140: }
141:
142: /**
143: * @return
144: */
145: public static ListPropertyAccessor<Commodity> getCommoditiesAccessor() {
146: return commoditiesAccessor;
147: }
148:
149: /**
150: * @return
151: */
152: public static ListPropertyAccessor<Account> getAccountsAccessor() {
153: return accountsAccessor;
154: }
155:
156: /**
157: * @return
158: */
159: public static ListPropertyAccessor<Transaction> getTransactionsAccessor() {
160: return transactionsAccessor;
161: }
162:
163: /**
164: * @return
165: */
166: public static ReferencePropertyAccessor<Currency> getDefaultCurrencyAccessor() {
167: return defaultCurrencyAccessor;
168: }
169: }
|