Coverage Report - org.apache.tapestry.contrib.table.model.common.AbstractTableColumn
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractTableColumn
0% 
0% 
1.5
 
 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
 31  
  * {@link org.apache.tapestry.contrib.table.model.ITableColumn} that allows
 32  
  * renderers to be set via aggregation.
 33  
  * 
 34  
  * @see org.apache.tapestry.contrib.table.model.ITableRendererSource
 35  
  * @author mindbridge
 36  
  * @since 2.3
 37  
  */
 38  
 public class AbstractTableColumn implements IAdvancedTableColumn, Serializable
 39  
 {
 40  
 
 41  
     /**
 42  
      * The suffix of the name of the Block that will be used as the column
 43  
      * renderer 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
 49  
      * renderer for this column.
 50  
      */
 51  
     public static final String VALUE_RENDERER_BLOCK_SUFFIX = "ColumnValue";
 52  
 
 53  
     private static final long serialVersionUID = 1L;
 54  
 
 55  
     private String m_strColumnName;
 56  
     private boolean m_bSortable;
 57  
     private Comparator m_objComparator;
 58  
 
 59  
     private ITableRendererSource m_objColumnRendererSource;
 60  
     private ITableRendererSource m_objValueRendererSource;
 61  
 
 62  
     public AbstractTableColumn()
 63  
     {
 64  0
         this("", false, null);
 65  0
     }
 66  
 
 67  
     public AbstractTableColumn(String strColumnName, boolean bSortable,
 68  
             Comparator objComparator)
 69  
     {
 70  0
         this(strColumnName, bSortable, objComparator, null, null);
 71  0
     }
 72  
 
 73  
     public AbstractTableColumn(String strColumnName, boolean bSortable,
 74  
             Comparator objComparator,
 75  
             ITableRendererSource objColumnRendererSource,
 76  
             ITableRendererSource objValueRendererSource)
 77  0
     {
 78  0
         setColumnName(strColumnName);
 79  0
         setSortable(bSortable);
 80  0
         setComparator(objComparator);
 81  0
         setColumnRendererSource(objColumnRendererSource);
 82  0
         setValueRendererSource(objValueRendererSource);
 83  0
     }
 84  
 
 85  
     /**
 86  
      * @see org.apache.tapestry.contrib.table.model.ITableColumn#getColumnName()
 87  
      */
 88  
     public String getColumnName()
 89  
     {
 90  0
         return m_strColumnName;
 91  
     }
 92  
 
 93  
     /**
 94  
      * Sets the columnName.
 95  
      * 
 96  
      * @param columnName
 97  
      *            The columnName to set
 98  
      */
 99  
     public void setColumnName(String columnName)
 100  
     {
 101  0
         m_strColumnName = columnName;
 102  0
     }
 103  
 
 104  
     /**
 105  
      * @see org.apache.tapestry.contrib.table.model.ITableColumn#getSortable()
 106  
      */
 107  
     public boolean getSortable()
 108  
     {
 109  0
         return m_bSortable;
 110  
     }
 111  
 
 112  
     /**
 113  
      * Sets whether the column is sortable.
 114  
      * 
 115  
      * @param sortable
 116  
      *            The sortable flag to set
 117  
      */
 118  
     public void setSortable(boolean sortable)
 119  
     {
 120  0
         m_bSortable = sortable;
 121  0
     }
 122  
 
 123  
     /**
 124  
      * @see org.apache.tapestry.contrib.table.model.ITableColumn#getComparator()
 125  
      */
 126  
     public Comparator getComparator()
 127  
     {
 128  0
         return m_objComparator;
 129  
     }
 130  
 
 131  
     /**
 132  
      * Sets the comparator.
 133  
      * 
 134  
      * @param comparator
 135  
      *            The comparator to set
 136  
      */
 137  
     public void setComparator(Comparator comparator)
 138  
     {
 139  0
         m_objComparator = comparator;
 140  0
     }
 141  
 
 142  
     /**
 143  
      * @see org.apache.tapestry.contrib.table.model.ITableColumn#getColumnRenderer(IRequestCycle,
 144  
      *      ITableModelSource)
 145  
      */
 146  
     public IRender getColumnRenderer(IRequestCycle objCycle,
 147  
             ITableModelSource objSource)
 148  
     {
 149  0
         ITableRendererSource objRendererSource = getColumnRendererSource();
 150  0
         if (objRendererSource == null)
 151  
         {
 152  
             // log error
 153  0
             return new RenderString("");
 154  
         }
 155  
 
 156  0
         return objRendererSource.getRenderer(objCycle, objSource, this, null);
 157  
     }
 158  
 
 159  
     /**
 160  
      * @see org.apache.tapestry.contrib.table.model.ITableColumn#getValueRenderer(IRequestCycle,
 161  
      *      ITableModelSource, Object)
 162  
      */
 163  
     public IRender getValueRenderer(IRequestCycle objCycle,
 164  
             ITableModelSource objSource, Object objRow)
 165  
     {
 166  0
         ITableRendererSource objRendererSource = getValueRendererSource();
 167  0
         if (objRendererSource == null)
 168  
         {
 169  
             // log error
 170  0
             return new RenderString("");
 171  
         }
 172  
 
 173  0
         return objRendererSource.getRenderer(objCycle, objSource, this, objRow);
 174  
     }
 175  
 
 176  
     /**
 177  
      * Returns the columnRendererSource.
 178  
      * 
 179  
      * @return ITableColumnRendererSource
 180  
      */
 181  
     public ITableRendererSource getColumnRendererSource()
 182  
     {
 183  0
         return m_objColumnRendererSource;
 184  
     }
 185  
 
 186  
     /**
 187  
      * Sets the columnRendererSource.
 188  
      * 
 189  
      * @param columnRendererSource
 190  
      *            The columnRendererSource to set
 191  
      */
 192  
     public void setColumnRendererSource(
 193  
             ITableRendererSource columnRendererSource)
 194  
     {
 195  0
         m_objColumnRendererSource = columnRendererSource;
 196  0
     }
 197  
 
 198  
     /**
 199  
      * Returns the valueRendererSource.
 200  
      * 
 201  
      * @return the valueRendererSource of this column
 202  
      */
 203  
     public ITableRendererSource getValueRendererSource()
 204  
     {
 205  0
         return m_objValueRendererSource;
 206  
     }
 207  
 
 208  
     /**
 209  
      * Sets the valueRendererSource.
 210  
      * 
 211  
      * @param valueRendererSource
 212  
      *            The valueRendererSource to set
 213  
      */
 214  
     public void setValueRendererSource(ITableRendererSource valueRendererSource)
 215  
     {
 216  0
         m_objValueRendererSource = valueRendererSource;
 217  0
     }
 218  
 
 219  
     /**
 220  
      * Use the column name to get the column and value renderer sources from the
 221  
      * provided component. Use the column and value renderer sources for all
 222  
      * columns if necessary.
 223  
      * 
 224  
      * @param objSettingsContainer
 225  
      *            the component from which to get the settings
 226  
      */
 227  
     public void loadSettings(IComponent objSettingsContainer)
 228  
     {
 229  0
         IComponent objColumnRendererSource = (IComponent) objSettingsContainer
 230  
                 .getComponents().get(
 231  
                         getColumnName() + COLUMN_RENDERER_BLOCK_SUFFIX);
 232  0
         if (objColumnRendererSource == null)
 233  0
             objColumnRendererSource = (IComponent) objSettingsContainer
 234  
                     .getComponents().get(COLUMN_RENDERER_BLOCK_SUFFIX);
 235  0
         if (objColumnRendererSource != null
 236  
                 && objColumnRendererSource instanceof Block)
 237  0
             setColumnRendererSource(new BlockTableRendererSource(
 238  
                     (Block) objColumnRendererSource));
 239  
 
 240  0
         IComponent objValueRendererSource = (IComponent) objSettingsContainer
 241  
                 .getComponents().get(
 242  
                         getColumnName() + VALUE_RENDERER_BLOCK_SUFFIX);
 243  0
         if (objValueRendererSource == null)
 244  0
             objValueRendererSource = (IComponent) objSettingsContainer
 245  
                     .getComponents().get(VALUE_RENDERER_BLOCK_SUFFIX);
 246  0
         if (objValueRendererSource != null
 247  
                 && objValueRendererSource instanceof Block)
 248  0
             setValueRendererSource(new BlockTableRendererSource(
 249  
                     (Block) objValueRendererSource));
 250  0
     }
 251  
 
 252  
 }