source: main/trunk/release-kits/shared/core/ant-installer/src/org/tp23/antinstaller/input/LargeSelectInput.java@ 30052

Last change on this file since 30052 was 30052, checked in by ak19, 9 years ago

Installer language selection now uses a dropdown in place of radio buttons to accomodate additional language translations submitted for the gsinstaller module. To get the dropdown <large-select> to work like the radio buttons <select>, Dr Bainbridge figured out that Oran had made some code changes to <select> in AntInstaller's LoadConfigFilter.java. Added the same change in for the <large-select> and then needed to port Oran's additional changes to SelectInput.java into LargeSelectInput.java (didn't put the changes in the superclass InputField.java since a lot of other AntInstaller classes inherit from that).

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