1 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 24 public class ExpressionTableColumnModel extends SimpleTableColumnModel 25 { 26 private static final long serialVersionUID = 1L; 27 28 43 public ExpressionTableColumnModel(String [] arrColumnInfo, boolean bSorted, 44 ExpressionEvaluator expressionEvaluator) 45 { 46 this(convertToDetailedArray(arrColumnInfo, bSorted), expressionEvaluator); 47 } 48 49 65 public ExpressionTableColumnModel(Object [] arrColumnInfo, 66 ExpressionEvaluator expressionEvaluator) 67 { 68 super(convertToColumns(arrColumnInfo, expressionEvaluator)); 69 } 70 71 78 protected static Object [] convertToDetailedArray(String [] arrColumnInfo, boolean bSorted) 79 { 80 int nColumns = arrColumnInfo.length / 2; 81 int nSize = nColumns * 4; 82 Object [] arrDetailedInfo = new Object [nSize]; 83 84 for (int i = 0; i < nColumns; i++) 85 { 86 int nInputBaseIndex = 2 * i; 87 String strColumnName = arrColumnInfo[nInputBaseIndex]; 88 String strExpression = arrColumnInfo[nInputBaseIndex + 1]; 89 90 int nOutputBaseIndex = 4 * i; 91 arrDetailedInfo[nOutputBaseIndex] = strColumnName; 92 arrDetailedInfo[nOutputBaseIndex + 1] = strColumnName; 93 arrDetailedInfo[nOutputBaseIndex + 2] = strExpression; 94 arrDetailedInfo[nOutputBaseIndex + 3] = bSorted ? Boolean.TRUE : Boolean.FALSE; 95 } 96 97 return arrDetailedInfo; 98 } 99 100 106 protected static ITableColumn[] convertToColumns(Object [] arrDetailedInfo, 107 ExpressionEvaluator expressionEvaluator) 108 { 109 int nColumns = arrDetailedInfo.length / 4; 110 ITableColumn[] arrColumns = new ITableColumn[nColumns]; 111 112 for (int i = 0; i < nColumns; i++) 113 { 114 Object objTempValue; 115 int nBaseIndex = 4 * i; 116 117 String strColumnName = ""; 118 objTempValue = arrDetailedInfo[nBaseIndex]; 119 if (objTempValue != null) 120 strColumnName = objTempValue.toString(); 121 122 String strDisplayName = ""; 123 objTempValue = arrDetailedInfo[nBaseIndex + 1]; 124 if (objTempValue != null) 125 strDisplayName = objTempValue.toString(); 126 127 String strExpression = ""; 128 objTempValue = arrDetailedInfo[nBaseIndex + 2]; 129 if (objTempValue != null) 130 strExpression = objTempValue.toString(); 131 132 boolean bSorted = false; 133 objTempValue = arrDetailedInfo[nBaseIndex + 3]; 134 if (objTempValue != null) 135 { 136 if (objTempValue instanceof Boolean ) 137 bSorted = ((Boolean ) objTempValue).booleanValue(); 138 else 139 bSorted = Boolean.valueOf(objTempValue.toString()).booleanValue(); 140 } 141 142 arrColumns[i] = new ExpressionTableColumn(strColumnName, strDisplayName, strExpression, 143 bSorted, expressionEvaluator); 144 } 145 146 return arrColumns; 147 } 148 } | Popular Tags |