1
2
3
4
5 package pt.digitalis.dif.dem.objects.parameters.constraints.impl.numeric;
6
7 import java.util.HashMap;
8 import java.util.Map;
9
10 import pt.digitalis.dif.dem.interfaces.IStageInstance;
11
12
13
14
15
16
17
18 public class ParameterConstraintNumericImpl extends AbstractNumericParameterConstraint {
19
20
21 String lastTestedValue;
22
23
24
25
26 public void configureConstraint(String configurationString)
27 {
28
29 }
30
31
32
33
34 @Override
35 protected Map<String, String> getErrorMessageValues(boolean parseValues)
36 {
37 Map<String, String> substitutions = new HashMap<String, String>();
38
39 if (parseValues)
40 {
41 substitutions.put("value", lastTestedValue);
42 }
43
44 return substitutions;
45 }
46
47
48
49
50 public String getJavaScriptValidationCondition()
51 {
52 return "Ext.isNumeric(value)";
53 }
54
55
56
57
58
59 @Override
60 public boolean validateConstraint(Double value, IStageInstance stageInstance)
61 {
62
63
64 return true;
65 }
66
67
68
69
70
71 @Override
72 public boolean validateConstraint(String value, IStageInstance stageInstance)
73 {
74
75 lastTestedValue = value;
76
77 if (value == null || "".equals(value) || "undefined".equals(value))
78 return true;
79 else
80 try
81 {
82 value = value.replace(',', '.');
83
84 Double.valueOf(value);
85
86 return true;
87
88 }
89 catch (NumberFormatException e)
90 {
91 return false;
92 }
93 }
94 }