Coverage Report - net.sf.tacos.components.dojo.form.HtmlArea
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlArea
0% 
0% 
1,286
 
 1  
 // Copyright May 4, 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 net.sf.tacos.components.dojo.form;
 15  
 
 16  
 import java.util.ArrayList;
 17  
 import java.util.HashMap;
 18  
 import java.util.List;
 19  
 import java.util.Map;
 20  
 import org.apache.tapestry.IMarkupWriter;
 21  
 import org.apache.tapestry.IRequestCycle;
 22  
 import org.apache.tapestry.IScript;
 23  
 import org.apache.tapestry.PageRenderSupport;
 24  
 import org.apache.tapestry.TapestryUtils;
 25  
 import org.apache.tapestry.dojo.form.AbstractFormWidget;
 26  
 import org.apache.tapestry.engine.IEngineService;
 27  
 import org.apache.tapestry.form.TranslatedField;
 28  
 import org.apache.tapestry.form.TranslatedFieldSupport;
 29  
 import org.apache.tapestry.form.ValidatableFieldSupport;
 30  
 import org.apache.tapestry.json.JSONObject;
 31  
 import org.apache.tapestry.services.DataSqueezer;
 32  
 import org.apache.tapestry.valid.ValidatorException;
 33  
 
 34  
 /**
 35  
  * An html field similar to a <code>textarea</code> field that 
 36  
  * is wrapped by a dojo Editor2 widget.<p/>
 37  
  * This component adds javascript that makes the dojo widget
 38  
  * update the value of the textarea (to support async submits) it is bound to. 
 39  
  * 
 40  
  * @author andyhot
 41  
  */
 42  0
 public abstract class HtmlArea extends AbstractFormWidget implements TranslatedField
 43  
 {    
 44  
     /**
 45  
      * 
 46  
      * {@inheritDoc}
 47  
      */
 48  
     protected void renderFormWidget(IMarkupWriter writer, IRequestCycle cycle)
 49  
     {
 50  0
         String value = getTranslatedFieldSupport().format(this, getValue());
 51  
         
 52  0
         renderDelegatePrefix(writer, cycle);
 53  
         
 54  0
         writer.begin("textarea");
 55  0
         writer.attribute("name", getName());
 56  
         
 57  0
         if (isDisabled())
 58  0
             writer.attribute("disabled", "disabled");
 59  
         
 60  0
         renderIdAttribute(writer, cycle);
 61  
         
 62  0
         renderDelegateAttributes(writer, cycle);
 63  
         
 64  0
         getTranslatedFieldSupport().renderContributions(this, writer, cycle);
 65  0
         getValidatableFieldSupport().renderContributions(this, writer, cycle);
 66  
         
 67  0
         renderInformalParameters(writer, cycle);
 68  
         
 69  0
         if (value != null) writer.print(value);
 70  
 
 71  0
         writer.end();
 72  
 
 73  0
         renderDelegateSuffix(writer, cycle);
 74  
               
 75  0
         Map parms = new HashMap();
 76  0
         parms.put("id", getClientId());
 77  
         
 78  0
         JSONObject json = new JSONObject();        
 79  0
         json.put((Object)"widgetId", getName());
 80  0
         json.put((Object)"name", getName());
 81  0
         json.put((Object)"disabled", isDisabled());
 82  0
         if (getToolbarTemplatePath()!=null)
 83  0
             json.put((Object)"toolbarTemplatePath", getToolbarTemplatePath());
 84  
         
 85  0
         parms.put("props", json.toString());
 86  0
         parms.put("widget", this);
 87  
         
 88  0
         PageRenderSupport prs = TapestryUtils.getPageRenderSupport(cycle, this);
 89  0
         getScript().execute(this, cycle, prs, parms);
 90  0
     }
 91  
     
 92  
     /**
 93  
      * @see org.apache.tapestry.form.AbstractFormComponent#rewindFormComponent(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle)
 94  
      */
 95  
     protected void rewindFormWidget(IMarkupWriter writer, IRequestCycle cycle)
 96  
     {
 97  0
         String value = cycle.getParameter(getName());
 98  
         
 99  
         try
 100  
         {
 101  0
             String text = (String) getTranslatedFieldSupport().parse(this, value);
 102  
             
 103  0
             getValidatableFieldSupport().validate(this, writer, cycle, text);
 104  
             
 105  0
             setValue(text);
 106  
         }
 107  0
         catch (ValidatorException e)
 108  
         {
 109  0
             getForm().getDelegate().record(e);
 110  0
         }
 111  0
     }    
 112  
     
 113  
     public abstract String getToolbarTemplatePath();
 114  
         
 115  
     /** @since 2.2 * */
 116  
     public abstract Object getValue();
 117  
 
 118  
     /** @since 2.2 * */
 119  
     public abstract void setValue(Object value);
 120  
     
 121  
     /** Injected. */
 122  
     public abstract DataSqueezer getDataSqueezer();
 123  
     
 124  
     /**
 125  
      * Injected.
 126  
      */
 127  
     public abstract ValidatableFieldSupport getValidatableFieldSupport();
 128  
     
 129  
     /**
 130  
      * Injected.
 131  
      */
 132  
     public abstract TranslatedFieldSupport getTranslatedFieldSupport();    
 133  
 
 134  
     /**
 135  
      * Injected.
 136  
      */
 137  
     public abstract IEngineService getDirectService();
 138  
     
 139  
     /**
 140  
      * Injected.
 141  
      */
 142  
     public abstract IScript getScript();
 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  
     /** 
 153  
      * {@inheritDoc}
 154  
      */
 155  
     public List getUpdateComponents()
 156  
     {
 157  0
         List comps = new ArrayList();
 158  0
         comps.add(getClientId());
 159  
         
 160  0
         return comps;
 161  
     }
 162  
     
 163  
     /** 
 164  
      * {@inheritDoc}
 165  
      */
 166  
     public boolean isAsync()
 167  
     {
 168  0
         return false;
 169  
     }
 170  
     
 171  
     /** 
 172  
      * {@inheritDoc}
 173  
      */
 174  
     public boolean isJson()
 175  
     {
 176  0
         return false;
 177  
     }
 178  
 }