1 15 package org.apache.tapestry.contrib.table.components; 16 17 import java.util.ArrayList ; 18 import java.util.List ; 19 import java.util.StringTokenizer ; 20 21 import org.apache.hivemind.ApplicationRuntimeException; 22 import org.apache.tapestry.IComponent; 23 import org.apache.tapestry.contrib.table.model.IAdvancedTableColumn; 24 import org.apache.tapestry.contrib.table.model.IAdvancedTableColumnSource; 25 import org.apache.tapestry.contrib.table.model.ITableColumn; 26 import org.apache.tapestry.contrib.table.model.ITableColumnModel; 27 import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumn; 28 import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumnModel; 29 import org.apache.tapestry.services.ExpressionEvaluator; 30 31 37 public class TableColumnModelSourceImpl implements TableColumnModelSource 38 { 39 40 private ExpressionEvaluator _expressionEvaluator; 41 42 43 44 public void setExpressionEvaluator(ExpressionEvaluator expressionEvaluator) 45 { 46 _expressionEvaluator = expressionEvaluator; 47 } 48 49 64 public ITableColumnModel generateTableColumnModel(IAdvancedTableColumnSource objColumnSource, 65 String strDesc, IComponent objComponent, IComponent objColumnSettingsContainer) 66 { 67 if (strDesc == null) 68 return null; 69 70 List arrColumns = new ArrayList (); 71 72 boolean bFormColumns = false; 73 while (strDesc.startsWith("*")) 74 { 75 strDesc = strDesc.substring(1); 76 bFormColumns = true; 77 } 78 79 StringTokenizer objTokenizer = new StringTokenizer (strDesc, ","); 80 while (objTokenizer.hasMoreTokens()) 81 { 82 String strToken = objTokenizer.nextToken().trim(); 83 84 if (strToken.startsWith("=")) 85 { 86 String strColumnExpression = strToken.substring(1); 87 88 Object objColumn = _expressionEvaluator.read( 89 objColumnSettingsContainer, 90 strColumnExpression); 91 92 if (!(objColumn instanceof ITableColumn)) 93 throw new ApplicationRuntimeException(TableMessages.notAColumn( 94 objComponent, 95 strColumnExpression)); 96 97 arrColumns.add(objColumn); 98 continue; 99 } 100 101 boolean bSortable = true; 102 if (strToken.startsWith("!")) 103 { 104 strToken = strToken.substring(1); 105 bSortable = false; 106 } 107 108 StringTokenizer objColumnTokenizer = new StringTokenizer (strToken, ":"); 109 110 String strName = ""; 111 if (objColumnTokenizer.hasMoreTokens()) 112 strName = objColumnTokenizer.nextToken(); 113 114 String strExpression = strName; 115 if (objColumnTokenizer.hasMoreTokens()) 116 strExpression = objColumnTokenizer.nextToken(); 117 118 String strDisplayName = strName; 119 if (objColumnTokenizer.hasMoreTokens()) 120 { 121 strDisplayName = strExpression; 122 strExpression = objColumnTokenizer.nextToken(); 123 } 124 125 IAdvancedTableColumn objColumn = 126 objColumnSource.generateTableColumn(strName, strDisplayName, 127 bSortable, strExpression); 128 if (bFormColumns) 129 objColumn.setColumnRendererSource(SimpleTableColumn.FORM_COLUMN_RENDERER_SOURCE); 130 if (objColumnSettingsContainer != null) 131 objColumn.loadSettings(objColumnSettingsContainer); 132 133 arrColumns.add(objColumn); 134 } 135 136 return new SimpleTableColumnModel(arrColumns); 137 } 138 139 } | Popular Tags |