01: /* DateFieldFactory.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: May 15, 2007 3:19:17 PM, Created by henrichen
10: }}IS_NOTE
11:
12: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.zkmob.factory;
20:
21: import java.util.Date;
22: import java.util.TimeZone;
23:
24: import org.xml.sax.Attributes;
25: import org.zkoss.zkmob.ZkComponent;
26: import org.zkoss.zkmob.UiManager;
27: import org.zkoss.zkmob.ui.ZkDesktop;
28: import org.zkoss.zkmob.ui.ZkDateField;
29:
30: /**
31: * An UiFactory that create a DateField Ui component.
32: * @author henrichen
33: *
34: */
35: public class DateFieldFactory extends AbstractUiFactory {
36: public DateFieldFactory(String name) {
37: super (name);
38: }
39:
40: public ZkComponent create(ZkComponent parent, String tag,
41: Attributes attrs, String hostURL, String pathURL) {
42: final String id = attrs.getValue("id"); //id
43: final String label = attrs.getValue("lb"); //label
44: final String modeStr = attrs.getValue("md"); //mode
45: final String dateStr = attrs.getValue("dt"); //date
46: // final String tzid = attrs.getValue("tz"); //timezone
47: //The JavaME TimeZone support is poor.
48: //Always use GMT timezone and calculate the correct date in ZK server
49: final TimeZone tz = TimeZone.getTimeZone("GMT");
50: final int mode = Integer.parseInt(modeStr);
51: final String onChange = attrs.getValue("on");
52: final ZkDesktop zk = ((ZkComponent) parent).getZkDesktop();
53:
54: final ZkDateField component = new ZkDateField(zk, id, label,
55: mode, tz, onChange == null ? null : new Boolean("t"
56: .equals(onChange)));
57: if (dateStr != null) {
58: final long time = Long.parseLong(dateStr);
59: component.setDate(new Date(time));
60: }
61:
62: UiManager.applyItemProperties(parent, component, attrs);
63:
64: return component;
65: }
66: }
|