001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry.contrib.table.model.simple;
016
017 import org.apache.tapestry.IRender;
018 import org.apache.tapestry.IRequestCycle;
019 import org.apache.tapestry.contrib.table.model.ITableColumn;
020 import org.apache.tapestry.contrib.table.model.ITableModelSource;
021 import org.apache.tapestry.contrib.table.model.ITableRendererSource;
022 import org.apache.tapestry.valid.RenderString;
023
024 /**
025 * This is a simple implementation of
026 * {@link org.apache.tapestry.contrib.table.model.ITableRendererSource} that
027 * returns a standard renderer of a column value. This implementation requires
028 * that the column passed is of type SimpleTableColumn
029 *
030 * @see org.apache.tapestry.contrib.table.model.common.AbstractTableColumn
031 * @author mindbridge
032 * @since 2.3
033 */
034 public class SimpleTableValueRendererSource implements ITableRendererSource
035 {
036 private static final long serialVersionUID = 1L;
037
038 /**
039 * The representation of null values. This is geared towards HTML, but will
040 * work for some other *ML languages as well. In any case, changing the
041 * column's value renderer allows selecting fully custom rendering
042 * behaviour.
043 */
044 private static final String EMPTY_REPRESENTATION = " ";
045
046 /**
047 * @see org.apache.tapestry.contrib.table.model.ITableRendererSource#getRenderer(IRequestCycle,
048 * ITableModelSource, ITableColumn, Object)
049 */
050 public IRender getRenderer(IRequestCycle objCycle,
051 ITableModelSource objSource, ITableColumn objColumn, Object objRow)
052 {
053 SimpleTableColumn objSimpleColumn = (SimpleTableColumn) objColumn;
054
055 Object objValue = objSimpleColumn.getColumnValue(objRow);
056 if (objValue == null)
057 return new RenderString(EMPTY_REPRESENTATION, true);
058
059 return new RenderString(objValue.toString());
060 }
061
062 }