1
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
36public class LargeSelectInput
37 extends InputField{
38
39 private static ResourceBundle langPack = null;
41 private int optionIdx = 0;
42 static{
43 try {
44 langPack = ResourceBundle.getBundle("resources.LanguagePack");
45 } catch (MissingResourceException e) {
46 }
48 }
49
50 private LargeSelectInput.Option[] options;
51
52 public LargeSelectInput() {
53 }
54
55
56 public LargeSelectInput.Option[] getOptions() {
57 return options;
58 }
59
60 public void setOptions(LargeSelectInput.Option[] options) {
61 this.options = options;
62 }
63 public Option getNewOption(){
64 return new Option();
65 }
66
67 public class Option {
68
69 private int idx = ++optionIdx;
70 private String text;
71 public String value;
72 public void setText(String text) {
73 this.text = text;
74 }
75 public String getText() {
76 if(langPack != null){
77 return langPack.getString(getProperty() + "." + idx +".displayText");
78 }
79 return text;
80 }
81 }
82
83 public void setValue(String dir){
84 setInputResult(dir);
85 }
86
89 public boolean validate(InstallerContext cxt) throws ValidationException{
90 if(getInputResult()==null)return false;
91 String value = getInputResult();
92 boolean ok = false;
93 for (int i = 0; i < options.length; i++) {
94 ok |= options[i].value.equals(value);
95 }
96 return ok;
97 }
98
99
00
01
06 public boolean validateObject() {
07 if(getDisplayText()==null){
08 System.out.println("LargeSelect:displayText must be set");
09 return false;
10 }
11 if(getProperty()==null){
12 System.out.println("LargeSelect:property must be set");
13 return false;
14 }
15 if(getDefaultValue()==null){
16 System.out.println("LargeSelect:defaultValue must be set");
17 return false;
18 }
19 if(getOptions()==null){
20 System.out.println("LargeSelect:option must have at least two options");
21 return false;
22 }
23 if(getOptions().length<2){
24 System.out.println("LargeSelect:option must have at least two options");
25 return false;
26 }
27 for (int i = 0; i < getOptions().length; i++) {
28 Option o = getOptions()[i];
29 if(o.getText()==null){
30 System.out.println("LargeSelect:option:text must be set");
31 return false;
32 }
33 if(o.value==null){
34 System.out.println("LargeSelect:option:value must be set");
35 return false;
36 }
37 }
38 boolean defaultExists = false;
39 for (int i = 0; i < getOptions().length; i++) {
40 Option o = getOptions()[i];
41 if(o.value.equals(getDefaultValue())){
42 defaultExists=true;
43 }
44 }
45 if(!defaultExists){
46 System.out.println("LargeSelect:option:Default must be one of the options");
47 return false;
48 }
49 return true;
50 }
51}
52