Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
ExpressionTableColumnModel |
|
| 2.75;2.75 |
1 | // Copyright 2004, 2005 The Apache Software Foundation |
|
2 | // |
|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 | // you may not use this file except in compliance with the License. |
|
5 | // You may obtain a copy of the License at |
|
6 | // |
|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | // |
|
9 | // Unless required by applicable law or agreed to in writing, software |
|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 | // See the License for the specific language governing permissions and |
|
13 | // limitations under the License. |
|
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 | * @author mindbridge |
|
23 | */ |
|
24 | public class ExpressionTableColumnModel extends SimpleTableColumnModel |
|
25 | { |
|
26 | ||
27 | private static final long serialVersionUID = 1L; |
|
28 | ||
29 | /** |
|
30 | * Constructs a table column model containting OGNL expression columns. <br> |
|
31 | * The data for the columns is provided in the form of a string array, where |
|
32 | * the info of each column is stored in two consecutive fields in the array, |
|
33 | * hence its size must be even. The expected info is the following: |
|
34 | * <ul> |
|
35 | * <li>Column Name |
|
36 | * <li>OGNL expression |
|
37 | * </ul> |
|
38 | * |
|
39 | * @param arrColumnInfo |
|
40 | * The information to construct the columns from |
|
41 | * @param bSorted |
|
42 | * Whether all columns are sorted or not |
|
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 | * Constructs a table column model containting OGNL expression columns. <br> |
|
53 | * The data for the columns is provided in the form of a string array, where |
|
54 | * the info of each column is stored in four consecutive fields in the |
|
55 | * array, hence its size must be divisible by 4.<br> |
|
56 | * The expected info is the following: |
|
57 | * <ul> |
|
58 | * <li>Column Name |
|
59 | * <li>Display Name |
|
60 | * <li>OGNL expression |
|
61 | * <li>Sorting of the column. This is either a Boolean, or a String |
|
62 | * representation of a boolean. |
|
63 | * </ul> |
|
64 | * |
|
65 | * @param arrColumnInfo |
|
66 | */ |
|
67 | public ExpressionTableColumnModel(Object[] arrColumnInfo, |
|
68 | ExpressionEvaluator expressionEvaluator) |
|
69 | { |
|
70 | 0 | super(convertToColumns(arrColumnInfo, expressionEvaluator)); |
71 | 0 | } |
72 | ||
73 | /** |
|
74 | * Method convertToDetailedArray. |
|
75 | * |
|
76 | * @param arrColumnInfo |
|
77 | * @param bSorted |
|
78 | * @return Object[] |
|
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 | * Method convertToColumns. |
|
106 | * |
|
107 | * @param arrDetailedInfo |
|
108 | * @return ITableColumn[] |
|
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 | } |