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.Type;
26 import org.efaps.ci.CIAdminDataModel;
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 TypeValueSelect
38 extends AbstractValueSelect
39 {
40
41
42
43 private Type type;
44
45
46
47
48 public TypeValueSelect(final OneSelect _oneSelect)
49 {
50 super(_oneSelect);
51 }
52
53
54
55
56 @Override
57 public int append2SQLSelect(final Type _type,
58 final SQLSelect _select,
59 final int _tableIndex,
60 final int _colIndex)
61 {
62 int ret = 0;
63 if (_type.getMainTable().getSqlColType() != null) {
64 _select.column(_tableIndex, _type.getMainTable().getSqlColType());
65 getColIndexs().add(_colIndex + ret);
66 ret++;
67 }
68 this.type = _type;
69 return ret;
70 }
71
72
73
74
75 @Override
76 public Object getValue(final Object _currentObject)
77 throws EFapsException
78 {
79 Type tempType;
80 if (this.type.getMainTable().getSqlColType() == null) {
81 tempType = this.type;
82 } else if (_currentObject != null) {
83
84 if (_currentObject instanceof BigDecimal) {
85 tempType = Type.get(((BigDecimal) _currentObject).longValue());
86 } else {
87 tempType = Type.get((Long) _currentObject);
88 }
89 } else {
90 tempType = null;
91 }
92 return analyzeChildValue(this, tempType);
93 }
94
95
96
97
98 @Override
99 public String getValueType()
100 {
101 return "type";
102 }
103
104
105
106
107
108
109 protected Object analyzeChildValue(final AbstractValueSelect _currentSelect,
110 final Type _tempType)
111 {
112 Object ret;
113 if (_tempType != null && _currentSelect.getChildValueSelect() != null) {
114 switch (_currentSelect.getChildValueSelect().getValueType()) {
115 case "label":
116 ret = _tempType.getLabel();
117 break;
118 case "oid":
119 ret = new StringBuilder().append(CIAdminDataModel.Type.getType().getId()).append(".").append(
120 _tempType.getId()).toString();
121 break;
122 case "UUID":
123 ret = _tempType.getUUID();
124 break;
125 case "name":
126 ret = _tempType.getName();
127 break;
128 default:
129 ret = _tempType;
130 break;
131 }
132 } else {
133 ret = _tempType;
134 }
135 return ret;
136 }
137 }