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 java.util.Comparator;
026:
027: import org.eclipse.swt.widgets.Composite;
028:
029: /**
030: * @param V the type of the value that can be edited by the controls
031: * produced by this factory
032: *
033: * @author Nigel
034: *
035: */
036: public interface IPropertyControlFactory<V> {
037: /**
038: * Create a control that edits the property.
039: * <P>
040: * The PropertyAccessor object is not known when the factory
041: * is created so we require that it is passed as a parameter
042: * when a control is created.
043:
044: * @return An interface to the class that wraps the
045: * control.
046: */
047: IPropertyControl createPropertyControl(Composite parent,
048: ScalarPropertyAccessor<V> propertyAccessor);
049:
050: /**
051: * Format the value of a property so it can be embedded into a
052: * message.
053: *
054: * The returned value must look sensible when embedded in a message.
055: * Therefore null values and empty values must return non-empty
056: * text such as "none" or "empty". Text values should be placed in
057: * quotes unless sure that only a single word will be returned that
058: * would be readable without quotes.
059: *
060: * @return The value of the property formatted as appropriate.
061: */
062: String formatValueForMessage(ExtendableObject extendableObject,
063: ScalarPropertyAccessor<? extends V> propertyAccessor);
064:
065: /**
066: * Format the value of a property as appropriate for displaying in a
067: * table.
068: *
069: * The returned value will be displayed in a table or some similar
070: * view. Null and empty values should be returned as empty strings.
071: * Text values should not be quoted.
072: *
073: * @return The value of the property formatted as appropriate.
074: */
075: String formatValueForTable(ExtendableObject extendableObject,
076: ScalarPropertyAccessor<? extends V> propertyAccessor);
077:
078: /**
079: * Indicates if the property is editable. If the property
080: * is editable then the <code>createPropertyControl</code>
081: * method must create and return a valid property. If the
082: * property is not editable then the <code>createPropertyControl</code>
083: * method will never be called by the framework.
084: * <P>
085: * Most properties will be editable. However some properties,
086: * such as the creation date for each entry, cannot be edited
087: * by the user. The rest of this interface must still be implemented
088: * so that the values can be formatted correctly for displaying
089: * to the user.
090: *
091: * @return true if a control is provided to allow the user to
092: * edit the property, false if the user cannot edit
093: * the property
094: */
095: // TODO: Determine if this method should be removed. If a property
096: // is not to be edited then a non-editable control, such as a Label,
097: // can be created as the editing control.
098: boolean isEditable();
099:
100: /**
101: * The default value for a property is suitable for uses such
102: * as:
103: *
104: * - setting the default columnn value in a database
105: * - providing values when the value is missing from an
106: * XML file
107: *
108: * It is expected that this value is constant (the same value
109: * is always returned for a given property). The results will
110: * be unpredicable if this is not the case.
111: *
112: * @return the default value to use for this property, which may
113: * be null if the property is of a nullable type
114: */
115: V getDefaultValue();
116:
117: /**
118: * Many views allow sorting based on property values. This method
119: * allows the comparator to be used for sorting to be specified.
120: *
121: * @return a comparator if sorting is to be allowed, or null if sorting
122: * based on this property is not to be allowed
123: */
124: Comparator<V> getComparator();
125: }
|