001: /* *************************************************************************
002:
003: Millstone(TM)
004: Open Sourced User Interface Library for
005: Internet Development with Java
006:
007: Millstone is a registered trademark of IT Mill Ltd
008: Copyright (C) 2000-2005 IT Mill Ltd
009:
010: *************************************************************************
011:
012: This library is free software; you can redistribute it and/or
013: modify it under the terms of the GNU Lesser General Public
014: license version 2.1 as published by the Free Software Foundation.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: *************************************************************************
026:
027: For more information, contact:
028:
029: IT Mill Ltd phone: +358 2 4802 7180
030: Ruukinkatu 2-4 fax: +358 2 4802 7181
031: 20540, Turku email: info@itmill.com
032: Finland company www: www.itmill.com
033:
034: Primary source for MillStone information and releases: www.millstone.org
035:
036: ********************************************************************** */
037:
038: package org.millstone.base.ui;
039:
040: import java.util.Date;
041:
042: import org.millstone.base.data.Container;
043: import org.millstone.base.data.Item;
044: import org.millstone.base.data.Property;
045:
046: /** Default implementation of the
047:
048: *
049: *
050: * The following Field types are used by default:
051: * <p>
052: * <b>Boolean</b>: Button(switchMode:true)<br/>
053: * <b>Date</b>: DateField(resolution: day)
054: * <b>Item</b>: Form<br/>
055: * <b>default field type</b>: TextField
056: * <p>
057: * @author IT Mill Ltd.
058: * @version 3.1.1
059: * @since 3.1
060: */
061:
062: public class BaseFieldFactory implements FieldFactory {
063:
064: /** Creates field based on type of data.
065: *
066: *
067: * @param type The type of data presented in field
068: * @param uiContext The context where the Field is presented.
069: *
070: * @see org.millstone.base.ui.FieldFactory#createField(Class, Component)
071: */
072: public Field createField(Class type, Component uiContext) {
073: // Null typed properties can not be edited
074: if (type == null)
075: return null;
076:
077: // Item field
078: if (Item.class.isAssignableFrom(type)) {
079: return new Form();
080: }
081:
082: // Date field
083: if (Date.class.isAssignableFrom(type)) {
084: DateField df = new DateField();
085: df.setResolution(DateField.RESOLUTION_DAY);
086: return df;
087: }
088:
089: // Boolean field
090: if (Boolean.class.isAssignableFrom(type)) {
091: Button button = new Button();
092: button.setSwitchMode(true);
093: button.setImmediate(false);
094: return button;
095: }
096:
097: // Nested form is used by default
098: return new TextField();
099: }
100:
101: /** Create field based on the datasource property.
102: *
103: * @see org.millstone.base.ui.FieldFactory#createField(Property, Component)
104: */
105: public Field createField(Property property, Component uiContext) {
106: if (property != null)
107: return createField(property.getType(), uiContext);
108: else
109: return null;
110: }
111:
112: /** Creates field based on the item and property id.
113: *
114: * @see org.millstone.base.ui.FieldFactory#createField(Item, Object, Component)
115: */
116: public Field createField(Item item, Object propertyId,
117: Component uiContext) {
118: if (item != null && propertyId != null) {
119: Field f = createField(item.getItemProperty(propertyId),
120: uiContext);
121: if (f instanceof AbstractComponent)
122: ((AbstractComponent) f).setCaption(propertyId
123: .toString());
124: return f;
125: } else
126: return null;
127: }
128:
129: /**
130: * @see org.millstone.base.ui.FieldFactory#createField(org.millstone.base.data.Container, java.lang.Object, java.lang.Object, org.millstone.base.ui.Component)
131: */
132: public Field createField(Container container, Object itemId,
133: Object propertyId, Component uiContext) {
134: return createField(container.getContainerProperty(itemId,
135: propertyId), uiContext);
136: }
137:
138: }
|