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.TextControlFactory;
027:
028: import org.eclipse.swt.widgets.Composite;
029:
030: /**
031: * This class is a listener class to the net.sf.jmoney.fields
032: * extension point. It implements an extension.
033: * <P>
034: * This extension registers the Entry properties. By registering
035: * the properties, every one can know how to display, edit, and store
036: * the properties.
037: * <P>
038: * These properties are supported in the JMoney base code, so everyone
039: * including plug-ins will know about these properties. However, to
040: * follow the Eclipse paradigm (every one should be treated equal,
041: * including oneself), these are registered through the same extension
042: * point that plug-ins must also use to register their properties.
043: *
044: * @author Nigel Westbury
045: * @author Johann Gyger
046: */
047: public class CurrencyInfo implements IPropertySetInfo {
048:
049: private static ExtendablePropertySet<Currency> propertySet = PropertySet
050: .addDerivedFinalPropertySet(Currency.class, "Currency",
051: CommodityInfo.getPropertySet(),
052: new IExtendableObjectConstructors<Currency>() {
053:
054: public Currency construct(IObjectKey objectKey,
055: ListKey parentKey) {
056: return new Currency(objectKey, parentKey);
057: }
058:
059: public Currency construct(IObjectKey objectKey,
060: ListKey parentKey, IValues values) {
061: return new Currency(objectKey, parentKey,
062: values.getScalarValue(CommodityInfo
063: .getNameAccessor()),
064: values.getScalarValue(CurrencyInfo
065: .getCodeAccessor()),
066: values.getScalarValue(CurrencyInfo
067: .getDecimalsAccessor()),
068: values);
069: }
070: });
071:
072: private static ScalarPropertyAccessor<String> codeAccessor = null;
073: private static ScalarPropertyAccessor<Integer> decimalsAccessor = null;
074:
075: public PropertySet registerProperties() {
076: IPropertyControlFactory<String> textControlFactory = new TextControlFactory();
077:
078: IPropertyControlFactory<Integer> numberControlFactory = new PropertyControlFactory<Integer>() {
079: public IPropertyControl createPropertyControl(
080: Composite parent,
081: ScalarPropertyAccessor<Integer> propertyAccessor) {
082: // Property is not editable
083: return null;
084: }
085:
086: public Integer getDefaultValue() {
087: return 0;
088: }
089:
090: public boolean isEditable() {
091: return false;
092: }
093: };
094:
095: codeAccessor = propertySet.addProperty("code", JMoneyPlugin
096: .getResourceString("Currency.code"), String.class, 0,
097: 8, textControlFactory, null);
098: decimalsAccessor = propertySet.addProperty("decimals",
099: JMoneyPlugin.getResourceString("Currency.decimals"),
100: Integer.class, 0, 8, numberControlFactory, null);
101:
102: return propertySet;
103: }
104:
105: /**
106: * @return
107: */
108: public static ExtendablePropertySet<Currency> getPropertySet() {
109: return propertySet;
110: }
111:
112: /**
113: * @return
114: */
115: public static ScalarPropertyAccessor<String> getCodeAccessor() {
116: return codeAccessor;
117: }
118:
119: /**
120: * @return
121: */
122: public static ScalarPropertyAccessor<Integer> getDecimalsAccessor() {
123: return decimalsAccessor;
124: }
125: }
|