1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.efaps.admin.datamodel.ui;
22
23 import org.efaps.db.Context;
24 import org.efaps.util.EFapsException;
25 import org.joda.time.DateTime;
26 import org.joda.time.DateTimeComparator;
27 import org.joda.time.format.DateTimeFormat;
28 import org.joda.time.format.DateTimeFormatter;
29
30
31
32
33
34
35
36 public class DateTimeUI
37 extends AbstractUI
38 {
39
40
41
42
43 private static final long serialVersionUID = 1L;
44
45
46
47
48 @Override
49 public String getReadOnlyHtml(final FieldValue _fieldValue)
50 throws EFapsException
51 {
52 String ret = null;
53
54 if (_fieldValue.getValue() instanceof DateTime) {
55 final DateTime datetime = (DateTime) _fieldValue.getValue();
56 if (datetime != null) {
57 final DateTimeFormatter formatter = DateTimeFormat.mediumDateTime();
58
59
60 ret = datetime.withChronology(Context.getThreadContext().getChronology()).toString(
61 formatter.withLocale(Context.getThreadContext().getLocale()));
62 }
63 } else if (_fieldValue.getValue() instanceof String) {
64 ret = (String) _fieldValue.getValue();
65 } else if (_fieldValue.getValue() != null) {
66 throw new EFapsException(this.getClass(), "getViewHtml.noDateTime", (Object[]) null);
67 }
68 return ret;
69 }
70
71
72
73
74 @Override
75 public String getStringValue(final FieldValue _fieldValue)
76 throws EFapsException
77 {
78 String ret = null;
79 if (_fieldValue.getValue() != null) {
80 ret = _fieldValue.getValue().toString();
81 }
82 return ret;
83 }
84
85
86
87
88 @Override
89 public Object getObject4Compare(final FieldValue _fieldValue)
90 throws EFapsException
91 {
92 Object ret;
93 if (_fieldValue != null && _fieldValue.getValue() instanceof DateTime) {
94 final DateTime datetime = (DateTime) _fieldValue.getValue();
95 ret = datetime.withChronology(Context.getThreadContext().getChronology());
96 } else {
97 ret = _fieldValue.getValue();
98 }
99 return ret;
100 }
101
102
103
104
105 @Override
106 public int compare(final FieldValue _fieldValue,
107 final FieldValue _fieldValue2)
108 {
109 int ret = 0;
110 if (_fieldValue.getValue() instanceof DateTime && _fieldValue2.getValue() instanceof DateTime) {
111 ret = DateTimeComparator.getInstance().compare(_fieldValue.getValue(), _fieldValue2.getValue());
112 }
113 return ret;
114 }
115
116
117
118
119 @Override
120 public Object format(final Object _object,
121 final String _pattern)
122 throws EFapsException
123 {
124 Object ret;
125 if (_object instanceof DateTime) {
126 ret = ((DateTime) _object).toString(_pattern, Context.getThreadContext().getLocale());
127 } else {
128 ret = _object;
129 }
130 return ret;
131 }
132 }