1 15 package org.apache.tapestry.contrib.table.components; 16 17 import java.util.Iterator ; 18 import java.util.Map ; 19 20 import org.apache.tapestry.IRequestCycle; 21 import org.apache.tapestry.contrib.table.model.*; 22 23 24 49 public abstract class TableFormRows extends TableRows 50 { 51 public abstract IPrimaryKeyConvertor getConvertor(); 52 public abstract IPrimaryKeyConvertor getConvertorCache(); 53 public abstract void setConvertorCache(IPrimaryKeyConvertor convertor); 54 public abstract Map getConvertedValues(); 55 56 61 public IPrimaryKeyConvertor getCachedConvertor() 62 { 63 IPrimaryKeyConvertor objConvertor = getConvertorCache(); 64 65 if (objConvertor == null) { 66 objConvertor = getConvertor(); 67 setConvertorCache(objConvertor); 68 } 69 70 return objConvertor; 71 } 72 73 79 public Iterator getConvertedTableRowsIterator() 80 { 81 final Iterator objTableRowsIterator = getTableRowsIterator(); 82 final IPrimaryKeyConvertor objConvertor = getCachedConvertor(); 83 if (objConvertor == null) 84 return objTableRowsIterator; 85 86 return new Iterator () 87 { 88 public boolean hasNext() 89 { 90 return objTableRowsIterator.hasNext(); 91 } 92 93 public Object next() 94 { 95 Object objValue = objTableRowsIterator.next(); 96 Object objPrimaryKey = objConvertor.getPrimaryKey(objValue); 97 Map mapConvertedValues = getConvertedValues(); 98 mapConvertedValues.put(objPrimaryKey, objValue); 99 return objPrimaryKey; 100 } 101 102 public void remove() 103 { 104 objTableRowsIterator.remove(); 105 } 106 }; 107 } 108 109 115 public void setConvertedTableRow(Object objConvertedTableRow) 116 { 117 Object objValue = objConvertedTableRow; 118 119 IPrimaryKeyConvertor objConvertor = getCachedConvertor(); 120 if (objConvertor != null) { 121 IRequestCycle objCycle = getPage().getRequestCycle(); 122 if (objCycle.isRewinding()) { 123 objValue = objConvertor.getValue(objConvertedTableRow); 124 } 125 else { 126 Map mapConvertedValues = getConvertedValues(); 127 objValue = mapConvertedValues.get(objConvertedTableRow); 128 } 129 } 130 131 setTableRow(objValue); 132 } 133 } 134 | Popular Tags |