Clover coverage report - Code Coverage for tapestry-contrib release 4.0-beta-12
Coverage timestamp: Sun Oct 30 2005 16:28:27 EST
file stats: LOC: 238   Methods: 16
NCLOC: 127   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractTableColumn.java 0% 0% 0% 0%
coverage
 1    // Copyright 2004, 2005 The Apache Software Foundation
 2    //
 3    // Licensed under the Apache License, Version 2.0 (the "License");
 4    // you may not use this file except in compliance with the License.
 5    // You may obtain a copy of the License at
 6    //
 7    // http://www.apache.org/licenses/LICENSE-2.0
 8    //
 9    // Unless required by applicable law or agreed to in writing, software
 10    // distributed under the License is distributed on an "AS IS" BASIS,
 11    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12    // See the License for the specific language governing permissions and
 13    // limitations under the License.
 14   
 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    /**
 30    * A base implementation of {@link org.apache.tapestry.contrib.table.model.ITableColumn}
 31    * that allows renderers to be set via aggregation.
 32    *
 33    * @see org.apache.tapestry.contrib.table.model.ITableRendererSource
 34    * @author mindbridge
 35    * @since 2.3
 36    */
 37    public class AbstractTableColumn implements IAdvancedTableColumn, Serializable
 38    {
 39    private static final long serialVersionUID = 1L;
 40   
 41    /**
 42    * The suffix of the name of the Block that will be used as the column renderer
 43    * for this column
 44    */
 45    public static final String COLUMN_RENDERER_BLOCK_SUFFIX = "ColumnHeader";
 46   
 47    /**
 48    * The suffix of the name of the Block that will be used as the value renderer
 49    * for this column
 50    */
 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  0 public AbstractTableColumn()
 61    {
 62  0 this("", false, null);
 63    }
 64   
 65  0 public AbstractTableColumn(
 66    String strColumnName,
 67    boolean bSortable,
 68    Comparator objComparator)
 69    {
 70  0 this(strColumnName, bSortable, objComparator, null, null);
 71    }
 72   
 73  0 public AbstractTableColumn(
 74    String strColumnName,
 75    boolean bSortable,
 76    Comparator objComparator,
 77    ITableRendererSource objColumnRendererSource,
 78    ITableRendererSource objValueRendererSource)
 79    {
 80  0 setColumnName(strColumnName);
 81  0 setSortable(bSortable);
 82  0 setComparator(objComparator);
 83  0 setColumnRendererSource(objColumnRendererSource);
 84  0 setValueRendererSource(objValueRendererSource);
 85    }
 86   
 87    /**
 88    * @see org.apache.tapestry.contrib.table.model.ITableColumn#getColumnName()
 89    */
 90  0 public String getColumnName()
 91    {
 92  0 return m_strColumnName;
 93    }
 94   
 95    /**
 96    * Sets the columnName.
 97    * @param columnName The columnName to set
 98    */
 99  0 public void setColumnName(String columnName)
 100    {
 101  0 m_strColumnName = columnName;
 102    }
 103   
 104    /**
 105    * @see org.apache.tapestry.contrib.table.model.ITableColumn#getSortable()
 106    */
 107  0 public boolean getSortable()
 108    {
 109  0 return m_bSortable;
 110    }
 111   
 112    /**
 113    * Sets whether the column is sortable.
 114    * @param sortable The sortable flag to set
 115    */
 116  0 public void setSortable(boolean sortable)
 117    {
 118  0 m_bSortable = sortable;
 119    }
 120   
 121    /**
 122    * @see org.apache.tapestry.contrib.table.model.ITableColumn#getComparator()
 123    */
 124  0 public Comparator getComparator()
 125    {
 126  0 return m_objComparator;
 127    }
 128   
 129    /**
 130    * Sets the comparator.
 131    * @param comparator The comparator to set
 132    */
 133  0 public void setComparator(Comparator comparator)
 134    {
 135  0 m_objComparator = comparator;
 136    }
 137   
 138    /**
 139    * @see org.apache.tapestry.contrib.table.model.ITableColumn#getColumnRenderer(IRequestCycle, ITableModelSource)
 140    */
 141  0 public IRender getColumnRenderer(
 142    IRequestCycle objCycle,
 143    ITableModelSource objSource)
 144    {
 145  0 ITableRendererSource objRendererSource =
 146    getColumnRendererSource();
 147  0 if (objRendererSource == null)
 148    {
 149    // log error
 150  0 return new RenderString("");
 151    }
 152   
 153  0 return objRendererSource.getRenderer(objCycle, objSource, this, null);
 154    }
 155   
 156    /**
 157    * @see org.apache.tapestry.contrib.table.model.ITableColumn#getValueRenderer(IRequestCycle, ITableModelSource, Object)
 158    */
 159  0 public IRender getValueRenderer(
 160    IRequestCycle objCycle,
 161    ITableModelSource objSource,
 162    Object objRow)
 163    {
 164  0 ITableRendererSource objRendererSource = getValueRendererSource();
 165  0 if (objRendererSource == null)
 166    {
 167    // log error
 168  0 return new RenderString("");
 169    }
 170   
 171  0 return objRendererSource.getRenderer(
 172    objCycle,
 173    objSource,
 174    this,
 175    objRow);
 176    }
 177   
 178    /**
 179    * Returns the columnRendererSource.
 180    * @return ITableColumnRendererSource
 181    */
 182  0 public ITableRendererSource getColumnRendererSource()
 183    {
 184  0 return m_objColumnRendererSource;
 185    }
 186   
 187    /**
 188    * Sets the columnRendererSource.
 189    * @param columnRendererSource The columnRendererSource to set
 190    */
 191  0 public void setColumnRendererSource(ITableRendererSource columnRendererSource)
 192    {
 193  0 m_objColumnRendererSource = columnRendererSource;
 194    }
 195   
 196    /**
 197    * Returns the valueRendererSource.
 198    *
 199    * @return the valueRendererSource of this column
 200    */
 201  0 public ITableRendererSource getValueRendererSource()
 202    {
 203  0 return m_objValueRendererSource;
 204    }
 205   
 206    /**
 207    * Sets the valueRendererSource.
 208    *
 209    * @param valueRendererSource The valueRendererSource to set
 210    */
 211  0 public void setValueRendererSource(ITableRendererSource valueRendererSource)
 212    {
 213  0 m_objValueRendererSource = valueRendererSource;
 214    }
 215   
 216    /**
 217    * Use the column name to get the column and value renderer sources
 218    * from the provided component.
 219    * Use the column and value renderer sources for all columns if necessary.
 220    *
 221    * @param objSettingsContainer the component from which to get the settings
 222    */
 223  0 public void loadSettings(IComponent objSettingsContainer)
 224    {
 225  0 IComponent objColumnRendererSource = (IComponent) objSettingsContainer.getComponents().get(getColumnName() + COLUMN_RENDERER_BLOCK_SUFFIX);
 226  0 if (objColumnRendererSource == null)
 227  0 objColumnRendererSource = (IComponent) objSettingsContainer.getComponents().get(COLUMN_RENDERER_BLOCK_SUFFIX);
 228  0 if (objColumnRendererSource != null && objColumnRendererSource instanceof Block)
 229  0 setColumnRendererSource(new BlockTableRendererSource((Block) objColumnRendererSource));
 230   
 231  0 IComponent objValueRendererSource = (IComponent) objSettingsContainer.getComponents().get(getColumnName() + VALUE_RENDERER_BLOCK_SUFFIX);
 232  0 if (objValueRendererSource == null)
 233  0 objValueRendererSource = (IComponent) objSettingsContainer.getComponents().get(VALUE_RENDERER_BLOCK_SUFFIX);
 234  0 if (objValueRendererSource != null && objValueRendererSource instanceof Block)
 235  0 setValueRendererSource(new BlockTableRendererSource((Block) objValueRendererSource));
 236    }
 237   
 238    }