1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.efaps.db.print.value;
22
23 import java.math.BigDecimal;
24
25 import org.efaps.admin.datamodel.Status;
26 import org.efaps.admin.datamodel.Type;
27 import org.efaps.db.print.OneSelect;
28 import org.efaps.db.wrapper.SQLSelect;
29 import org.efaps.util.EFapsException;
30
31
32
33
34
35
36
37 public class StatusValueSelect
38 extends AbstractValueSelect
39 {
40
41
42
43 public StatusValueSelect(final OneSelect _oneSelect)
44 {
45 super(_oneSelect);
46 }
47
48
49
50
51 @Override
52 public int append2SQLSelect(final Type _type,
53 final SQLSelect _select,
54 final int _tableIndex,
55 final int _colIndex)
56 {
57 int ret = 0;
58 Type tmpType = _type;
59
60 while (!tmpType.isCheckStatus() && tmpType.getParentType() != null) {
61 tmpType = tmpType.getParentType();
62 }
63 if (tmpType.isCheckStatus()) {
64 for (final String colName : tmpType.getStatusAttribute().getSqlColNames()) {
65 _select.column(_tableIndex, colName);
66 getColIndexs().add(_colIndex + ret);
67 ret++;
68 }
69 }
70 return ret;
71 }
72
73
74
75
76 @Override
77 public Object getValue(final Object _currentObject)
78 throws EFapsException
79 {
80 Object ret = null;
81 Status tempStatus;
82 if (_currentObject != null) {
83
84 if (_currentObject instanceof BigDecimal) {
85 tempStatus = Status.get(((BigDecimal) _currentObject).longValue());
86 } else {
87 tempStatus = Status.get((Long) _currentObject);
88 }
89 } else {
90 tempStatus = null;
91 }
92 if (tempStatus != null && getChildValueSelect() != null) {
93 switch (getChildValueSelect().getValueType()) {
94 case "label":
95 ret = tempStatus.getLabel();
96 break;
97 case "oid":
98 ret = new StringBuilder().append(Type.get(tempStatus.getStatusGroup().getUUID()).getId())
99 .append(".").append(tempStatus.getId()).toString();
100 break;
101 case "key":
102 ret = tempStatus.getKey();
103 break;
104 case "type":
105 ret = ((TypeValueSelect) getChildValueSelect()).analyzeChildValue(getChildValueSelect(),
106 Type.get(tempStatus.getStatusGroup().getUUID()));
107 break;
108 default:
109 ret = tempStatus;
110 break;
111 }
112 } else {
113 ret = tempStatus;
114 }
115 return ret;
116 }
117
118
119
120
121 @Override
122 public String getValueType()
123 {
124 return "status";
125 }
126 }