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 DateUI
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 if (_fieldValue.getValue() instanceof DateTime) {
54 final DateTime datetime = (DateTime) _fieldValue.getValue();
55 if (datetime != null) {
56
57
58 final DateTime dateTmp = new DateTime().withTimeAtStartOfDay()
59 .withYear(datetime.getYear())
60 .withMonthOfYear(datetime.getMonthOfYear())
61 .withDayOfMonth(datetime.getDayOfMonth())
62 .withChronology(Context.getThreadContext().getChronology());
63
64 final DateTimeFormatter formatter = DateTimeFormat.mediumDate();
65
66 ret = dateTmp.toString(formatter.withLocale(Context.getThreadContext().getLocale()));
67 }
68 } else if (_fieldValue.getValue() instanceof String) {
69 ret = (String) _fieldValue.getValue();
70 } else if (_fieldValue.getValue() != null) {
71 throw new EFapsException(this.getClass(), "getViewHtml.noDateTime", (Object[]) null);
72 }
73 return ret;
74 }
75
76
77
78
79 @Override
80 public String getStringValue(final FieldValue _fieldValue)
81 throws EFapsException
82 {
83 String ret = null;
84 if (_fieldValue.getValue() != null) {
85 ret = _fieldValue.getValue().toString();
86 }
87 return ret;
88 }
89
90
91
92
93 @Override
94 public Object getObject4Compare(final FieldValue _fieldValue)
95 throws EFapsException
96 {
97 Object ret;
98 if (_fieldValue != null && _fieldValue.getValue() instanceof DateTime) {
99 final DateTime datetime = (DateTime) _fieldValue.getValue();
100 ret = new DateTime().withTimeAtStartOfDay()
101 .withYear(datetime.getYear())
102 .withMonthOfYear(datetime.getMonthOfYear())
103 .withDayOfMonth(datetime.getDayOfMonth())
104 .withChronology(Context.getThreadContext().getChronology());
105 } else {
106 ret = _fieldValue.getValue();
107 }
108 return ret;
109 }
110
111
112
113
114 @Override
115 public int compare(final FieldValue _fieldValue,
116 final FieldValue _fieldValue2)
117 {
118 int ret = 0;
119 if (_fieldValue.getValue() instanceof DateTime && _fieldValue2.getValue() instanceof DateTime) {
120 ret = DateTimeComparator.getDateOnlyInstance().compare(_fieldValue.getValue(), _fieldValue2.getValue());
121 }
122 return ret;
123 }
124
125
126
127
128 @Override
129 public Object format(final Object _object,
130 final String _pattern)
131 throws EFapsException
132 {
133 Object ret;
134 if (_object instanceof DateTime) {
135 ret = ((DateTime) _object).toString(_pattern, Context.getThreadContext().getLocale());
136 } else {
137 ret = _object;
138 }
139 return ret;
140 }
141 }