01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.uilib.form.control;
16:
17: import org.araneaframework.uilib.ConfigurationContext;
18: import org.araneaframework.uilib.support.UiLibMessages;
19: import org.araneaframework.uilib.util.MessageUtil;
20:
21: /**
22: * This class represents a {@link org.araneaframework.uilib.form.control.TimestampControl}, that holds only time - that is
23: * it's default pattern is "HH:mm".
24: *
25: * @author <a href="mailto:ekabanov@webmedia.ee">Jevgeni Kabanov </a>
26: */
27: public class TimeControl extends TimestampControl {
28:
29: /**
30: * This is the default time format for this control.
31: */
32: public final static String DEFAULT_FORMAT = "HH:mm";
33:
34: /**
35: * Creates the control initializing the pattern to {@link #DEFAULT_FORMAT}.
36: */
37: public TimeControl() {
38: super (DEFAULT_FORMAT, DEFAULT_FORMAT);
39: }
40:
41: /**
42: * Creates the control initializing the pattern to <code>dateTimeFormat</code>.
43: *
44: * @param dateTimeFormat the custom pattern.
45: */
46: public TimeControl(String dateTimeFormat,
47: String defaultTimeOutputFormat) {
48: super (dateTimeFormat, defaultTimeOutputFormat);
49:
50: confOverridden = true;
51: }
52:
53: /**
54: * Returns "Timestamp".
55: *
56: * @return "Timestamp".
57: */
58: public String getRawValueType() {
59: return "Timestamp";
60: }
61:
62: public void init() throws Exception {
63: super .init();
64: if (!confOverridden) {
65: ConfigurationContext confCtx = (ConfigurationContext) getEnvironment()
66: .getEntry(ConfigurationContext.class);
67:
68: if (confCtx != null) {
69: String confFormat = (String) confCtx
70: .getEntry(ConfigurationContext.CUSTOM_TIME_FORMAT);
71: if (confFormat != null)
72: dateTimeInputPattern = confFormat;
73:
74: String confOutputFormat = (String) confCtx
75: .getEntry(ConfigurationContext.DEFAULT_TIME_OUTPUT_FORMAT);
76: if (confOutputFormat != null)
77: dateTimeOutputPattern = confOutputFormat;
78: }
79: }
80: }
81:
82: //*********************************************************************
83: //* INTERNAL METHODS
84: //*********************************************************************
85:
86: /** @since 1.1 */
87: protected void addWrongTimeFormatError() {
88: addError(MessageUtil.localizeAndFormat(
89: UiLibMessages.WRONG_TIME_FORMAT, MessageUtil.localize(
90: getLabel(), getEnvironment()),
91: dateTimeInputPattern, getEnvironment()));
92: }
93: }
|