Coverage Report - org.apache.tapestry.dojo.html.InlineEditBox
 
Classes in this File Line Coverage Branch Coverage Complexity
InlineEditBox
0% 
0% 
1.4
 
 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  
 package org.apache.tapestry.dojo.html;
 15  
 
 16  
 import org.apache.hivemind.ApplicationRuntimeException;
 17  
 import org.apache.tapestry.*;
 18  
 import org.apache.tapestry.dojo.AbstractWidget;
 19  
 import org.apache.tapestry.engine.DirectServiceParameter;
 20  
 import org.apache.tapestry.engine.IEngineService;
 21  
 import org.apache.tapestry.json.JSONObject;
 22  
 
 23  
 import java.util.Collections;
 24  
 import java.util.HashMap;
 25  
 import java.util.List;
 26  
 import java.util.Map;
 27  
 
 28  
 
 29  
 /**
 30  
  * Wraps a dojo InlineEditBox widget. 
 31  
  * 
 32  
  * <p>
 33  
  * Manages a single string value that when hovered over can be edited "inline" in the document
 34  
  * wherever it is referenced. Supports various modes of operation (ie disable/enabled), as well as 
 35  
  * textarea or single line style edits.
 36  
  * </p>
 37  
  *
 38  
  *
 39  
  * <p>
 40  
  * Some of the commonly used widget functions to listen to are:<br/>
 41  
  * <ul>
 42  
  *  <li><b>onSave - </b>When the save button is clicked. Default function listened to when updating
 43  
  *  server side managed value.
 44  
  *  </li>
 45  
  *  <li><b>onUndo - </b>When cancel button is clicked.</li>
 46  
  *  <li><b>onMouseOver - </b>Mouse moved over editable region.</li>
 47  
  *  <li><b>onMouseOut - </b>Mouse moved away from editable region.</li>
 48  
  * </ul>
 49  
  * </p>
 50  
  * 
 51  
  */
 52  0
 public abstract class InlineEditBox extends AbstractWidget implements IDirect
 53  
 {
 54  
     /** 
 55  
      * Default single line editing text mode. Use as one of two possible
 56  
      * parameters to the <code>mode</code> parameter.
 57  
      */
 58  
     public static final String TEXT_MODE = "text";
 59  
     
 60  
     /** 
 61  
      * Multi line editing text mode. Use as one of two possible
 62  
      * parameters to the <code>mode</code> parameter.
 63  
      */
 64  
     public static final String TEXT_AREA_MODE = "textarea";
 65  
     
 66  
     public abstract String getValue();
 67  
     public abstract void setValue(String value);
 68  
     
 69  
     public abstract String getMode();
 70  
     
 71  
     public abstract int getMinWidth();
 72  
     
 73  
     public abstract int getMinHeight();
 74  
     
 75  
     public abstract boolean getDoFade();
 76  
     
 77  
     public abstract boolean isDiabled();
 78  
     
 79  
     /**
 80  
      * {@inheritDoc}
 81  
      */
 82  
     public void renderWidget(IMarkupWriter writer, IRequestCycle cycle)
 83  
     {
 84  0
         if (!cycle.isRewinding()) {
 85  
             
 86  0
             writer.begin(getTemplateTagName()); // use whatever template tag they specified
 87  0
             renderInformalParameters(writer, cycle);
 88  0
             renderIdAttribute(writer, cycle);
 89  
         }
 90  
         
 91  0
         renderBody(writer, cycle);
 92  
         
 93  0
         if (!cycle.isRewinding()) {
 94  
             
 95  0
             writer.end();
 96  
         }
 97  
         
 98  0
         if(!TEXT_MODE.equals(getMode())
 99  
                 && !TEXT_AREA_MODE.equals(getMode())) {
 100  0
             throw new ApplicationRuntimeException(WidgetMessages.invalidTextMode(getMode()));
 101  
         }
 102  
         
 103  0
         if (cycle.isRewinding()) {
 104  0
             return;
 105  
         }
 106  
         
 107  0
         JSONObject prop = new JSONObject();
 108  0
         prop.put("widgetId", getClientId());
 109  0
         prop.put("value", getValue());
 110  0
         prop.put("mode", getMode());
 111  0
         prop.put("minWidth", getMinWidth());
 112  0
         prop.put("minHeight", getMinHeight());
 113  0
         prop.put("doFade", getDoFade());
 114  
         
 115  0
         Map parms = new HashMap();
 116  0
         parms.put("component", this);
 117  0
         parms.put("props", prop.toString());
 118  
         
 119  0
         PageRenderSupport prs = TapestryUtils.getPageRenderSupport(cycle, this);
 120  0
         getScript().execute(this, cycle, prs, parms);
 121  0
     }
 122  
     
 123  
     /**
 124  
      * Callback url used by client side widget to update server component.
 125  
      */
 126  
     public String getUpdateUrl()
 127  
     {
 128  0
         DirectServiceParameter dsp =
 129  
             new DirectServiceParameter(this);
 130  
         
 131  0
         return getEngine().getLink(false, dsp).getURL();
 132  
     }
 133  
     
 134  
     /**
 135  
      * {@inheritDoc}
 136  
      */
 137  
     public List getUpdateComponents()
 138  
     {
 139  0
         return Collections.EMPTY_LIST;
 140  
     }
 141  
 
 142  
     /**
 143  
      * {@inheritDoc}
 144  
      */
 145  
     public boolean isAsync()
 146  
     {
 147  0
         return true;
 148  
     }
 149  
 
 150  
     /**
 151  
      * {@inheritDoc}
 152  
      */
 153  
     public boolean isJson()
 154  
     {
 155  0
         return false;
 156  
     }
 157  
     
 158  
     /**
 159  
      * {@inheritDoc}
 160  
      */
 161  
     public void trigger(IRequestCycle cycle)
 162  
     {
 163  0
         String newValue = cycle.getParameter(getClientId());
 164  
         
 165  0
         setValue(newValue);
 166  0
     }
 167  
     
 168  
     /** Injected. */
 169  
     public abstract IEngineService getEngine();
 170  
     
 171  
     /** Injected. */
 172  
     public abstract IScript getScript();
 173  
 }