001: /*
002: * CheckBox.java
003: *
004: * Version: $Revision: 1.3 $
005: *
006: * Date: $Date: 2006/07/20 21:47:44 $
007: *
008: * Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
009: * Institute of Technology. All rights reserved.
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are
013: * met:
014: *
015: * - Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * - Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in the
020: * documentation and/or other materials provided with the distribution.
021: *
022: * - Neither the name of the Hewlett-Packard Company nor the name of the
023: * Massachusetts Institute of Technology nor the names of their
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038: * DAMAGE.
039: */
040:
041: package org.dspace.app.xmlui.wing.element;
042:
043: /**
044: * A class representing a CheckBox input control. The checkbox input control is
045: * a boolean control which may be toggled by the user. A checkbox may have
046: * several fields which share the same name and each of those fields may be
047: * toggled independently. This is distinct from a radio button where only one
048: * field may be toggled.
049: *
050: * @author Scott Phillips
051: */
052:
053: import org.dspace.app.xmlui.wing.Message;
054: import org.dspace.app.xmlui.wing.WingContext;
055: import org.dspace.app.xmlui.wing.WingException;
056:
057: public class CheckBox extends Field {
058:
059: /**
060: * Construct a new field.
061: *
062: * @param context
063: * (Required) The context this element is contained in, such as
064: * where to route SAX events and what i18n catalogue to use.
065: *
066: * @param name
067: * (Required) a non-unique local identifier used to differentiate
068: * the element from its siblings within an interactive division.
069: * This is the name of the field use when data is submitted back
070: * to the server.
071: * @param rend
072: * (May be null) a rendering hint used to override the default
073: * display of the element.
074: */
075: protected CheckBox(WingContext context, String name, String rend)
076: throws WingException {
077: super (context, name, Field.TYPE_CHECKBOX, rend);
078: this .params = new Params(context);
079: }
080:
081: /**
082: * Enable the add operation for this field. When this is enabled the
083: * front end will add a button to add more items to the field.
084: *
085: */
086: public void enableAddOperation() throws WingException {
087: this .params.enableAddOperation();
088: }
089:
090: /**
091: * Enable the delete operation for this field. When this is enabled then
092: * the front end will provide a way for the user to select fields (probably
093: * checkboxes) along with a submit button to delete the selected fields.
094: *
095: */
096: public void enableDeleteOperation() throws WingException {
097: this .params.enableDeleteOperation();
098: }
099:
100: /**
101: * Add an option.
102: *
103: * @param returnValue
104: * (Required) The value to be passed back if this option is
105: * selected.
106: */
107: public Option addOption(String returnValue) throws WingException {
108: Option option = new Option(context, returnValue);
109: options.add(option);
110:
111: return option;
112: }
113:
114: /**
115: * Add an option.
116: *
117: * @param returnValue
118: * (Required) The value to be passed back if this option is
119: * selected.
120: */
121: public Option addOption(int returnValue) throws WingException {
122: return addOption(String.valueOf(returnValue));
123: }
124:
125: /**
126: * Add an option.
127: *
128: * @param selected
129: * (Required) Set the option is checked
130: * @param returnValue
131: * (Required) The value to be passed back if this option is
132: * checked.
133: */
134: public Option addOption(boolean selected, String returnValue)
135: throws WingException {
136: if (selected)
137: setOptionSelected(returnValue);
138: return addOption(returnValue);
139: }
140:
141: /**
142: * Add an option.
143: *
144: * @param returnValue
145: * (Required) The value to be passed back if this option is
146: * checked.
147: * @param characters
148: * (Required) The text to set as the visible option.
149: */
150: public void addOption(String returnValue, String characters)
151: throws WingException {
152: Option option = this .addOption(returnValue);
153: option.addContent(characters);
154: }
155:
156: /**
157: * Add an option.
158: *
159: * @param selected
160: * (Required) Set the option is checked
161: * @param returnValue
162: * (Required) The value to be passed back if this option is
163: * checked.
164: * @param characters
165: * (Required) The text to set as the visible option.
166: */
167: public void addOption(boolean selected, String returnValue,
168: String characters) throws WingException {
169: if (selected)
170: setOptionSelected(returnValue);
171: addOption(returnValue, characters);
172: }
173:
174: /**
175: * Add an option.
176: *
177: * @param returnValue
178: * (Required) The value to be passed back if this option is
179: * checked.
180: * @param characters
181: * (Required) The text to set as the visible option.
182: */
183: public void addOption(int returnValue, String characters)
184: throws WingException {
185: Option option = this .addOption(String.valueOf(returnValue));
186: option.addContent(characters);
187: }
188:
189: /**
190: * Add an option.
191: *
192: * @param selected
193: * (Required) Set the option as selected.
194: * @param returnValue
195: * (Required) The value to be passed back if this option is
196: * selected.
197: * @param characters
198: * (Required) The text to set as the visible option.
199: */
200: public void addOption(boolean selected, int returnValue,
201: String characters) throws WingException {
202: if (selected)
203: setOptionSelected(returnValue);
204: addOption(returnValue, characters);
205: }
206:
207: /**
208: * Add an option.
209: *
210: * @param returnValue
211: * (Required) The value to be passed back if this option is
212: * selected.
213: * @param message
214: * (Required) The transalted text to set as the visible option.
215: */
216: public void addOption(String returnValue, Message message)
217: throws WingException {
218: Option option = this .addOption(returnValue);
219: option.addContent(message);
220: }
221:
222: /**
223: * Add an option.
224: *
225: * @param selected
226: * (Required) Set the option as selected.
227: * @param returnValue
228: * (Required) The value to be passed back if this option is
229: * selected.
230: * @param message
231: * (Required) The transalted text to set as the visible option.
232: */
233: public void addOption(boolean selected, String returnValue,
234: Message message) throws WingException {
235: if (selected)
236: setOptionSelected(returnValue);
237: addOption(returnValue, message);
238: }
239:
240: /**
241: * Add an option.
242: *
243: * @param returnValue
244: * (Required) The value to be passed back if this option is
245: * selected.
246: * @param message
247: * (Required) The transalted text to set as the visible option.
248: */
249: public void addOption(int returnValue, Message message)
250: throws WingException {
251: Option option = this .addOption(String.valueOf(returnValue));
252: option.addContent(message);
253: }
254:
255: /**
256: * Add an option.
257: *
258: * @param selected
259: * (Required) Set the field as selected.
260: * @param returnValue
261: * (Required) The value to be passed back if this option is
262: * selected.
263: * @param message
264: * (Required) The transalted text to set as the visible option.
265: */
266: public void addOption(boolean selected, int returnValue,
267: Message message) throws WingException {
268: if (selected)
269: setOptionSelected(returnValue);
270: addOption(returnValue, message);
271: }
272:
273: /**
274: * Set the given option as checked.
275: *
276: * @param returnValue
277: * (Required) The return value of the option to be selected.
278: */
279: public void setOptionSelected(String returnValue)
280: throws WingException {
281: Value value = new Value(context, Value.TYPE_OPTION, returnValue);
282: values.add(value);
283: }
284:
285: /**
286: * Set the given option as selected.
287: *
288: * @param returnValue
289: * (Required) The return value of the option to be selected.
290: */
291: public void setOptionSelected(int returnValue) throws WingException {
292: Value value = new Value(context, Value.TYPE_OPTION, String
293: .valueOf(returnValue));
294: values.add(value);
295: }
296:
297: /**
298: * Add a field instance
299: * @return instance
300: */
301: public Instance addInstance() throws WingException {
302: Instance instance = new Instance(context);
303: instances.add(instance);
304: return instance;
305: }
306: }
|