Coverage Report - org.apache.tapestry.dojo.form.DropdownTimePicker
 
Classes in this File Line Coverage Branch Coverage Complexity
DropdownTimePicker
74% 
100% 
1.2
 
 1  
 // Copyright Jun 10, 2006 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  
 package org.apache.tapestry.dojo.form;
 15  
 
 16  
 import org.apache.tapestry.IMarkupWriter;
 17  
 import org.apache.tapestry.IRequestCycle;
 18  
 import org.apache.tapestry.IScript;
 19  
 import org.apache.tapestry.TapestryUtils;
 20  
 import org.apache.tapestry.form.TranslatedField;
 21  
 import org.apache.tapestry.form.TranslatedFieldSupport;
 22  
 import org.apache.tapestry.form.ValidatableFieldSupport;
 23  
 import org.apache.tapestry.form.translator.DateTranslator;
 24  
 import org.apache.tapestry.json.JSONObject;
 25  
 import org.apache.tapestry.valid.ValidatorException;
 26  
 
 27  
 import java.util.HashMap;
 28  
 import java.util.Map;
 29  
 
 30  
 /**
 31  
  * Implementation of the dojo DropdownTimePicker widget as a tapestry
 32  
  * component. Wraps a form input field with a date picker icon next to it
 33  
  * that when clicked on reveals a pane to choose time values from. 
 34  
  * 
 35  
  * @author jkuhnert
 36  
  */
 37  1
 public abstract class DropdownTimePicker extends AbstractFormWidget implements TranslatedField
 38  
 {
 39  
     
 40  
     /** parameter. */
 41  
     public abstract Object getValue();
 42  
     
 43  
     public abstract void setValue(Object value);
 44  
     
 45  
     public abstract boolean isDisabled();
 46  
     
 47  
     /** Alt html text for the date icon, what is displayed when mouse hovers over icon. */
 48  
     public abstract String getIconAlt();
 49  
     
 50  
     /**
 51  
      * {@inheritDoc}
 52  
      */
 53  
     protected void renderFormWidget(IMarkupWriter writer, IRequestCycle cycle)
 54  
     {
 55  
         // dojo dates are in POSIX style formats so we format the value manually
 56  1
         DateTranslator translator = (DateTranslator) getTranslator();
 57  
         
 58  1
         renderDelegatePrefix(writer, cycle);
 59  
         
 60  
         // the html output doesn't matter very much as dojo
 61  
         // will create an inline input field for us anyways, but we do need
 62  
         // a node to reference
 63  1
         writer.begin("div");
 64  1
         renderIdAttribute(writer, cycle);
 65  
         
 66  1
         renderDelegateAttributes(writer, cycle);
 67  
         
 68  1
         getValidatableFieldSupport().renderContributions(this, writer, cycle);
 69  
         
 70  1
         renderInformalParameters(writer, cycle);
 71  
         
 72  1
         writer.print(" ");
 73  
         
 74  1
         writer.end();
 75  1
         renderDelegateSuffix(writer, cycle);
 76  
         
 77  
         // now create widget parms
 78  1
         JSONObject json = new JSONObject();
 79  1
         json.put("inputId", getClientId());
 80  1
         json.put("inputName", getName());
 81  1
         json.put("iconAlt", getIconAlt());
 82  1
         json.put("displayFormat", translator.getPattern(getPage().getLocale()));
 83  1
         json.put("saveFormat", translator.getPattern(getPage().getLocale()));
 84  
         
 85  1
         if (getValue() != null) {
 86  1
             json.put("value", translator.formatRfc3339(getValue()));
 87  
         }
 88  
         
 89  1
         json.put("disabled", isDisabled());
 90  
         
 91  1
         Map parms = new HashMap();
 92  1
         parms.put("clientId", getClientId());
 93  1
         parms.put("props", json.toString());
 94  1
         parms.put("widget", this);
 95  
         
 96  1
         getScript().execute(this, cycle, TapestryUtils.getPageRenderSupport(cycle, this), parms);
 97  1
     }
 98  
     
 99  
     /**
 100  
      * @see org.apache.tapestry.form.AbstractFormComponent#rewindFormComponent(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle)
 101  
      */
 102  
     protected void rewindFormWidget(IMarkupWriter writer, IRequestCycle cycle)
 103  
     {
 104  0
         String value = cycle.getParameter(getName());
 105  
         
 106  
         try
 107  
         {
 108  0
             Object translated = getTranslatedFieldSupport().parse(this, value);
 109  
             
 110  0
             getValidatableFieldSupport().validate(this, writer, cycle, translated);
 111  
             
 112  0
             setValue(translated);
 113  
         }
 114  0
         catch (ValidatorException e)
 115  
         {
 116  0
             getForm().getDelegate().record(e);
 117  0
         }
 118  0
     }
 119  
     
 120  
     /**
 121  
      * @see org.apache.tapestry.form.AbstractFormComponent#isRequired()
 122  
      */
 123  
     public boolean isRequired()
 124  
     {
 125  0
         return getValidatableFieldSupport().isRequired(this);
 126  
     }
 127  
     
 128  
     /** Injected. */
 129  
     public abstract IScript getScript();
 130  
     
 131  
     /** Injected. */
 132  
     public abstract TranslatedFieldSupport getTranslatedFieldSupport();
 133  
     
 134  
     /** Injected. */
 135  
     public abstract ValidatableFieldSupport getValidatableFieldSupport();
 136  
     
 137  
 }