|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ExpressionTableColumnModel.java | 0% | 0% | 0% | 0% |
|
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 |
* Constructs a table column model containting OGNL expression columns. <br>
|
|
28 |
* The data for the columns is provided in the form of a string array, where the info of each
|
|
29 |
* column is stored in two consecutive fields in the array, hence its size must be even. The
|
|
30 |
* expected info is the following:
|
|
31 |
* <ul>
|
|
32 |
* <li>Column Name
|
|
33 |
* <li>OGNL expression
|
|
34 |
* </ul>
|
|
35 |
*
|
|
36 |
* @param arrColumnInfo
|
|
37 |
* The information to construct the columns from
|
|
38 |
* @param bSorted
|
|
39 |
* Whether all columns are sorted or not
|
|
40 |
*/
|
|
41 | 0 |
public ExpressionTableColumnModel(String[] arrColumnInfo, boolean bSorted, |
42 |
ExpressionEvaluator expressionEvaluator) |
|
43 |
{ |
|
44 | 0 |
this(convertToDetailedArray(arrColumnInfo, bSorted), expressionEvaluator);
|
45 |
} |
|
46 |
|
|
47 |
/**
|
|
48 |
* Constructs a table column model containting OGNL expression columns. <br>
|
|
49 |
* The data for the columns is provided in the form of a string array, where the info of each
|
|
50 |
* column is stored in four consecutive fields in the array, hence its size must be divisible by
|
|
51 |
* 4.<br>
|
|
52 |
* The expected info is the following:
|
|
53 |
* <ul>
|
|
54 |
* <li>Column Name
|
|
55 |
* <li>Display Name
|
|
56 |
* <li>OGNL expression
|
|
57 |
* <li>Sorting of the column. This is either a Boolean, or a String representation of a
|
|
58 |
* boolean.
|
|
59 |
* </ul>
|
|
60 |
*
|
|
61 |
* @param arrColumnInfo
|
|
62 |
*/
|
|
63 | 0 |
public ExpressionTableColumnModel(Object[] arrColumnInfo,
|
64 |
ExpressionEvaluator expressionEvaluator) |
|
65 |
{ |
|
66 | 0 |
super(convertToColumns(arrColumnInfo, expressionEvaluator));
|
67 |
} |
|
68 |
|
|
69 |
/**
|
|
70 |
* Method convertToDetailedArray.
|
|
71 |
*
|
|
72 |
* @param arrColumnInfo
|
|
73 |
* @param bSorted
|
|
74 |
* @return Object[]
|
|
75 |
*/
|
|
76 | 0 |
protected static Object[] convertToDetailedArray(String[] arrColumnInfo, boolean bSorted) |
77 |
{ |
|
78 | 0 |
int nColumns = arrColumnInfo.length / 2;
|
79 | 0 |
int nSize = nColumns * 4;
|
80 | 0 |
Object[] arrDetailedInfo = new Object[nSize];
|
81 |
|
|
82 | 0 |
for (int i = 0; i < nColumns; i++) |
83 |
{ |
|
84 | 0 |
int nInputBaseIndex = 2 * i;
|
85 | 0 |
String strColumnName = arrColumnInfo[nInputBaseIndex]; |
86 | 0 |
String strExpression = arrColumnInfo[nInputBaseIndex + 1]; |
87 |
|
|
88 | 0 |
int nOutputBaseIndex = 4 * i;
|
89 | 0 |
arrDetailedInfo[nOutputBaseIndex] = strColumnName; |
90 | 0 |
arrDetailedInfo[nOutputBaseIndex + 1] = strColumnName; |
91 | 0 |
arrDetailedInfo[nOutputBaseIndex + 2] = strExpression; |
92 | 0 |
arrDetailedInfo[nOutputBaseIndex + 3] = bSorted ? Boolean.TRUE : Boolean.FALSE; |
93 |
} |
|
94 |
|
|
95 | 0 |
return arrDetailedInfo;
|
96 |
} |
|
97 |
|
|
98 |
/**
|
|
99 |
* Method convertToColumns.
|
|
100 |
*
|
|
101 |
* @param arrDetailedInfo
|
|
102 |
* @return ITableColumn[]
|
|
103 |
*/
|
|
104 | 0 |
protected static ITableColumn[] convertToColumns(Object[] arrDetailedInfo, |
105 |
ExpressionEvaluator expressionEvaluator) |
|
106 |
{ |
|
107 | 0 |
int nColumns = arrDetailedInfo.length / 4;
|
108 | 0 |
ITableColumn[] arrColumns = new ITableColumn[nColumns];
|
109 |
|
|
110 | 0 |
for (int i = 0; i < nColumns; i++) |
111 |
{ |
|
112 | 0 |
Object objTempValue; |
113 | 0 |
int nBaseIndex = 4 * i;
|
114 |
|
|
115 | 0 |
String strColumnName = "";
|
116 | 0 |
objTempValue = arrDetailedInfo[nBaseIndex]; |
117 | 0 |
if (objTempValue != null) |
118 | 0 |
strColumnName = objTempValue.toString(); |
119 |
|
|
120 | 0 |
String strDisplayName = "";
|
121 | 0 |
objTempValue = arrDetailedInfo[nBaseIndex + 1]; |
122 | 0 |
if (objTempValue != null) |
123 | 0 |
strDisplayName = objTempValue.toString(); |
124 |
|
|
125 | 0 |
String strExpression = "";
|
126 | 0 |
objTempValue = arrDetailedInfo[nBaseIndex + 2]; |
127 | 0 |
if (objTempValue != null) |
128 | 0 |
strExpression = objTempValue.toString(); |
129 |
|
|
130 | 0 |
boolean bSorted = false; |
131 | 0 |
objTempValue = arrDetailedInfo[nBaseIndex + 3]; |
132 | 0 |
if (objTempValue != null) |
133 |
{ |
|
134 | 0 |
if (objTempValue instanceof Boolean) |
135 | 0 |
bSorted = ((Boolean) objTempValue).booleanValue(); |
136 |
else
|
|
137 | 0 |
bSorted = Boolean.valueOf(objTempValue.toString()).booleanValue(); |
138 |
} |
|
139 |
|
|
140 | 0 |
arrColumns[i] = new ExpressionTableColumn(strColumnName, strDisplayName, strExpression,
|
141 |
bSorted, expressionEvaluator); |
|
142 |
} |
|
143 |
|
|
144 | 0 |
return arrColumns;
|
145 |
} |
|
146 |
} |
|