1 | /*
|
---|
2 | * Copyright 2005 Paul Hinds, Mark Anderson
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
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 |
|
---|
19 | /**
|
---|
20 | *
|
---|
21 | * <p>Input type to choose a single value from a (numbered) list of options
|
---|
22 | * which will be rendered as radio buttons in the Swing GUI </p>
|
---|
23 | * REF: 1177206
|
---|
24 | * @author Paul Hinds, Mark Anderson
|
---|
25 | * @version $Id: TargetSelectInput.java,v 1.4 2006/12/21 00:03:08 teknopaul Exp $
|
---|
26 | */
|
---|
27 | public class TargetSelectInput
|
---|
28 | extends SelectInput
|
---|
29 | implements Target{
|
---|
30 |
|
---|
31 | //targets are ordered
|
---|
32 | private int idx;
|
---|
33 |
|
---|
34 | public TargetSelectInput() {
|
---|
35 | idx = TargetInput.getGlobalIdx();
|
---|
36 | }
|
---|
37 |
|
---|
38 | public int getIdx() {
|
---|
39 | return idx;
|
---|
40 | }
|
---|
41 |
|
---|
42 | public String getTarget(){
|
---|
43 | return super.getDefaultValue();
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Used by checkConfig to validate the configuration file.
|
---|
48 | * Not used at runtime.
|
---|
49 | * @return boolean
|
---|
50 | */
|
---|
51 | public boolean validateObject() {
|
---|
52 | if(getDisplayText() == null){
|
---|
53 | System.out.println("TargetSelect:displayText must be set");
|
---|
54 | return false;
|
---|
55 | }
|
---|
56 | if(getProperty() == null){
|
---|
57 | System.out.println("TargetSelect:property must be set");
|
---|
58 | return false;
|
---|
59 | }
|
---|
60 | if(getDefaultValue() == null){
|
---|
61 | System.out.println("TargetSelect:defaultValue must be set");
|
---|
62 | return false;
|
---|
63 | }
|
---|
64 | if(getOptions() == null){
|
---|
65 | System.out.println("TargetSelect:option must have at least two options");
|
---|
66 | return false;
|
---|
67 | }
|
---|
68 | if(getOptions().length < 2){
|
---|
69 | System.out.println("TargetSelect:option must have at least two options");
|
---|
70 | return false;
|
---|
71 | }
|
---|
72 | for (int i = 0; i < getOptions().length; i++) {
|
---|
73 | Option o = getOptions()[i];
|
---|
74 | if(o.getText() == null){
|
---|
75 | System.out.println("TargetSelect:option:text must be set");
|
---|
76 | return false;
|
---|
77 | }
|
---|
78 | if(o.value == null){
|
---|
79 | System.out.println("TargetSelect:option:value must be set");
|
---|
80 | return false;
|
---|
81 | }
|
---|
82 | }
|
---|
83 | boolean defaultExists = false;
|
---|
84 | for (int i = 0; i < getOptions().length; i++) {
|
---|
85 | Option o = getOptions()[i];
|
---|
86 | if(o.value.equals(getDefaultValue())){
|
---|
87 | defaultExists=true;
|
---|
88 | }
|
---|
89 | // if(o.value.equals("default")){
|
---|
90 | // System.out.println("Target:target can not be \"default\"");
|
---|
91 | // return false;
|
---|
92 | // }
|
---|
93 | }
|
---|
94 | if(!defaultExists){
|
---|
95 | System.out.println("TargetSelect:option:Default must be one of the options");
|
---|
96 | return false;
|
---|
97 | }
|
---|
98 | return true;
|
---|
99 | }
|
---|
100 | }
|
---|