01: /*
02: * Copyright 2005 Paul Hinds
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.tp23.antinstaller.input;
17:
18: import org.tp23.antinstaller.InstallerContext;
19: import org.tp23.antinstaller.ValidationException;
20:
21: /**
22: *
23: * <p>Input type for boolean choices represented as a checkbox in swing and a yes/no option
24: * on the command line </p>
25: * @author Paul Hinds
26: * @version $Id: CheckboxInput.java,v 1.3 2006/12/07 02:42:22 teknopaul Exp $
27: */
28: public class CheckboxInput extends InputField {
29:
30: private String force;
31:
32: public CheckboxInput() {
33: }
34:
35: public String getForce() {
36: return force;
37: }
38:
39: public void setForce(String force) {
40: this .force = force;
41: }
42:
43: public void setValue(String trueOrFalse) {
44: setInputResult(trueOrFalse);
45: }
46:
47: /**
48: * Called to validate the user input
49: * @TODO should validate against non internationalized true or false flags
50: */
51: public boolean validate(InstallerContext cxt)
52: throws ValidationException {
53: return true;
54: }
55:
56: /**
57: * Used by checkConfig to validate the configuration file.
58: * Not used at runtime.
59: * @return boolean
60: */
61: public boolean validateObject() {
62: if (getProperty() == null) {
63: System.out.println("Checkbox:property must be set");
64: return false;
65: }
66: if (getDisplayText() == null) {
67: System.out.println("Checkbox:displayText must be set");
68: return false;
69: }
70: if (!InputField.requiredBoolean(getDefaultValue())) {
71: System.out
72: .println("Checkbox:defaultValue must be true or false");
73: return false;
74: }
75: if (!InputField.optionalBoolean(getForce())) {
76: System.out
77: .println("Checkbox:defaultValue must be true or false or null");
78: return false;
79: }
80: return true;
81: }
82:
83: }
|