1 15 package org.apache.tapestry.contrib.table.components; 16 17 import java.util.Iterator ; 18 19 import org.apache.tapestry.IAsset; 20 import org.apache.tapestry.IMarkupWriter; 21 import org.apache.tapestry.IRender; 22 import org.apache.tapestry.IRequestCycle; 23 import org.apache.tapestry.contrib.table.model.ITableColumn; 24 import org.apache.tapestry.contrib.table.model.ITableColumnModel; 25 26 42 public abstract class TableColumns extends AbstractTableViewComponent 43 { 44 public static final String TABLE_COLUMN_ARROW_UP_ATTRIBUTE = "org.apache.tapestry.contrib.table.components.TableColumns.arrowUp"; 45 46 public static final String TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE = "org.apache.tapestry.contrib.table.components.TableColumns.arrowDown"; 47 48 public static final String TABLE_COLUMN_CSS_CLASS_SUFFIX = "ColumnHeader"; 49 50 public abstract IAsset getArrowDownAsset(); 51 52 public abstract IAsset getArrowUpAsset(); 53 54 public abstract void setColumn(ITableColumn column); 55 56 private ITableColumn m_objTableColumn = null; 58 59 65 public ITableColumn getTableColumn() 66 { 67 return m_objTableColumn; 68 } 69 70 76 public void setTableColumn(ITableColumn tableColumn) 77 { 78 m_objTableColumn = tableColumn; 79 80 if (isParameterBound("column")) 81 setColumn(tableColumn); 82 } 83 84 89 public Iterator getTableColumnIterator() 90 { 91 ITableColumnModel objColumnModel = getTableModelSource().getTableModel().getColumnModel(); 92 return objColumnModel.getColumns(); 93 } 94 95 100 public IRender getTableColumnRenderer() 101 { 102 return getTableColumn().getColumnRenderer( 103 getPage().getRequestCycle(), 104 getTableModelSource()); 105 } 106 107 public abstract String getColumnClassParameter(); 108 109 115 public String getColumnClass() 116 { 117 if (isParameterBound("class")) 118 return getColumnClassParameter(); 119 120 return getTableColumn().getColumnName() + TABLE_COLUMN_CSS_CLASS_SUFFIX; 121 } 122 123 126 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) 127 { 128 Object oldValueUp = cycle.getAttribute(TABLE_COLUMN_ARROW_UP_ATTRIBUTE); 129 Object oldValueDown = cycle.getAttribute(TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE); 130 131 try 132 { 133 cycle.setAttribute(TABLE_COLUMN_ARROW_UP_ATTRIBUTE, getArrowUpAsset()); 134 cycle.setAttribute(TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE, getArrowDownAsset()); 135 136 super.renderComponent(writer, cycle); 137 } 138 finally 139 { 140 cycle.setAttribute(TABLE_COLUMN_ARROW_UP_ATTRIBUTE, oldValueUp); 141 cycle.setAttribute(TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE, oldValueDown); 142 143 m_objTableColumn = null; 145 } 146 } 147 148 } | Popular Tags |