source: release-kits/shared/ant-installer/src/org/tp23/antinstaller/input/LargeSelectInput.java@ 17514

Last change on this file since 17514 was 17514, checked in by oranfry, 16 years ago

changes to the way ant-installer loads and reloads the language packs, and a new attribute to the select input which triggers it to change the language to the input value

File size: 3.6 KB
Line 
1/*
2 * Copyright 2005 Paul Hinds
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 */
16package org.tp23.antinstaller.input;
17
18
19import java.util.MissingResourceException;
20import java.util.ResourceBundle;
21
22import org.tp23.antinstaller.InstallerContext;
23import org.tp23.antinstaller.ValidationException;
24
25
26
27/**
28 *
29 * <p>Input type to choose a single value from a (numbered) list of options </p>
30 * <p>This input is designed to handle larger lists of options </p>
31 * <p>Copyright: Copyright (c) 2004</p>
32 * <p>Company: tp23</p>
33 * @author Paul Hinds
34 * @version $Id: LargeSelectInput.java,v 1.3 2006/12/07 02:50:27 teknopaul Exp $
35 */
36public class LargeSelectInput
37 extends InputField{
38
39 private int optionIdx = 0;
40
41 private LargeSelectInput.Option[] options;
42
43 public LargeSelectInput() {
44 }
45
46
47 public LargeSelectInput.Option[] getOptions() {
48 return options;
49 }
50
51 public void setOptions(LargeSelectInput.Option[] options) {
52 this.options = options;
53 }
54 public Option getNewOption(){
55 return new Option();
56 }
57
58 public class Option {
59
60 private int idx = ++optionIdx;
61 private String text;
62 public String value;
63 public void setText(String text) {
64 this.text = text;
65 }
66 public String getText() {
67 if( org.tp23.antinstaller.Installer.langPack != null ) {
68 return org.tp23.antinstaller.Installer.langPack.getString(getProperty() + "." + idx +".displayText");
69 }
70 return text;
71 }
72 }
73
74 public void setValue(String dir){
75 setInputResult(dir);
76 }
77 /**
78 * Called to validate the user input
79 */
80 public boolean validate(InstallerContext cxt) throws ValidationException{
81 if(getInputResult()==null)return false;
82 String value = getInputResult();
83 boolean ok = false;
84 for (int i = 0; i < options.length; i++) {
85 ok |= options[i].value.equals(value);
86 }
87 return ok;
88 }
89
90
91
92 /**
93 * Used by checkConfig to validate the configuration file.
94 * Not used at runtime.
95 * @return boolean
96 */
97 public boolean validateObject() {
98 if(getDisplayText()==null){
99 System.out.println("LargeSelect:displayText must be set");
100 return false;
101 }
102 if(getProperty()==null){
103 System.out.println("LargeSelect:property must be set");
104 return false;
105 }
106 if(getDefaultValue()==null){
107 System.out.println("LargeSelect:defaultValue must be set");
108 return false;
109 }
110 if(getOptions()==null){
111 System.out.println("LargeSelect:option must have at least two options");
112 return false;
113 }
114 if(getOptions().length<2){
115 System.out.println("LargeSelect:option must have at least two options");
116 return false;
117 }
118 for (int i = 0; i < getOptions().length; i++) {
119 Option o = getOptions()[i];
120 if(o.getText()==null){
121 System.out.println("LargeSelect:option:text must be set");
122 return false;
123 }
124 if(o.value==null){
125 System.out.println("LargeSelect:option:value must be set");
126 return false;
127 }
128 }
129 boolean defaultExists = false;
130 for (int i = 0; i < getOptions().length; i++) {
131 Option o = getOptions()[i];
132 if(o.value.equals(getDefaultValue())){
133 defaultExists=true;
134 }
135 }
136 if(!defaultExists){
137 System.out.println("LargeSelect:option:Default must be one of the options");
138 return false;
139 }
140 return true;
141 }
142}
Note: See TracBrowser for help on using the repository browser.