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