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