1 15 package org.apache.tapestry.contrib.table.model.common; 16 17 import java.io.Serializable ; 18 import java.util.Comparator ; 19 20 import org.apache.tapestry.IComponent; 21 import org.apache.tapestry.IRender; 22 import org.apache.tapestry.IRequestCycle; 23 import org.apache.tapestry.components.Block; 24 import org.apache.tapestry.contrib.table.model.IAdvancedTableColumn; 25 import org.apache.tapestry.contrib.table.model.ITableModelSource; 26 import org.apache.tapestry.contrib.table.model.ITableRendererSource; 27 import org.apache.tapestry.valid.RenderString; 28 29 37 public class AbstractTableColumn implements IAdvancedTableColumn, Serializable 38 { 39 private static final long serialVersionUID = 1L; 40 41 45 public static final String COLUMN_RENDERER_BLOCK_SUFFIX = "ColumnHeader"; 46 47 51 public static final String VALUE_RENDERER_BLOCK_SUFFIX = "ColumnValue"; 52 53 private String m_strColumnName; 54 private boolean m_bSortable; 55 private Comparator m_objComparator; 56 57 private ITableRendererSource m_objColumnRendererSource; 58 private ITableRendererSource m_objValueRendererSource; 59 60 public AbstractTableColumn() 61 { 62 this("", false, null); 63 } 64 65 public AbstractTableColumn( 66 String strColumnName, 67 boolean bSortable, 68 Comparator objComparator) 69 { 70 this(strColumnName, bSortable, objComparator, null, null); 71 } 72 73 public AbstractTableColumn( 74 String strColumnName, 75 boolean bSortable, 76 Comparator objComparator, 77 ITableRendererSource objColumnRendererSource, 78 ITableRendererSource objValueRendererSource) 79 { 80 setColumnName(strColumnName); 81 setSortable(bSortable); 82 setComparator(objComparator); 83 setColumnRendererSource(objColumnRendererSource); 84 setValueRendererSource(objValueRendererSource); 85 } 86 87 90 public String getColumnName() 91 { 92 return m_strColumnName; 93 } 94 95 99 public void setColumnName(String columnName) 100 { 101 m_strColumnName = columnName; 102 } 103 104 107 public boolean getSortable() 108 { 109 return m_bSortable; 110 } 111 112 116 public void setSortable(boolean sortable) 117 { 118 m_bSortable = sortable; 119 } 120 121 124 public Comparator getComparator() 125 { 126 return m_objComparator; 127 } 128 129 133 public void setComparator(Comparator comparator) 134 { 135 m_objComparator = comparator; 136 } 137 138 141 public IRender getColumnRenderer( 142 IRequestCycle objCycle, 143 ITableModelSource objSource) 144 { 145 ITableRendererSource objRendererSource = 146 getColumnRendererSource(); 147 if (objRendererSource == null) 148 { 149 return new RenderString(""); 151 } 152 153 return objRendererSource.getRenderer(objCycle, objSource, this, null); 154 } 155 156 159 public IRender getValueRenderer( 160 IRequestCycle objCycle, 161 ITableModelSource objSource, 162 Object objRow) 163 { 164 ITableRendererSource objRendererSource = getValueRendererSource(); 165 if (objRendererSource == null) 166 { 167 return new RenderString(""); 169 } 170 171 return objRendererSource.getRenderer( 172 objCycle, 173 objSource, 174 this, 175 objRow); 176 } 177 178 182 public ITableRendererSource getColumnRendererSource() 183 { 184 return m_objColumnRendererSource; 185 } 186 187 191 public void setColumnRendererSource(ITableRendererSource columnRendererSource) 192 { 193 m_objColumnRendererSource = columnRendererSource; 194 } 195 196 201 public ITableRendererSource getValueRendererSource() 202 { 203 return m_objValueRendererSource; 204 } 205 206 211 public void setValueRendererSource(ITableRendererSource valueRendererSource) 212 { 213 m_objValueRendererSource = valueRendererSource; 214 } 215 216 223 public void loadSettings(IComponent objSettingsContainer) 224 { 225 IComponent objColumnRendererSource = (IComponent) objSettingsContainer.getComponents().get(getColumnName() + COLUMN_RENDERER_BLOCK_SUFFIX); 226 if (objColumnRendererSource == null) 227 objColumnRendererSource = (IComponent) objSettingsContainer.getComponents().get(COLUMN_RENDERER_BLOCK_SUFFIX); 228 if (objColumnRendererSource != null && objColumnRendererSource instanceof Block) 229 setColumnRendererSource(new BlockTableRendererSource((Block) objColumnRendererSource)); 230 231 IComponent objValueRendererSource = (IComponent) objSettingsContainer.getComponents().get(getColumnName() + VALUE_RENDERER_BLOCK_SUFFIX); 232 if (objValueRendererSource == null) 233 objValueRendererSource = (IComponent) objSettingsContainer.getComponents().get(VALUE_RENDERER_BLOCK_SUFFIX); 234 if (objValueRendererSource != null && objValueRendererSource instanceof Block) 235 setValueRendererSource(new BlockTableRendererSource((Block) objValueRendererSource)); 236 } 237 238 } 239 | Popular Tags |