source: release-kits/shared/ant-installer/src/org/tp23/antinstaller/page/Page.java@ 17622

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

extra options to directory chooser and page

File size: 7.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.page;
17
18import java.util.ArrayList;
19import java.util.Iterator;
20import java.util.List;
21import java.util.MissingResourceException;
22import java.util.ResourceBundle;
23import java.util.Set;
24import java.util.StringTokenizer;
25import java.util.TreeSet;
26
27import org.tp23.antinstaller.InstallException;
28import org.tp23.antinstaller.InstallerContext;
29import org.tp23.antinstaller.input.OutputField;
30import org.tp23.antinstaller.input.TargetInput;
31import org.tp23.antinstaller.runtime.IfPropertyHelper;
32/**
33 *
34 * <p>Represents a page in the installer. </p>
35 * <p>This object maintians an ordered list of targets that have been selected
36* so that when ant is run the targets are run in the correct order. If
37* Targets exist in multiple pages they are run in the order they appear in the config file. </p>
38 * <p>Copyright: Copyright (c) 2004</p>
39 * <p>Company: tp23</p>
40 * @author Paul Hinds
41 * @version $Id: Page.java,v 1.10 2007/01/19 00:24:36 teknopaul Exp $
42 */
43
44public abstract class Page {
45
46 //private static final int MAX_TARGETS = 10;
47 private String name;
48 private String displayText;
49 private String imageResource;
50 private OutputField[] outputField;
51 private boolean abort;
52
53 private boolean showNextButton = true;
54
55 /**
56 * target to be called as the installer is running
57 */
58 private String postDisplayTarget;
59 private Set targets = new TreeSet();
60
61 public Page() {
62 }
63
64 public String getName() {
65 return name;
66 }
67
68 public void setName(String name) {
69 this.name = name;
70 }
71
72 public String getDisplayText() {
73 if( org.tp23.antinstaller.Installer.langPack != null ) {
74 return org.tp23.antinstaller.Installer.langPack.getString("page." + getName() + ".displayText");
75 }
76 return displayText;
77 }
78
79 public void setDisplayText(String displayText) {
80 this.displayText = displayText;
81 }
82
83 public String getImageResource() {
84 return imageResource;
85 }
86
87 public void setImageResource(String imageResource) {
88 this.imageResource = imageResource;
89 }
90
91 public OutputField[] getOutputField() {
92 return outputField;
93 }
94
95 public void setOutputField(OutputField[] outputField) {
96 this.outputField = outputField;
97 }
98
99 public String getPostDisplayTarget() {
100 return postDisplayTarget;
101 }
102
103 public void setPostDisplayTarget(String runtimeTarget) {
104 this.postDisplayTarget = runtimeTarget;
105 }
106
107 public boolean isShowNextButton() {
108 return showNextButton;
109 }
110 public void setShowNextButton(boolean snb) {
111 this.showNextButton = snb;
112 }
113 public void setShowNextButton(String snb) {
114 this.showNextButton = OutputField.isTrue(snb);
115 }
116
117 /**
118 * These are the ant targets that will be run, this is decided after
119 * the Page has been displayed. For example if the user chooses not
120 * to enter a field that may signify that a target should not be run
121 * @return A sorted List a list of Ant targets as Strings;
122 * @throws InstallException
123 */
124 public List getTargets(InstallerContext ctx) {
125 List results = new ArrayList(targets.size());
126 try {
127 Iterator iter = targets.iterator();
128 IfPropertyHelper helper = new IfPropertyHelper(ctx);
129 while(iter.hasNext()){
130 IndexedTarget idxTarget = (IndexedTarget)iter.next();
131 if( IndexedTarget.PAGE.equals(idxTarget.getTargetType()) ){
132 if( helper.ifProperty(this) || helper.ifTarget(this, ctx.getInstaller().getPages() ) ){
133 results.add(idxTarget.target);
134 }
135 }
136 else{
137 results.add(idxTarget.target);
138 }
139 }
140 } catch (InstallException e) {
141 // should not happen at runtime if ifProperty has been validated
142 e.printStackTrace();
143 ctx.log(ctx.getInstaller().isVerbose(), e);
144 throw new RuntimeException();
145 }
146 return results;
147 }
148 /**
149 * get input targets that are selected and all page targets, independent of
150 * the ifProperty value
151 * @return
152 */
153 public List getAllTargets() {
154 List results = new ArrayList(targets.size());
155 Iterator iter = targets.iterator();
156 while(iter.hasNext()){
157 IndexedTarget idxTarget = (IndexedTarget)iter.next();
158 results.add(idxTarget.target);
159 }
160 return results;
161 }
162 /**
163 * Comma separated list of targets for this page, called when parsing the
164 * config file
165 * @param target String
166 */
167 public void setTarget(String targetList) {
168 StringTokenizer st = new StringTokenizer(targetList, ",");
169 while (st.hasMoreTokens()) {
170 targets.add(new IndexedTarget(TargetInput.getGlobalIdx(),
171 st.nextToken(),
172 IndexedTarget.PAGE));
173 }
174 }
175 /**
176 * Adds an INPUT target to the Page config
177 * @param idx
178 * @param target
179 */
180 public void addTarget(int idx, String target) {
181 this.targets.add(new IndexedTarget(idx, target, IndexedTarget.INPUT));
182 }
183 public void removeTarget(int idx) {
184 this.targets.remove(new IndexedTarget(idx, null));
185 }
186 /**
187 * returns true if the page has the current target set
188 * @param target String
189 * @return boolean
190 */
191 public boolean isTarget(String target) {
192 if(target == null){
193 return false;
194 }
195 Iterator iter = targets.iterator();
196 while(iter.hasNext()) {
197 IndexedTarget idxTarget = (IndexedTarget)iter.next();
198 if(idxTarget.target.equals(target)){
199 return true;
200 }
201 }
202 return false;
203 }
204
205 /**
206 * @return a List of IndexedTarget objects
207 */
208 public List getPageTargets(){
209 List toReturn = new ArrayList(targets.size());
210 Iterator iter = targets.iterator();
211 while(iter.hasNext()) {
212 IndexedTarget idxTarget = (IndexedTarget)iter.next();
213 if( IndexedTarget.PAGE.equals(idxTarget.targetType) ){
214 toReturn.add(idxTarget);
215 }
216 }
217 return toReturn;
218 }
219
220 /**
221 * @return a List of IndexedTarget objects
222 */
223 public List getElementTargets(){
224 List toReturn = new ArrayList(targets.size());
225 Iterator iter = targets.iterator();
226 while(iter.hasNext()) {
227 IndexedTarget idxTarget = (IndexedTarget)iter.next();
228 if( IndexedTarget.INPUT.equals(idxTarget.targetType) ){
229 toReturn.add(idxTarget);
230 }
231 }
232 return toReturn;
233 }
234 /**
235 * This is called after the page is displayed, a page can return false to indicate
236 * that the installation should abort. Should be false if the cancel button is pressed.
237 * System.exit is not called to allow the installer to clean up temporary files.
238 * @return boolean
239 */
240 public boolean isAbort() {
241 return abort;
242 }
243
244 public void setAbort(boolean abort) {
245 this.abort = abort;
246 }
247 public static class IndexedTarget implements Comparable{
248
249 private static final String PAGE = "page";
250 private static final String INPUT = "input";
251
252 int idx;
253 String target;
254 String targetType = INPUT;
255
256 IndexedTarget(int idx, String target){
257 this.idx = idx;
258 this.target = target;
259 }
260 IndexedTarget(int idx, String target, String targetType){
261 this.idx = idx;
262 this.target = target;
263 this.targetType = targetType;
264 }
265
266 public boolean equals(Object target){
267 IndexedTarget test = (IndexedTarget)target;
268 return test.idx == idx;
269 }
270 // FindBugs - part of equals() contract
271 public int hashCode(){
272 return this.idx;
273 }
274 public int compareTo(Object o) {
275 IndexedTarget test = (IndexedTarget)o;
276 return idx - test.idx;
277 }
278 public String getTarget() {
279 return target;
280 }
281 public String getTargetType() {
282 return targetType;
283 }
284
285 }
286}
Note: See TracBrowser for help on using the repository browser.