01: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
02: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
03: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
04: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
05: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
06: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
07: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
08: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
09: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
10: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
11: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
12: // POSSIBILITY OF SUCH DAMAGE.
13: //
14: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
15: package com.metaboss.enterprise.xi.enhydrabarracuda.htmlwidgets;
16:
17: import org.w3c.dom.html.HTMLInputElement;
18:
19: import com.metaboss.enterprise.ui.UIUnexpectedProgramConditionException;
20: import com.metaboss.enterprise.xi.enhydrabarracuda.Widget;
21: import com.metaboss.enterprise.xi.enhydrabarracuda.WidgetModel;
22:
23: /** This class is the very simple checkbox implementation */
24: public class CheckEdit extends Widget {
25: /** This class represents the data model of the checkbox input control */
26: public static class Model implements WidgetModel {
27: private Boolean mIsChecked = null;
28:
29: /** Returns true if the checkbox is checked and false otherwise.
30: * If null is returned from here the checkbox will stay unmodified */
31: public Boolean isChecked() {
32: return mIsChecked;
33: }
34:
35: /** Sets the value of the checkbox to be set into the checkbox widget. */
36: public void setChecked(boolean pIsChecked) {
37: mIsChecked = new Boolean(pIsChecked);
38: }
39:
40: /** This method is used to apply the values passed from the form back into the model.
41: * @return the model object after the form values have been applied (The model object may just return itself)
42: * @exception UIUnexpectedProgramConditionException thrown when this widget model does not support editing */
43: public void applyFormValues(String[] pValues)
44: throws UIUnexpectedProgramConditionException {
45: if (pValues == null || pValues.length != 1
46: || pValues[0] == null)
47: throw new UIUnexpectedProgramConditionException(
48: "Unexpected value passed from form. Expecting single string value");
49: mIsChecked = Boolean.valueOf(pValues[0]);
50: }
51:
52: /** This method used primarily for debug purposes. It is expected to output a single string value reflecting the content of the model */
53: public String getDebugString() {
54: return mIsChecked != null ? mIsChecked.toString() : "null";
55: }
56: }
57:
58: /** This standard method creates an instance of the model object for this widget */
59: public WidgetModel createModel() {
60: // Get the inlut element and create the model object initialised with it
61: HTMLInputElement lInputElement = (HTMLInputElement) getBoundDocumentElement();
62: Model lModel = new Model();
63: lModel.setChecked(lInputElement.getChecked());
64: return lModel;
65: }
66:
67: /** This lifecycle method is expected to render the control's image onto the document */
68: public void render() {
69: HTMLInputElement lInputElement = (HTMLInputElement) getBoundDocumentElement();
70: Model lModel = (Model) getModel();
71: Boolean lIsChecked = lModel.isChecked();
72: if (lIsChecked != null)
73: lInputElement.setChecked(lIsChecked.booleanValue());
74: }
75: }
|