Coverage Report - org.apache.tapestry5.corelib.pages.PropertyEditBlocks
 
Classes in this File Line Coverage Branch Coverage Complexity
PropertyEditBlocks
100%
14/14
N/A
0
 
 1  
 // Copyright 2007, 2008 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.tapestry5.corelib.pages;
 16  
 
 17  
 import org.apache.tapestry5.FieldTranslator;
 18  
 import org.apache.tapestry5.FieldValidator;
 19  
 import org.apache.tapestry5.SelectModel;
 20  
 import org.apache.tapestry5.ValueEncoder;
 21  
 import org.apache.tapestry5.annotations.Component;
 22  
 import org.apache.tapestry5.annotations.Environmental;
 23  
 import org.apache.tapestry5.corelib.components.*;
 24  
 import org.apache.tapestry5.services.BeanBlockContribution;
 25  
 import org.apache.tapestry5.services.BeanBlockSource;
 26  
 import org.apache.tapestry5.services.PropertyEditContext;
 27  
 import org.apache.tapestry5.util.EnumSelectModel;
 28  
 import org.apache.tapestry5.util.EnumValueEncoder;
 29  
 
 30  
 /**
 31  
  * A page that exists to contain blocks used to edit different types of properties. The blocks on this page are
 32  
  * contributed into the {@link BeanBlockSource} service configuration.
 33  
  *
 34  
  * @see BeanBlockContribution
 35  
  * @see BeanEditForm
 36  
  */
 37  8
 public class PropertyEditBlocks
 38  
 {
 39  
     @Environmental
 40  
     private PropertyEditContext context;
 41  
 
 42  
     @Component(
 43  
             parameters = {"value=context.propertyValue", "label=prop:context.label",
 44  
                     "translate=prop:textFieldTranslator", "validate=prop:textFieldValidator",
 45  
                     "clientId=prop:context.propertyId", "annotationProvider=context"})
 46  
     private TextField textField;
 47  
 
 48  
     @Component(
 49  
             parameters = {"value=context.propertyValue", "label=prop:context.label",
 50  
                     "translate=prop:numberFieldTranslator", "validate=prop:numberFieldValidator",
 51  
                     "clientId=prop:context.propertyId", "annotationProvider=context"})
 52  
     private TextField numberField;
 53  
 
 54  
 
 55  
     @Component(
 56  
             parameters = {"value=context.propertyValue", "label=prop:context.label", "encoder=valueEncoderForProperty",
 57  
                     "model=selectModelForProperty", "validate=prop:selectValidator",
 58  
                     "clientId=prop:context.propertyId"})
 59  
     private Select select;
 60  
 
 61  
     @SuppressWarnings("unused")
 62  
     @Component(
 63  
             parameters = {"value=context.propertyValue", "label=prop:context.label",
 64  
                     "clientId=prop:context.propertyId"})
 65  
     private Checkbox checkboxField;
 66  
 
 67  
     @SuppressWarnings("unused")
 68  
     @Component(
 69  
             parameters = {"value=context.propertyValue", "label=prop:context.label", "clientId=prop:context.propertyid",
 70  
                     "validate=prop:dateFieldValidator"})
 71  
     private DateField dateField;
 72  
 
 73  
     @Component(
 74  
             parameters = {"value=context.propertyValue", "label=prop:context.label",
 75  
                     "translate=prop:passwordFieldTranslator", "validate=prop:passwordFieldValidator",
 76  
                     "clientId=prop:context.propertyId", "annotationProvider=context"})
 77  
     private PasswordField passwordField;
 78  
 
 79  
     @Component(
 80  
             parameters = {"value=context.propertyValue", "label=prop:context.label",
 81  
                     "translate=prop:textAreaTranslator",
 82  
                     "validate=prop:textAreaValidator", "clientId=prop:context.propertyId",
 83  
                     "annotationProvider=context"})
 84  
     private TextArea textArea;
 85  
 
 86  
 
 87  
     public PropertyEditContext getContext()
 88  
     {
 89  1360
         return context;
 90  
     }
 91  
 
 92  
 
 93  
     public FieldTranslator getTextFieldTranslator()
 94  
     {
 95  124
         return context.getTranslator(textField);
 96  
     }
 97  
 
 98  
     public FieldValidator getTextFieldValidator()
 99  
     {
 100  124
         return context.getValidator(textField);
 101  
     }
 102  
 
 103  
     public FieldTranslator getNumberFieldTranslator()
 104  
     {
 105  84
         return context.getTranslator(numberField);
 106  
     }
 107  
 
 108  
     public FieldValidator getNumberFieldValidator()
 109  
     {
 110  84
         return context.getValidator(numberField);
 111  
     }
 112  
 
 113  
     public FieldTranslator getPasswordFieldTranslator()
 114  
     {
 115  60
         return context.getTranslator(passwordField);
 116  
     }
 117  
 
 118  
     public FieldValidator getPasswordFieldValidator()
 119  
     {
 120  60
         return context.getValidator(passwordField);
 121  
     }
 122  
 
 123  
     public FieldTranslator getTextAreaTranslator()
 124  
     {
 125  32
         return context.getTranslator(textArea);
 126  
     }
 127  
 
 128  
     public FieldValidator getTextAreaValidator()
 129  
     {
 130  32
         return context.getValidator(textArea);
 131  
     }
 132  
 
 133  
 
 134  
     public FieldValidator getDateFieldValidator()
 135  
     {
 136  6
         return context.getValidator(dateField);
 137  
     }
 138  
 
 139  
     public FieldValidator getSelectValidator()
 140  
     {
 141  38
         return context.getValidator(select);
 142  
     }
 143  
 
 144  
     /**
 145  
      * Provide a value encoder for an enum type.
 146  
      */
 147  
     @SuppressWarnings("unchecked")
 148  
     public ValueEncoder getValueEncoderForProperty()
 149  
     {
 150  38
         return new EnumValueEncoder(context.getPropertyType());
 151  
     }
 152  
 
 153  
     /**
 154  
      * Provide a select mode for an enum type.
 155  
      */
 156  
     @SuppressWarnings("unchecked")
 157  
     public SelectModel getSelectModelForProperty()
 158  
     {
 159  26
         return new EnumSelectModel(context.getPropertyType(), context.getContainerMessages());
 160  
     }
 161  
 }