Coverage Report - org.apache.tapestry.dojo.form.DropdownDatePicker
 
Classes in this File Line Coverage Branch Coverage Complexity
DropdownDatePicker
0%
0/47
0%
0/14
1.5
 
 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 DropdownDatePicker 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 calendar to choose date values from. 
 34  
  * 
 35  
  * @author jkuhnert
 36  
  */
 37  0
 public abstract class DropdownDatePicker 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  
     public abstract int getDisplayWeeks();
 51  
 
 52  
     public abstract boolean isAdjustWeeks();
 53  
 
 54  
     public abstract Object getStartDate();
 55  
 
 56  
     public abstract Object getEndDate();
 57  
 
 58  
     public abstract int getWeekStartsOn();
 59  
 
 60  
     public abstract boolean isStaticDisplay();
 61  
     
 62  
     /**
 63  
      * {@inheritDoc}
 64  
      */
 65  
     protected void renderFormWidget(IMarkupWriter writer, IRequestCycle cycle)
 66  
     {
 67  
         // dojo dates are in POSIX style formats so we format the value manually
 68  0
         DateTranslator translator = (DateTranslator) getTranslator();
 69  
         
 70  0
         renderDelegatePrefix(writer, cycle);
 71  
         
 72  
         // the html output doesn't matter very much as dojo
 73  
         // will create an inline input field for us anyways, but we do need
 74  
         // a node to reference
 75  0
         writer.begin(getTemplateTagName());
 76  0
         renderIdAttribute(writer, cycle);
 77  
         
 78  0
         renderDelegateAttributes(writer, cycle);
 79  
         
 80  0
         getValidatableFieldSupport().renderContributions(this, writer, cycle);
 81  
         
 82  0
         renderInformalParameters(writer, cycle);
 83  
         
 84  0
         writer.print(" ");
 85  
         
 86  0
         writer.end();
 87  0
         renderDelegateSuffix(writer, cycle);
 88  
         
 89  
         // now create widget parms
 90  0
         JSONObject json = new JSONObject();
 91  0
         json.put("inputId", getClientId());
 92  0
         json.put("inputName", getName());
 93  0
         json.put("iconAlt", getIconAlt());
 94  0
         json.put("displayFormat", translator.getPattern(getPage().getLocale()));
 95  0
         json.put("saveFormat", translator.getPattern(getPage().getLocale()));
 96  
         
 97  0
         if (getValue() != null) {
 98  0
             json.put("value", translator.formatRfc3339(getValue()));
 99  
         }
 100  
         
 101  0
         json.put("disabled", isDisabled());
 102  0
         if (getDisplayWeeks() > 0)
 103  0
             json.put("displayWeeks", getDisplayWeeks());
 104  0
         if (isAdjustWeeks())
 105  0
             json.put("adjustWeeks", isAdjustWeeks());
 106  0
         if (getStartDate() != null)
 107  0
             json.put("startDate", translator.formatRfc3339(getStartDate()));
 108  0
         if (getEndDate() != null)
 109  0
             json.put("endDate", translator.formatRfc3339(getEndDate()));
 110  0
         if (getWeekStartsOn() > -1)
 111  0
             json.put("weekStartsOn", getWeekStartsOn());
 112  0
         if (isStaticDisplay())
 113  0
             json.put("staticDisplay", isStaticDisplay());
 114  
 
 115  0
         Map parms = new HashMap();
 116  0
         parms.put("clientId", getClientId());
 117  0
         parms.put("props", json.toString());
 118  0
         parms.put("widget", this);
 119  
         
 120  0
         getScript().execute(this, cycle, TapestryUtils.getPageRenderSupport(cycle, this), parms);
 121  0
     }
 122  
     
 123  
     /**
 124  
      * @see org.apache.tapestry.form.AbstractFormComponent#rewindFormComponent(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle)
 125  
      */
 126  
     protected void rewindFormWidget(IMarkupWriter writer, IRequestCycle cycle)
 127  
     {
 128  0
         String value = cycle.getParameter(getName());
 129  
         
 130  
         try
 131  
         {
 132  0
             Object translated = getTranslatedFieldSupport().parse(this, value);
 133  
             
 134  0
             getValidatableFieldSupport().validate(this, writer, cycle, translated);
 135  
             
 136  0
             setValue(translated);
 137  
         }
 138  0
         catch (ValidatorException e)
 139  
         {
 140  0
             getForm().getDelegate().record(e);
 141  0
         }
 142  0
     }
 143  
     
 144  
     /**
 145  
      * @see org.apache.tapestry.form.AbstractFormComponent#isRequired()
 146  
      */
 147  
     public boolean isRequired()
 148  
     {
 149  0
         return getValidatableFieldSupport().isRequired(this);
 150  
     }
 151  
     
 152  
     /** Injected. */
 153  
     public abstract IScript getScript();
 154  
     
 155  
     /** Injected. */
 156  
     public abstract TranslatedFieldSupport getTranslatedFieldSupport();
 157  
     
 158  
     /** Injected. */
 159  
     public abstract ValidatableFieldSupport getValidatableFieldSupport();
 160  
     
 161  
 }