001: /*
002: * Copyright 2005 Paul Hinds, Mark Anderson
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.tp23.antinstaller.input;
017:
018: /**
019: *
020: * <p>Input type to choose a single value from a (numbered) list of options
021: * which will be rendered as radio buttons in the Swing GUI </p>
022: * REF: 1177206
023: * @author Paul Hinds, Mark Anderson
024: * @version $Id: TargetSelectInput.java,v 1.4 2006/12/21 00:03:08 teknopaul Exp $
025: */
026: public class TargetSelectInput extends SelectInput implements Target {
027:
028: //targets are ordered
029: private int idx;
030:
031: public TargetSelectInput() {
032: idx = TargetInput.getGlobalIdx();
033: }
034:
035: public int getIdx() {
036: return idx;
037: }
038:
039: public String getTarget() {
040: return super .getDefaultValue();
041: }
042:
043: /**
044: * Used by checkConfig to validate the configuration file.
045: * Not used at runtime.
046: * @return boolean
047: */
048: public boolean validateObject() {
049: if (getDisplayText() == null) {
050: System.out.println("TargetSelect:displayText must be set");
051: return false;
052: }
053: if (getProperty() == null) {
054: System.out.println("TargetSelect:property must be set");
055: return false;
056: }
057: if (getDefaultValue() == null) {
058: System.out.println("TargetSelect:defaultValue must be set");
059: return false;
060: }
061: if (getOptions() == null) {
062: System.out
063: .println("TargetSelect:option must have at least two options");
064: return false;
065: }
066: if (getOptions().length < 2) {
067: System.out
068: .println("TargetSelect:option must have at least two options");
069: return false;
070: }
071: for (int i = 0; i < getOptions().length; i++) {
072: Option o = getOptions()[i];
073: if (o.getText() == null) {
074: System.out
075: .println("TargetSelect:option:text must be set");
076: return false;
077: }
078: if (o.value == null) {
079: System.out
080: .println("TargetSelect:option:value must be set");
081: return false;
082: }
083: }
084: boolean defaultExists = false;
085: for (int i = 0; i < getOptions().length; i++) {
086: Option o = getOptions()[i];
087: if (o.value.equals(getDefaultValue())) {
088: defaultExists = true;
089: }
090: // if(o.value.equals("default")){
091: // System.out.println("Target:target can not be \"default\"");
092: // return false;
093: // }
094: }
095: if (!defaultExists) {
096: System.out
097: .println("TargetSelect:option:Default must be one of the options");
098: return false;
099: }
100: return true;
101: }
102: }
|