Coverage Report - org.trails.component.TrailsTableColumn
 
Classes in this File Line Coverage Branch Coverage Complexity
TrailsTableColumn
81% 
100% 
3
 
 1  
 package org.trails.component;
 2  
 
 3  
 import org.apache.tapestry.contrib.table.model.ognl.ExpressionTableColumn;
 4  
 import org.apache.tapestry.services.ExpressionEvaluator;
 5  
 import org.trails.descriptor.IPropertyDescriptor;
 6  
 
 7  
 import java.text.DecimalFormat;
 8  
 import java.text.Format;
 9  
 import java.text.SimpleDateFormat;
 10  
 
 11  
 public class TrailsTableColumn extends ExpressionTableColumn
 12  
 {
 13  
 
 14  
         protected IPropertyDescriptor propertyDescriptor;
 15  
 
 16  
         public TrailsTableColumn(IPropertyDescriptor propertyDescriptor, ExpressionEvaluator evaluator)
 17  
         {
 18  64
                 super(propertyDescriptor.getName(), propertyDescriptor.getDisplayName(),
 19  64
                                 propertyDescriptor.getName(), true, evaluator);
 20  64
                 this.propertyDescriptor = propertyDescriptor;
 21  64
         }
 22  
 
 23  
         public IPropertyDescriptor getPropertyDescriptor()
 24  
         {
 25  0
                 return propertyDescriptor;
 26  
         }
 27  
 
 28  
         public Object getColumnValue(Object arg0)
 29  
         {
 30  8
                 Object value = super.getColumnValue(arg0);
 31  8
                 if (propertyDescriptor.getFormat() != null)
 32  
                 {
 33  
                         try
 34  
                         {
 35  8
                                 Format format = null;
 36  8
                                 if (propertyDescriptor.isDate())
 37  
                                 {
 38  8
                                         format = new SimpleDateFormat(propertyDescriptor.getFormat());
 39  
                                 }
 40  8
                                 if (propertyDescriptor.isNumeric())
 41  
                                 {
 42  0
                                         format = new DecimalFormat(propertyDescriptor.getFormat());
 43  
                                 }
 44  8
                                 return format.format(value);
 45  4
                         } catch (IllegalArgumentException e)
 46  
                         {
 47  4
                                 return value;
 48  
                         }
 49  
                 } else
 50  
                 {
 51  0
                         return value;
 52  
                 }
 53  
         }
 54  
 }