1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
package org.apache.tapestry.contrib.table.model.ognl; |
16 | |
|
17 | |
import org.apache.tapestry.contrib.table.model.ITableColumn; |
18 | |
import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumnModel; |
19 | |
import org.apache.tapestry.services.ExpressionEvaluator; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
public class ExpressionTableColumnModel extends SimpleTableColumnModel |
25 | |
{ |
26 | |
|
27 | |
private static final long serialVersionUID = 1L; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public ExpressionTableColumnModel(String[] arrColumnInfo, boolean bSorted, |
45 | |
ExpressionEvaluator expressionEvaluator) |
46 | |
{ |
47 | 0 | this(convertToDetailedArray(arrColumnInfo, bSorted), |
48 | |
expressionEvaluator); |
49 | 0 | } |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
public ExpressionTableColumnModel(Object[] arrColumnInfo, |
68 | |
ExpressionEvaluator expressionEvaluator) |
69 | |
{ |
70 | 0 | super(convertToColumns(arrColumnInfo, expressionEvaluator)); |
71 | 0 | } |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
protected static Object[] convertToDetailedArray(String[] arrColumnInfo, |
81 | |
boolean bSorted) |
82 | |
{ |
83 | 0 | int nColumns = arrColumnInfo.length / 2; |
84 | 0 | int nSize = nColumns * 4; |
85 | 0 | Object[] arrDetailedInfo = new Object[nSize]; |
86 | |
|
87 | 0 | for(int i = 0; i < nColumns; i++) |
88 | |
{ |
89 | 0 | int nInputBaseIndex = 2 * i; |
90 | 0 | String strColumnName = arrColumnInfo[nInputBaseIndex]; |
91 | 0 | String strExpression = arrColumnInfo[nInputBaseIndex + 1]; |
92 | |
|
93 | 0 | int nOutputBaseIndex = 4 * i; |
94 | 0 | arrDetailedInfo[nOutputBaseIndex] = strColumnName; |
95 | 0 | arrDetailedInfo[nOutputBaseIndex + 1] = strColumnName; |
96 | 0 | arrDetailedInfo[nOutputBaseIndex + 2] = strExpression; |
97 | 0 | arrDetailedInfo[nOutputBaseIndex + 3] = bSorted ? Boolean.TRUE |
98 | |
: Boolean.FALSE; |
99 | |
} |
100 | |
|
101 | 0 | return arrDetailedInfo; |
102 | |
} |
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
protected static ITableColumn[] convertToColumns(Object[] arrDetailedInfo, |
111 | |
ExpressionEvaluator expressionEvaluator) |
112 | |
{ |
113 | 0 | int nColumns = arrDetailedInfo.length / 4; |
114 | 0 | ITableColumn[] arrColumns = new ITableColumn[nColumns]; |
115 | |
|
116 | 0 | for(int i = 0; i < nColumns; i++) |
117 | |
{ |
118 | |
Object objTempValue; |
119 | 0 | int nBaseIndex = 4 * i; |
120 | |
|
121 | 0 | String strColumnName = ""; |
122 | 0 | objTempValue = arrDetailedInfo[nBaseIndex]; |
123 | 0 | if (objTempValue != null) strColumnName = objTempValue.toString(); |
124 | |
|
125 | 0 | String strDisplayName = ""; |
126 | 0 | objTempValue = arrDetailedInfo[nBaseIndex + 1]; |
127 | 0 | if (objTempValue != null) strDisplayName = objTempValue.toString(); |
128 | |
|
129 | 0 | String strExpression = ""; |
130 | 0 | objTempValue = arrDetailedInfo[nBaseIndex + 2]; |
131 | 0 | if (objTempValue != null) strExpression = objTempValue.toString(); |
132 | |
|
133 | 0 | boolean bSorted = false; |
134 | 0 | objTempValue = arrDetailedInfo[nBaseIndex + 3]; |
135 | 0 | if (objTempValue != null) |
136 | |
{ |
137 | 0 | if (objTempValue instanceof Boolean) |
138 | 0 | bSorted = ((Boolean) objTempValue).booleanValue(); |
139 | 0 | else bSorted = Boolean.valueOf(objTempValue.toString()) |
140 | |
.booleanValue(); |
141 | |
} |
142 | |
|
143 | 0 | arrColumns[i] = new ExpressionTableColumn(strColumnName, |
144 | |
strDisplayName, strExpression, bSorted, expressionEvaluator); |
145 | |
} |
146 | |
|
147 | 0 | return arrColumns; |
148 | |
} |
149 | |
} |