Coverage Report - org.trails.component.AbstractPropertySelectionModel
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractPropertySelectionModel
84% 
100% 
1.6
 
 1  
 package org.trails.component;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.List;
 5  
 
 6  
 import org.apache.tapestry.form.IPropertySelectionModel;
 7  
 import org.trails.TrailsRuntimeException;
 8  
 import ognl.Ognl;
 9  
 
 10  
 public abstract class AbstractPropertySelectionModel implements IPropertySelectionModel
 11  
 {
 12  
         protected List instances;
 13  
         protected boolean allowNone;
 14  46
         protected String labelProperty = "toString()";
 15  
         public static final String DEFAULT_NONE_LABEL = "None";
 16  
         public static final String DEFAULT_NONE_VALUE = "none";
 17  46
         protected String noneLabel = DEFAULT_NONE_LABEL;
 18  
 
 19  
         public AbstractPropertySelectionModel(List instances)
 20  
         {
 21  7
                 this(instances, false);
 22  7
         }
 23  
 
 24  46
         public AbstractPropertySelectionModel(List instances, boolean allowNone)
 25  
         {
 26  46
                 this.allowNone = allowNone;
 27  46
                 this.instances = new ArrayList();
 28  46
                 this.instances.addAll(instances);
 29  46
                 if (this.allowNone)
 30  
                 {
 31  23
                         this.instances.add(0, null);
 32  
                 }
 33  46
         }
 34  
 
 35  
         public String getNoneLabel()
 36  
         {
 37  6
                 return noneLabel;
 38  
         }
 39  
 
 40  
         public void setNoneLabel(String noneLabel)
 41  
         {
 42  8
                 this.noneLabel = noneLabel;
 43  8
         }
 44  
 
 45  
         public String getLabelProperty()
 46  
         {
 47  0
                 return labelProperty;
 48  
         }
 49  
 
 50  
         public void setLabelProperty(String labelProperty)
 51  
         {
 52  7
                 this.labelProperty = labelProperty;
 53  7
         }
 54  
 
 55  
         /**
 56  
          * (non-Javadoc)
 57  
          *
 58  
          * @see org.apache.tapestry.form.IPropertySelectionModel#getOptionCount()
 59  
          */
 60  
         public int getOptionCount()
 61  
         {
 62  12
                 return instances.size();
 63  
         }
 64  
 
 65  
         /**
 66  
          * (non-Javadoc)
 67  
          *
 68  
          * @see org.apache.tapestry.form.IPropertySelectionModel#getOption(int)
 69  
          */
 70  
         public Object getOption(int index)
 71  
         {
 72  1
                 return instances.get(index);
 73  
         }
 74  
 
 75  
 
 76  
         /**
 77  
          * (non-Javadoc)
 78  
          *
 79  
          * @see org.apache.tapestry.form.IPropertySelectionModel#getLabel(int)
 80  
          */
 81  
         public String getLabel(int index)
 82  
         {
 83  11
                 if (allowNone && index == 0)
 84  
                 {
 85  4
                         return getNoneLabel();
 86  
                 }
 87  
                 try
 88  
                 {
 89  7
                         return Ognl.getValue(labelProperty, instances.get(index)).toString();
 90  0
                 } catch (Exception e)
 91  
                 {
 92  0
                         throw new TrailsRuntimeException(e);
 93  
                 }
 94  
         }
 95  
 
 96  
         public boolean isDisabled(int i)
 97  
         {
 98  0
                 return false;
 99  
         }
 100  
 }