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.stocks;
024:
025: import java.util.Date;
026:
027: import net.sf.jmoney.fields.CheckBoxControlFactory;
028: import net.sf.jmoney.fields.DateControlFactory;
029: import net.sf.jmoney.model2.EntryInfo;
030: import net.sf.jmoney.model2.ExtendableObject;
031: import net.sf.jmoney.model2.ExtensionPropertySet;
032: import net.sf.jmoney.model2.IExtensionObjectConstructors;
033: import net.sf.jmoney.model2.IObjectKey;
034: import net.sf.jmoney.model2.IPropertyControlFactory;
035: import net.sf.jmoney.model2.IPropertySetInfo;
036: import net.sf.jmoney.model2.IReferenceControlFactory;
037: import net.sf.jmoney.model2.IValues;
038: import net.sf.jmoney.model2.PropertySet;
039: import net.sf.jmoney.model2.ReferencePropertyAccessor;
040: import net.sf.jmoney.model2.ScalarPropertyAccessor;
041:
042: /**
043: * Add extra properties to the Entry objects that are entries of amounts
044: * of a stock or bond.
045: *
046: * An entry for an amount of a stock or bond exists any time the number of
047: * a particular stock in an account changes. This can happen when a stock
048: * is acquired in any way, disposed of in any way, or transfered from one
049: * account to another.
050: * <P>
051: * The entry will contain the amount of the stock. This amount is kept in
052: * the base Amount property field. The entry will also contain the particular
053: * stock or bond concerned. In the case of, for example, the bank account
054: * entries, the currency is not kept in the entry but is kept in the account
055: * object. However, a stock account will usually contain stock in many different
056: * companies (unless it is your employee stock purchase plan account).
057: * Therefore a reference to the stock Commodity
058: * object is kept in the Entry object.
059: * <P>
060: * @author Nigel Westbury
061: */
062: public class StockEntryInfo implements IPropertySetInfo {
063:
064: private static ExtensionPropertySet<StockEntry> propertySet = PropertySet
065: .addExtensionPropertySet(StockEntry.class, EntryInfo
066: .getPropertySet(),
067: new IExtensionObjectConstructors<StockEntry>() {
068:
069: public StockEntry construct(
070: ExtendableObject extendedObject) {
071: return new StockEntry(extendedObject);
072: }
073:
074: public StockEntry construct(
075: ExtendableObject extendedObject,
076: IValues values) {
077: return new StockEntry(
078: extendedObject,
079: values
080: .getScalarValue(getStockChangeAccessor()),
081: values
082: .getReferencedObjectKey(getStockAccessor()),
083: values
084: .getScalarValue(getBargainDateAccessor()));
085: }
086: });
087:
088: private static ScalarPropertyAccessor<Boolean> stockChangeAccessor;
089: private static ReferencePropertyAccessor<Stock> stockAccessor;
090: private static ScalarPropertyAccessor<Date> bargainDateAccessor;
091:
092: public PropertySet registerProperties() {
093: StockEntryInfo.propertySet = propertySet;
094:
095: IPropertyControlFactory<Boolean> booleanPropertyControlFactory = new CheckBoxControlFactory();
096:
097: IReferenceControlFactory<StockEntry, Stock> stockPropertyControlFactory = new StockControlFactory<StockEntry>() {
098: public IObjectKey getObjectKey(StockEntry parentObject) {
099: return parentObject.stockKey;
100: }
101: };
102:
103: IPropertyControlFactory<Date> datePropertyControlFactory = new DateControlFactory();
104:
105: stockChangeAccessor = propertySet.addProperty("stockChange",
106: "Stock Acquisition/Disposal", Boolean.class, 0, 15,
107: booleanPropertyControlFactory, null);
108: stockAccessor = propertySet.addProperty("stock", "Stock",
109: Stock.class, 2, 20, stockPropertyControlFactory, null);
110: bargainDateAccessor = propertySet.addProperty("bargainDate",
111: "Bargain Date", Date.class, 0, 20,
112: datePropertyControlFactory, null);
113:
114: return propertySet;
115: }
116:
117: /**
118: * @return
119: */
120: public static ExtensionPropertySet<StockEntry> getPropertySet() {
121: return propertySet;
122: }
123:
124: /**
125: * @return
126: */
127: public static ScalarPropertyAccessor<Boolean> getStockChangeAccessor() {
128: return stockChangeAccessor;
129: }
130:
131: /**
132: * @return
133: */
134: public static ReferencePropertyAccessor<Stock> getStockAccessor() {
135: return stockAccessor;
136: }
137:
138: /**
139: * @return
140: */
141: public static ScalarPropertyAccessor<Date> getBargainDateAccessor() {
142: return bargainDateAccessor;
143: }
144: }
|