Coverage Report - org.apache.tapestry.contrib.form.checkboxes.CheckboxGroup
 
Classes in this File Line Coverage Branch Coverage Complexity
CheckboxGroup
0%
0/19
0%
0/4
1.333
 
 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.form.checkboxes;
 16  
 
 17  
 import java.util.Collection;
 18  
 
 19  
 import org.apache.tapestry.BaseComponent;
 20  
 import org.apache.tapestry.IMarkupWriter;
 21  
 import org.apache.tapestry.IRequestCycle;
 22  
 import org.apache.tapestry.PageRenderSupport;
 23  
 import org.apache.tapestry.TapestryUtils;
 24  
 
 25  
 /**
 26  
  * @author mb
 27  
  * @since 4.0
 28  
  */
 29  0
 public abstract class CheckboxGroup extends BaseComponent
 30  
 {
 31  
     public static final String CHECKBOX_GROUP_ATTRIBUTE = "org.apache.tapestry.contrib.form.CheckboxGroup";
 32  
     
 33  
     public abstract Collection getCheckboxNames();
 34  
     public abstract String getFunctionName();
 35  
     public abstract void setFunctionName(String functionName);    
 36  
 
 37  
     public void registerControlledCheckbox(ControlledCheckbox checkbox)
 38  
     {
 39  0
         String name = checkbox.getCheckboxName();
 40  0
         String form = checkbox.getForm().getName();
 41  0
         getCheckboxNames().add(form + "." + name);
 42  0
     }
 43  
     
 44  
     /**
 45  
      * @see org.apache.tapestry.BaseComponent#renderComponent(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle)
 46  
      */
 47  
     protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
 48  
     {
 49  0
         Object objOtherGroup = cycle.getAttribute(CHECKBOX_GROUP_ATTRIBUTE);
 50  0
         cycle.setAttribute(CHECKBOX_GROUP_ATTRIBUTE, this);
 51  
         
 52  0
         initialize(cycle);
 53  
         
 54  0
         super.renderComponent(writer, cycle);
 55  
 
 56  
         // clear the registered checkbox names after rendering
 57  
         // allows the component to be used in cycles
 58  0
         getCheckboxNames().clear();
 59  
 
 60  0
         cycle.setAttribute(CHECKBOX_GROUP_ATTRIBUTE, objOtherGroup);
 61  0
     }
 62  
 
 63  
     private void initialize(IRequestCycle cycle)
 64  
     {
 65  0
         String functionName = "setCheckboxGroup";
 66  
 
 67  0
         if (!cycle.isRewinding()) {
 68  0
             PageRenderSupport body = TapestryUtils.getPageRenderSupport(cycle, this);
 69  0
             if (body != null)
 70  0
                 functionName = body.getUniqueString("setCheckboxGroup");
 71  
         }
 72  
         
 73  0
         setFunctionName(functionName);
 74  0
     }
 75  
     
 76  
 }