1 15 package org.apache.tapestry.contrib.table.components.inserted; 16 17 import org.apache.tapestry.BaseComponent; 18 import org.apache.tapestry.IAsset; 19 import org.apache.tapestry.IRequestCycle; 20 import org.apache.tapestry.contrib.table.components.TableColumns; 21 import org.apache.tapestry.contrib.table.model.ITableColumn; 22 import org.apache.tapestry.contrib.table.model.ITableModel; 23 import org.apache.tapestry.contrib.table.model.ITableModelSource; 24 import org.apache.tapestry.contrib.table.model.ITableRendererListener; 25 import org.apache.tapestry.contrib.table.model.ITableSortingState; 26 import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumn; 27 28 40 public abstract class SimpleTableColumnFormComponent 41 extends BaseComponent 42 implements ITableRendererListener 43 { 44 45 public abstract ITableColumn getTableColumn(); 46 public abstract void setTableColumn(ITableColumn objColumn); 47 48 public abstract ITableModelSource getTableModelSource(); 49 public abstract void setTableModelSource(ITableModelSource objSource); 50 51 public abstract String getSelectedColumnName(); 52 53 56 public void initializeRenderer( 57 IRequestCycle objCycle, 58 ITableModelSource objSource, 59 ITableColumn objColumn, 60 Object objRow) 61 { 62 setTableModelSource(objSource); 63 setTableColumn(objColumn); 64 } 65 66 public ITableModel getTableModel() 67 { 68 return getTableModelSource().getTableModel(); 69 } 70 71 public boolean getColumnSorted() 72 { 73 return getTableColumn().getSortable(); 74 } 75 76 public String getDisplayName() 77 { 78 ITableColumn objColumn = getTableColumn(); 79 80 if (objColumn instanceof SimpleTableColumn) { 81 SimpleTableColumn objSimpleColumn = (SimpleTableColumn) objColumn; 82 return objSimpleColumn.getDisplayName(); 83 } 84 return objColumn.getColumnName(); 85 } 86 87 public boolean getIsSorted() 88 { 89 ITableSortingState objSortingState = getTableModel().getSortingState(); 90 String strSortColumn = objSortingState.getSortColumn(); 91 return getTableColumn().getColumnName().equals(strSortColumn); 92 } 93 94 public IAsset getSortImage() 95 { 96 IAsset objImageAsset; 97 98 IRequestCycle objCycle = getPage().getRequestCycle(); 99 ITableSortingState objSortingState = getTableModel().getSortingState(); 100 if (objSortingState.getSortOrder() 101 == ITableSortingState.SORT_ASCENDING) 102 { 103 objImageAsset = 104 (IAsset) objCycle.getAttribute( 105 TableColumns.TABLE_COLUMN_ARROW_UP_ATTRIBUTE); 106 if (objImageAsset == null) 107 objImageAsset = getAsset("sortUp"); 108 } 109 else 110 { 111 objImageAsset = 112 (IAsset) objCycle.getAttribute( 113 TableColumns.TABLE_COLUMN_ARROW_DOWN_ATTRIBUTE); 114 if (objImageAsset == null) 115 objImageAsset = getAsset("sortDown"); 116 } 117 118 return objImageAsset; 119 } 120 121 public void columnSelected(IRequestCycle objCycle) 122 { 123 String strColumnName = getSelectedColumnName(); 124 ITableSortingState objState = getTableModel().getSortingState(); 125 if (strColumnName.equals(objState.getSortColumn())) 126 objState.setSortColumn(strColumnName, !objState.getSortOrder()); 127 else 128 objState.setSortColumn( 129 strColumnName, 130 ITableSortingState.SORT_ASCENDING); 131 132 getTableModelSource().fireObservedStateChange(); 134 } 135 136 } 137 | Popular Tags |