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 java.text.DecimalFormat;
24 import java.text.NumberFormat;
25
26 import org.efaps.admin.dbproperty.DBProperties;
27 import org.efaps.db.Context;
28 import org.efaps.util.EFapsException;
29
30
31
32
33
34
35
36
37 public class NumberWithUoMUI
38 extends StringWithUoMUI
39 {
40
41
42
43
44 private static final long serialVersionUID = 1L;
45
46
47
48
49 @Override
50 public String validateValue(final UIValue _value)
51 {
52 String ret = null;
53 try {
54 if (_value.getDbValue() != null) {
55 Long.valueOf(String.valueOf(_value.getDbValue()));
56 }
57 } catch (final NumberFormatException e) {
58 ret = DBProperties.getProperty(NumberWithUoMUI.class.getName() + ".InvalidValue");
59 }
60 return ret;
61 }
62
63
64
65
66
67 @Override
68 public Object format(final Object _object,
69 final String _pattern)
70 throws EFapsException
71 {
72 final Object ret;
73 final DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Context.getThreadContext()
74 .getLocale());
75 formatter.applyPattern(_pattern);
76 if (_object instanceof Object[]) {
77 final String tmp = formatter.format(((Object[]) _object)[0]);
78 ((Object[]) _object)[0] = tmp;
79 ret = _object;
80 } else {
81 ret = formatter.format(_object);
82 }
83 return ret;
84 }
85 }