KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > panels > UserInputPanel


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/ http://developer.berlios.de/projects/izpack/
5  *
6  * Copyright 2002 Elmar Grom
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
9  * in compliance with the License. You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software distributed under the License
14  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
15  * or implied. See the License for the specific language governing permissions and limitations under
16  * the License.
17  */

18
19 package com.izforge.izpack.panels;
20
21 import java.awt.Color JavaDoc;
22 import java.awt.Font JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.io.File JavaDoc;
26 import java.io.InputStream JavaDoc;
27 import java.text.MessageFormat JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.HashSet JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.Map JavaDoc;
32 import java.util.StringTokenizer JavaDoc;
33 import java.util.Vector JavaDoc;
34
35 import javax.swing.BorderFactory JavaDoc;
36 import javax.swing.ButtonGroup JavaDoc;
37 import javax.swing.JButton JavaDoc;
38 import javax.swing.JCheckBox JavaDoc;
39 import javax.swing.JComboBox JavaDoc;
40 import javax.swing.JComponent JavaDoc;
41 import javax.swing.JFileChooser JavaDoc;
42 import javax.swing.JLabel JavaDoc;
43 import javax.swing.JOptionPane JavaDoc;
44 import javax.swing.JPanel JavaDoc;
45 import javax.swing.JPasswordField JavaDoc;
46 import javax.swing.JRadioButton JavaDoc;
47 import javax.swing.JTextField JavaDoc;
48
49 import net.n3.nanoxml.NonValidator;
50 import net.n3.nanoxml.StdXMLBuilder;
51 import net.n3.nanoxml.StdXMLParser;
52 import net.n3.nanoxml.StdXMLReader;
53 import net.n3.nanoxml.XMLElement;
54
55 import com.izforge.izpack.LocaleDatabase;
56 import com.izforge.izpack.Pack;
57 import com.izforge.izpack.gui.ButtonFactory;
58 import com.izforge.izpack.gui.TwoColumnConstraints;
59 import com.izforge.izpack.gui.TwoColumnLayout;
60 import com.izforge.izpack.installer.InstallData;
61 import com.izforge.izpack.installer.InstallerFrame;
62 import com.izforge.izpack.installer.IzPanel;
63 import com.izforge.izpack.installer.ResourceManager;
64 import com.izforge.izpack.rules.RulesEngine;
65 import com.izforge.izpack.util.MultiLineLabel;
66 import com.izforge.izpack.util.OsConstraint;
67 import com.izforge.izpack.util.OsVersion;
68 import com.izforge.izpack.util.VariableSubstitutor;
69
70 /*---------------------------------------------------------------------------*/
71 /**
72  * This panel is designed to collect user input during the installation process. The panel is
73  * initially blank and is populated with input elements based on the XML specification in a resource
74  * file.
75  *
76  *
77  * @version 0.0.1 / 10/19/02
78  * @author getDirectoryCreated
79  */

80 /*---------------------------------------------------------------------------*/
81 /*
82  * $ @design
83  *
84  * Each field is specified in its own node, containing attributes and data. When this class is
85  * instantiated, the specification is read and analyzed. Each field node is processed based on its
86  * type. An specialized member function is called for each field type that creates the necessary UI
87  * elements. All UI elements are stored in the uiElements vector. Elements are packaged in an object
88  * array that must follow this pattern:
89  *
90  * index 0 - a String object, that specifies the field type. This is identical to the string used to
91  * identify the field type in the XML file. index 1 - a String object that contains the variable
92  * name for substitution. index 2 - the constraints object that should be used for positioning the
93  * UI element index 3 - the UI element itself index 4 - a Vector containg a list of pack for which
94  * the item should be created. This is used by buildUI() to decide if the item should be added to
95  * the UI.
96  *
97  * In some cases additional entries are used. The use depends on the specific needs of the type of
98  * input field.
99  *
100  * When the panel is activated, the method buildUI() walks the list of UI elements adds them to the
101  * panel together with the matching constraint.
102  *
103  * When an attempt is made to move on to another panel, the method readInput() walks the list of UI
104  * elements again and calls specialized methods that know how to read the user input from each of
105  * the UI elemnts and set the associated varaible.
106  *
107  * The actual variable substitution is not performed by this panel but by the variable substitutor.
108  *
109  * To Do: ------ * make sure all header documentation is complete and correct
110  * --------------------------------------------------------------------------
111  */

112 public class UserInputPanel extends IzPanel
113 {
114
115     // ------------------------------------------------------------------------
116
// Constant Definitions
117
// ------------------------------------------------------------------------
118

119     // The constants beginning with 'POS_' define locations in the object arrays
120
// that used to hold all information for the individual fields. Some data is
121
// not required for all field types. If this happens withing the array, that
122
// location must be padded with 'null'. At the end of the array it can be
123
// omitted. The data stored in this way is in most cases only known by
124
// convention between the add and the associated read method. the following
125
// positions are also used by other service methods in this class and must
126
// not be used for other purposes:
127
// - POS_DISPLAYED
128
// - POS_TYPE
129
// - POS_CONSTRAINTS
130
// - POS_PACKS
131

132     /**
133      *
134      */

135     private static final long serialVersionUID = 3257850965439886129L;
136
137     private static final int POS_DISPLAYED = 0;
138
139     private static final int POS_TYPE = 1;
140
141     private static final int POS_VARIABLE = 2;
142
143     private static final int POS_CONSTRAINTS = 3;
144
145     private static final int POS_FIELD = 4;
146
147     private static final int POS_PACKS = 5;
148
149     private static final int POS_OS = 6;
150
151     private static final int POS_TRUE = 7;
152
153     private static final int POS_FALSE = 8;
154
155     private static final int POS_MESSAGE = 9;
156
157     private static final int POS_GROUP = 10;
158
159     /** The name of the XML file that specifies the panel layout */
160     private static final String JavaDoc SPEC_FILE_NAME = "userInputSpec.xml";
161
162     private static final String JavaDoc LANG_FILE_NAME = "userInputLang.xml";
163
164     /** how the spec node for a specific panel is identified */
165     private static final String JavaDoc NODE_ID = "panel";
166
167     private static final String JavaDoc FIELD_NODE_ID = "field";
168
169     private static final String JavaDoc INSTANCE_IDENTIFIER = "order";
170
171     private static final String JavaDoc TYPE = "type";
172
173     private static final String JavaDoc DESCRIPTION = "description";
174
175     private static final String JavaDoc VARIABLE = "variable";
176
177     private static final String JavaDoc TEXT = "txt";
178
179     private static final String JavaDoc KEY = "id";
180
181     private static final String JavaDoc SPEC = "spec";
182
183     private static final String JavaDoc SET = "set";
184
185     private static final String JavaDoc TRUE = "true";
186
187     private static final String JavaDoc FALSE = "false";
188
189     private static final String JavaDoc ALIGNMENT = "align";
190
191     private static final String JavaDoc LEFT = "left";
192
193     private static final String JavaDoc CENTER = "center";
194
195     private static final String JavaDoc RIGHT = "right";
196
197     private static final String JavaDoc TOP = "top";
198
199     private static final String JavaDoc ITALICS = "italic";
200
201     private static final String JavaDoc BOLD = "bold";
202
203     private static final String JavaDoc SIZE = "size";
204
205     private static final String JavaDoc VALIDATOR = "validator";
206
207     private static final String JavaDoc PROCESSOR = "processor";
208
209     private static final String JavaDoc CLASS = "class";
210
211     private static final String JavaDoc FIELD_LABEL = "label";
212
213     private static final String JavaDoc TITLE_FIELD = "title";
214
215     private static final String JavaDoc TEXT_FIELD = "text";
216
217     private static final String JavaDoc TEXT_SIZE = "size";
218
219     private static final String JavaDoc STATIC_TEXT = "staticText";
220
221     private static final String JavaDoc COMBO_FIELD = "combo";
222
223     private static final String JavaDoc COMBO_CHOICE = "choice";
224
225     private static final String JavaDoc COMBO_VALUE = "value";
226
227     private static final String JavaDoc RADIO_FIELD = "radio";
228
229     private static final String JavaDoc RADIO_CHOICE = "choice";
230
231     private static final String JavaDoc RADIO_VALUE = "value";
232
233     private static final String JavaDoc SPACE_FIELD = "space";
234
235     private static final String JavaDoc DIVIDER_FIELD = "divider";
236
237     private static final String JavaDoc CHECK_FIELD = "check";
238
239     private static final String JavaDoc RULE_FIELD = "rule";
240
241     private static final String JavaDoc RULE_LAYOUT = "layout";
242
243     private static final String JavaDoc RULE_SEPARATOR = "separator";
244
245     private static final String JavaDoc RULE_RESULT_FORMAT = "resultFormat";
246
247     private static final String JavaDoc RULE_PLAIN_STRING = "plainString";
248
249     private static final String JavaDoc RULE_DISPLAY_FORMAT = "displayFormat";
250
251     private static final String JavaDoc RULE_SPECIAL_SEPARATOR = "specialSeparator";
252
253     private static final String JavaDoc RULE_ENCRYPTED = "processed";
254
255     private static final String JavaDoc RULE_PARAM_NAME = "name";
256
257     private static final String JavaDoc RULE_PARAM_VALUE = "value";
258
259     private static final String JavaDoc RULE_PARAM = "param";
260
261     private static final String JavaDoc PWD_FIELD = "password";
262
263     private static final String JavaDoc PWD_INPUT = "pwd";
264
265     private static final String JavaDoc PWD_SIZE = "size";
266
267     private static final String JavaDoc SEARCH_FIELD = "search";
268
269     // internal value for the button used to trigger autodetection
270
private static final String JavaDoc SEARCH_BUTTON_FIELD = "autodetect";
271
272     private static final String JavaDoc SEARCH_CHOICE = "choice";
273
274     private static final String JavaDoc SEARCH_FILENAME = "filename";
275
276     private static final String JavaDoc SEARCH_RESULT = "result";
277
278     private static final String JavaDoc SEARCH_VALUE = "value";
279
280     private static final String JavaDoc SEARCH_TYPE = "type";
281
282     private static final String JavaDoc SEARCH_FILE = "file";
283
284     private static final String JavaDoc SEARCH_DIRECTORY = "directory";
285
286     private static final String JavaDoc SEARCH_PARENTDIR = "parentdir";
287
288     private static final String JavaDoc SEARCH_CHECKFILENAME = "checkfilename";
289
290     private static final String JavaDoc SELECTEDPACKS = "createForPack"; // renamed
291

292     private static final String JavaDoc UNSELECTEDPACKS = "createForUnselectedPack"; // new
293

294     protected static final String JavaDoc ATTRIBUTE_CONDITIONID_NAME = "conditionid";
295     
296     protected static final String JavaDoc VARIABLE_NODE = "variable";
297
298     protected static final String JavaDoc ATTRIBUTE_VARIABLE_NAME = "name";
299
300     protected static final String JavaDoc ATTRIBUTE_VARIABLE_VALUE = "value";
301
302     // node
303

304     private static final String JavaDoc NAME = "name";
305
306     private static final String JavaDoc OS = "os";
307
308     private static final String JavaDoc FAMILY = "family";
309
310     // ------------------------------------------------------------------------
311
// Variable Declarations
312
// ------------------------------------------------------------------------
313
private static int instanceCount = 0;
314
315     protected int instanceNumber = 0;
316
317     /**
318      * If there is a possibility that some UI elements will not get added we can not allow to go
319      * back to the PacksPanel, because the process of building the UI is not reversable. This
320      * variable keeps track if any packs have been defined and will be used to make a decision for
321      * locking the 'previous' button.
322      */

323     private boolean packsDefined = false;
324
325     private InstallerFrame parentFrame;
326
327     /** The parsed result from reading the XML specification from the file */
328     private XMLElement spec;
329
330     private boolean haveSpec = false;
331
332     /** Holds the references to all of the UI elements */
333     private Vector JavaDoc uiElements = new Vector JavaDoc();
334
335     /** Holds the references to all radio button groups */
336     private Vector JavaDoc buttonGroups = new Vector JavaDoc();
337
338     /** Holds the references to all password field groups */
339     private Vector JavaDoc passwordGroups = new Vector JavaDoc();
340
341     /**
342      * used for temporary storage of references to password groups that have already been read in a
343      * given read cycle.
344      */

345     private Vector JavaDoc passwordGroupsRead = new Vector JavaDoc();
346
347     /** Used to track search fields. Contains SearchField references. */
348     private Vector JavaDoc searchFields = new Vector JavaDoc();
349
350     /** Holds all user inputs for use in automated installation */
351     private Vector JavaDoc entries = new Vector JavaDoc();
352
353     private LocaleDatabase langpack = null;
354
355     /*--------------------------------------------------------------------------*/
356     // This method can be used to search for layout problems. If this class is
357
// compiled with this method uncommented, the layout guides will be shown
358
// on the panel, making it possible to see if all components are placed
359
// correctly.
360
/*--------------------------------------------------------------------------*/
361     // public void paint (Graphics graphics)
362
// {
363
// super.paint (graphics);
364
// layout.showRules ((Graphics2D)graphics, Color.red);
365
// }
366
/*--------------------------------------------------------------------------*/
367     /**
368      * Constructs a <code>UserInputPanel</code>.
369      *
370      * @param parent reference to the application frame
371      * @param installData shared information about the installation
372      */

373     /*--------------------------------------------------------------------------*/
374     public UserInputPanel(InstallerFrame parent, InstallData installData)
375     {
376         super(parent, installData);
377         instanceNumber = instanceCount++;
378         this.parentFrame = parent;
379     }
380
381     protected void init()
382     {
383         super.removeAll();
384         uiElements.clear();
385
386         // ----------------------------------------------------
387
// ----------------------------------------------------
388
TwoColumnLayout layout = new TwoColumnLayout(10, 5, 30, 25, TwoColumnLayout.LEFT);
389         setLayout(layout);
390
391         // ----------------------------------------------------
392
// get a locale database
393
// ----------------------------------------------------
394
try
395         {
396             // this.langpack = parent.langpack;
397

398             String JavaDoc resource = LANG_FILE_NAME + "_" + idata.localeISO3;
399             this.langpack = new LocaleDatabase(ResourceManager.getInstance().getInputStream(
400                     resource));
401         }
402         catch (Throwable JavaDoc exception)
403         {}
404
405         // ----------------------------------------------------
406
// read the specifications
407
// ----------------------------------------------------
408
try
409         {
410             readSpec();
411         }
412         catch (Throwable JavaDoc exception)
413         {
414             // log the problem
415
exception.printStackTrace();
416         }
417
418         if (!haveSpec)
419         {
420             // return if we could not read the spec. further
421
// processing will only lead to problems. In this
422
// case we must skip the panel when it gets activated.
423
return;
424         }
425
426         // refresh variables specified in spec
427
updateVariables();
428         
429         // ----------------------------------------------------
430
// process all field nodes. Each field node is analyzed
431
// for its type, then an appropriate memeber function
432
// is called that will create the correct UI elements.
433
// ----------------------------------------------------
434
Vector JavaDoc fields = spec.getChildrenNamed(FIELD_NODE_ID);
435
436         for (int i = 0; i < fields.size(); i++)
437         {
438             XMLElement field = (XMLElement) fields.elementAt(i);
439             String JavaDoc attribute = field.getAttribute(TYPE);
440             String JavaDoc conditionid = field.getAttribute(ATTRIBUTE_CONDITIONID_NAME);
441             if (conditionid != null)
442             {
443                 // check if condition is fulfilled
444
if (!this.parent.getRules().isConditionTrue(conditionid, idata.getVariables()))
445                 {
446                     continue;
447                 }
448             }
449             if (attribute != null)
450             {
451                 if (attribute.equals(RULE_FIELD))
452                 {
453                     addRuleField(field);
454                 }
455                 else if (attribute.equals(TEXT_FIELD))
456                 {
457                     addTextField(field);
458                 }
459                 else if (attribute.equals(COMBO_FIELD))
460                 {
461                     addComboBox(field);
462                 }
463                 else if (attribute.equals(RADIO_FIELD))
464                 {
465                     addRadioButton(field);
466                 }
467                 else if (attribute.equals(PWD_FIELD))
468                 {
469                     addPasswordField(field);
470                 }
471                 else if (attribute.equals(SPACE_FIELD))
472                 {
473                     addSpace(field);
474                 }
475                 else if (attribute.equals(DIVIDER_FIELD))
476                 {
477                     addDivider(field);
478                 }
479                 else if (attribute.equals(CHECK_FIELD))
480                 {
481                     addCheckBox(field);
482                 }
483                 else if (attribute.equals(STATIC_TEXT))
484                 {
485                     addText(field);
486                 }
487                 else if (attribute.equals(TITLE_FIELD))
488                 {
489                     addTitle(field);
490                 }
491                 else if (attribute.equals(SEARCH_FIELD))
492                 {
493                     addSearch(field);
494                 }
495             }
496         }
497     }
498
499     protected void updateUIElements()
500     {
501         boolean updated = false;
502         VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
503
504         for (int i = 0; i < uiElements.size(); i++)
505         {
506             Object JavaDoc[] element = (Object JavaDoc[]) uiElements.get(i);
507             if (element[POS_VARIABLE] == null)
508             {
509                 continue;
510             }
511             String JavaDoc value = idata.getVariable((String JavaDoc) element[POS_VARIABLE]);
512             
513             if (RADIO_FIELD.equals(element[POS_TYPE]))
514             {
515                 // we have a radio field, which should be updated
516
JRadioButton JavaDoc choice = (JRadioButton JavaDoc) element[POS_FIELD];
517                 if (value == null)
518                 {
519                     continue;
520                 }
521                 if (value.equals(element[POS_TRUE]))
522                 {
523                     choice.setSelected(true);
524                 }
525                 else
526                 {
527                     choice.setSelected(false);
528                 }
529                 element[POS_FIELD] = choice;
530             }
531             else if (TEXT_FIELD.equals(element[POS_TYPE]))
532             {
533                 // update TextField
534
JTextField JavaDoc textf = (JTextField JavaDoc) element[POS_FIELD];
535
536                 // System.out.println("Textfield: " + value);
537
if (value == null)
538                 {
539                     value = textf.getText();
540                 }
541                 textf.setText(vs.substitute(value, null));
542                 element[POS_FIELD] = textf;
543             }
544             else if (CHECK_FIELD.equals(element[POS_TYPE]))
545             {
546                 // TODO: HAS TO BE IMPLEMENTED
547
}
548             else if (SEARCH_FIELD.equals(element[POS_TYPE]))
549             {
550                 // TODO: HAS TO BE IMPLEMENTED
551
}
552             else if (RULE_FIELD.equals(element[POS_TYPE]))
553             {
554
555                 RuleInputField rulef = (RuleInputField) element[POS_FIELD];
556                 // System.out.println("RuleInputField: " + value);
557
if (value == null)
558                 {
559                     value = rulef.getText();
560                 }
561             }
562             // overwrite entry;
563
uiElements.set(i, element);
564             updated = true;
565         }
566         if (updated)
567         {
568             // super.removeAll();
569
super.invalidate();
570             // buildUI();
571
}
572     }
573
574     /*--------------------------------------------------------------------------*/
575     /**
576      * Indicates wether the panel has been validated or not. The installer won't let the user go
577      * further through the installation process until the panel is validated. Default behavior is to
578      * return true.
579      *
580      * @return A boolean stating wether the panel has been validated or not.
581      */

582     /*--------------------------------------------------------------------------*/
583     public boolean isValidated()
584     {
585         return (readInput());
586     }
587
588     /*--------------------------------------------------------------------------*/
589     /**
590      * This method is called when the panel becomes active.
591      */

592     /*--------------------------------------------------------------------------*/
593     public void panelActivate()
594     {
595         this.init();
596                 
597         if (spec == null)
598         {
599             // TODO: translate
600
emitError("User input specification could not be found.",
601                     "The specification for the user input panel could not be found. Please contact the packager.");
602             parentFrame.skipPanel();
603         }
604         // update UI with current values of associated variables
605
updateUIElements();
606         Vector JavaDoc forPacks = spec.getChildrenNamed(SELECTEDPACKS);
607         Vector JavaDoc forUnselectedPacks = spec.getChildrenNamed(UNSELECTEDPACKS);
608         Vector JavaDoc forOs = spec.getChildrenNamed(OS);
609
610         if (!itemRequiredFor(forPacks) || !itemRequiredForUnselected(forUnselectedPacks)
611                 || !itemRequiredForOs(forOs))
612         {
613             parentFrame.skipPanel();
614             return;
615         }
616         if (!haveSpec)
617         {
618             parentFrame.skipPanel();
619             return;
620         }
621         // if (uiBuilt)
622
// {
623
// return;
624
// }
625

626         buildUI();
627         //need a validation, else ui is scrambled
628
validate();
629         if (packsDefined)
630         {
631             parentFrame.lockPrevButton();
632         }
633     }
634
635     /*--------------------------------------------------------------------------*/
636     /**
637      * Asks the panel to set its own XML data that can be brought back for an automated installation
638      * process. Use it as a blackbox if your panel needs to do something even in automated mode.
639      *
640      * @param panelRoot The XML root element of the panels blackbox tree.
641      */

642     /*--------------------------------------------------------------------------*/
643     public void makeXMLData(XMLElement panelRoot)
644     {
645         Map JavaDoc entryMap = new HashMap JavaDoc();
646
647         for (int i = 0; i < entries.size(); i++)
648         {
649             TextValuePair pair = (TextValuePair) entries.elementAt(i);
650             entryMap.put(pair.toString(), pair.getValue());
651         }
652
653         new UserInputPanelAutomationHelper(entryMap).makeXMLData(idata, panelRoot);
654     }
655
656     /*--------------------------------------------------------------------------*/
657     /**
658      * Builds the UI and makes it ready for display
659      */

660     /*--------------------------------------------------------------------------*/
661     private void buildUI()
662     {
663         Object JavaDoc[] uiElement;
664
665         for (int i = 0; i < uiElements.size(); i++)
666         {
667             uiElement = (Object JavaDoc[]) uiElements.elementAt(i);
668
669             if (itemRequiredFor((Vector JavaDoc) uiElement[POS_PACKS])
670                     && itemRequiredForOs((Vector JavaDoc) uiElement[POS_OS]))
671             {
672                 try
673                 {
674                     if (uiElement[POS_DISPLAYED] == null
675                             || "false".equals(uiElement[POS_DISPLAYED].toString()))
676                     {
677                         add((JComponent JavaDoc) uiElement[POS_FIELD], uiElement[POS_CONSTRAINTS]);
678                     }
679
680                     uiElement[POS_DISPLAYED] = Boolean.valueOf(true);
681                     uiElements.remove(i);
682                     uiElements.add(i, uiElement);
683                 }
684                 catch (Throwable JavaDoc exception)
685                 {
686                     System.out.println("Internal format error in field: "
687                             + uiElement[POS_TYPE].toString()); // !!! logging
688
}
689             }
690             else
691             {
692                 try
693                 {
694                     if (uiElement[POS_DISPLAYED] != null
695                             && "true".equals(uiElement[POS_DISPLAYED].toString()))
696                     {
697                         remove((JComponent JavaDoc) uiElement[POS_FIELD]);
698                     }
699                 }
700                 catch (Throwable JavaDoc exception)
701                 {
702                     System.out.println("Internal format error in field: "
703                             + uiElement[POS_TYPE].toString()); // !!! logging
704
}
705                 uiElement[POS_DISPLAYED] = Boolean.valueOf(false);
706                 uiElements.remove(i);
707                 uiElements.add(i, uiElement);
708             }
709         }
710     }
711
712     /*--------------------------------------------------------------------------*/
713     /**
714      * Reads the input data from all UI elements and sets the associated variables.
715      *
716      * @return <code>true</code> if the operation is successdul, otherwise <code>false</code>.
717      */

718     /*--------------------------------------------------------------------------*/
719     private boolean readInput()
720     {
721         boolean success;
722         String JavaDoc fieldType = null;
723         Object JavaDoc[] field = null;
724
725         passwordGroupsRead.clear();
726         // ----------------------------------------------------
727
// cycle through all but the password fields and read
728
// their contents
729
// ----------------------------------------------------
730
for (int i = 0; i < uiElements.size(); i++)
731         {
732             field = (Object JavaDoc[]) uiElements.elementAt(i);
733
734             if ((field != null) && (((Boolean JavaDoc) field[POS_DISPLAYED]).booleanValue()))
735             {
736                 fieldType = (String JavaDoc) (field[POS_TYPE]);
737
738                 // ------------------------------------------------
739
if (fieldType.equals(RULE_FIELD))
740                 {
741                     success = readRuleField(field);
742                     if (!success) { return (false); }
743                 }
744
745                 // ------------------------------------------------
746
if (fieldType.equals(PWD_FIELD))
747                 {
748                     success = readPasswordField(field);
749                     if (!success) { return (false); }
750                 }
751
752                 // ------------------------------------------------
753
else if (fieldType.equals(TEXT_FIELD))
754                 {
755                     success = readTextField(field);
756                     if (!success) { return (false); }
757                 }
758
759                 // ------------------------------------------------
760
else if (fieldType.equals(COMBO_FIELD))
761                 {
762                     success = readComboBox(field);
763                     if (!success) { return (false); }
764                 }
765
766                 // ------------------------------------------------
767
else if (fieldType.equals(RADIO_FIELD))
768                 {
769                     success = readRadioButton(field);
770                     if (!success) { return (false); }
771                 }
772
773                 // ------------------------------------------------
774
else if (fieldType.equals(CHECK_FIELD))
775                 {
776                     success = readCheckBox(field);
777                     if (!success) { return (false); }
778                 }
779                 else if (fieldType.equals(SEARCH_FIELD))
780                 {
781                     success = readSearch(field);
782                     if (!success) { return (false); }
783                 }
784             }
785         }
786
787         return (true);
788     }
789
790     /*--------------------------------------------------------------------------*/
791     /**
792      * Reads the XML specification for the panel layout. The result is stored in spec.
793      *
794      * @exception Exception for any problems in reading the specification
795      */

796     /*--------------------------------------------------------------------------*/
797     private void readSpec() throws Exception JavaDoc
798     {
799         InputStream JavaDoc input = null;
800         XMLElement data;
801         Vector JavaDoc specElements;
802         String JavaDoc attribute;
803         String JavaDoc instance = Integer.toString(instanceNumber);
804
805         try
806         {
807             input = parentFrame.getResource(SPEC_FILE_NAME);
808         }
809         catch (Exception JavaDoc exception)
810         {
811             haveSpec = false;
812             return;
813         }
814         if (input == null)
815         {
816             haveSpec = false;
817             return;
818         }
819
820         // initialize the parser
821
StdXMLParser parser = new StdXMLParser();
822         parser.setBuilder(new StdXMLBuilder());
823         parser.setValidator(new NonValidator());
824         parser.setReader(new StdXMLReader(input));
825
826         // get the data
827
data = (XMLElement) parser.parse();
828
829         // extract the spec to this specific panel instance
830
if (data.hasChildren())
831         {
832             specElements = data.getChildrenNamed(NODE_ID);
833             for (int i = 0; i < specElements.size(); i++)
834             {
835                 data = (XMLElement) specElements.elementAt(i);
836                 attribute = data.getAttribute(INSTANCE_IDENTIFIER);
837
838                 if (instance.equals(attribute))
839                 {
840                     // use the current element as spec
841
spec = data;
842                     // close the stream
843
input.close();
844                     haveSpec = true;
845                     return;
846                 }
847             }
848
849             haveSpec = false;
850             return;
851         }
852
853         haveSpec = false;
854     }
855
856     /*--------------------------------------------------------------------------*/
857     /**
858      * Adds the title to the panel. There can only be one title, if mutiple titles are defined, they
859      * keep overwriting what has already be defined, so that the last definition is the one that
860      * prevails.
861      *
862      * @param spec a <code>XMLElement</code> containing the specification for the title.
863      */

864     /*--------------------------------------------------------------------------*/
865     private void addTitle(XMLElement spec)
866     {
867         String JavaDoc title = getText(spec);
868         boolean italic = getBoolean(spec, ITALICS, false);
869         boolean bold = getBoolean(spec, BOLD, false);
870         float multiplier = getFloat(spec, SIZE, 2.0f);
871         int justify = getAlignment(spec);
872
873         if (title != null)
874         {
875             JLabel JavaDoc label = new JLabel JavaDoc(title);
876             Font JavaDoc font = label.getFont();
877             float size = font.getSize();
878             int style = 0;
879
880             if (bold)
881             {
882                 style += Font.BOLD;
883             }
884             if (italic)
885             {
886                 style += Font.ITALIC;
887             }
888
889             font = font.deriveFont(style, (size * multiplier));
890             label.setFont(font);
891             label.setAlignmentX(0);
892
893             TwoColumnConstraints constraints = new TwoColumnConstraints();
894             constraints.align = justify;
895             constraints.position = TwoColumnConstraints.NORTH;
896
897             add(label, constraints);
898         }
899     }
900
901     /*--------------------------------------------------------------------------*/
902     /**
903      * Adds a rule field to the list of UI elements.
904      *
905      * @param spec a <code>XMLElement</code> containing the specification for the rule field.
906      */

907     /*--------------------------------------------------------------------------*/
908     private void addRuleField(XMLElement spec)
909     {
910         Vector JavaDoc forPacks = spec.getChildrenNamed(SELECTEDPACKS);
911         Vector JavaDoc forOs = spec.getChildrenNamed(OS);
912         XMLElement element = spec.getFirstChildNamed(SPEC);
913         String JavaDoc variable = spec.getAttribute(VARIABLE);
914         RuleInputField field = null;
915         JLabel JavaDoc label;
916         String JavaDoc layout;
917         String JavaDoc set;
918         String JavaDoc separator;
919         String JavaDoc format;
920         String JavaDoc validator = null;
921         String JavaDoc message = null;
922         boolean hasParams = false;
923         String JavaDoc paramName = null;
924         String JavaDoc paramValue = null;
925         HashMap JavaDoc validateParamMap = null;
926         Vector JavaDoc validateParams = null;
927         String JavaDoc processor = null;
928         int resultFormat = RuleInputField.DISPLAY_FORMAT;
929
930         // ----------------------------------------------------
931
// extract the specification details
932
// ----------------------------------------------------
933
if (element != null)
934         {
935             label = new JLabel JavaDoc(getText(element));
936             layout = element.getAttribute(RULE_LAYOUT);
937             set = element.getAttribute(SET);
938
939             // retrieve value of variable if not specified
940
// (does not work here because of special format for set attribute)
941
// if (set == null)
942
// {
943
// set = idata.getVariable (variable);
944
// }
945

946             separator = element.getAttribute(RULE_SEPARATOR);
947             format = element.getAttribute(RULE_RESULT_FORMAT);
948
949             if (format != null)
950             {
951                 if (format.equals(RULE_PLAIN_STRING))
952                 {
953                     resultFormat = RuleInputField.PLAIN_STRING;
954                 }
955                 else if (format.equals(RULE_DISPLAY_FORMAT))
956                 {
957                     resultFormat = RuleInputField.DISPLAY_FORMAT;
958                 }
959                 else if (format.equals(RULE_SPECIAL_SEPARATOR))
960                 {
961                     resultFormat = RuleInputField.SPECIAL_SEPARATOR;
962                 }
963                 else if (format.equals(RULE_ENCRYPTED))
964                 {
965                     resultFormat = RuleInputField.ENCRYPTED;
966                 }
967             }
968         }
969         // ----------------------------------------------------
970
// if there is no specification element, return without
971
// doing anything.
972
// ----------------------------------------------------
973
else
974         {
975             return;
976         }
977
978         // ----------------------------------------------------
979
// get the description and add it to the list of UI
980
// elements if it exists.
981
// ----------------------------------------------------
982
element = spec.getFirstChildNamed(DESCRIPTION);
983         addDescription(element, forPacks, forOs);
984
985         // ----------------------------------------------------
986
// get the validator and processor if they are defined
987
// ----------------------------------------------------
988
element = spec.getFirstChildNamed(VALIDATOR);
989         if (element != null)
990         {
991             validator = element.getAttribute(CLASS);
992             message = getText(element);
993             // ----------------------------------------------------------
994
// check and see if we have any parameters for this validator.
995
// If so, then add them to validateParamMap.
996
// ----------------------------------------------------------
997
validateParams = element.getChildrenNamed(RULE_PARAM);
998             if (validateParams != null && validateParams.size() > 0)
999             {
1000                hasParams = true;
1001
1002                if (validateParamMap == null) validateParamMap = new HashMap JavaDoc();
1003
1004                for (Iterator JavaDoc it = validateParams.iterator(); it.hasNext();)
1005                {
1006                    element = (XMLElement) it.next();
1007                    paramName = element.getAttribute(RULE_PARAM_NAME);
1008                    paramValue = element.getAttribute(RULE_PARAM_VALUE);
1009                    validateParamMap.put(paramName, paramValue);
1010                }
1011
1012            }
1013
1014        }
1015
1016        element = spec.getFirstChildNamed(PROCESSOR);
1017        if (element != null)
1018        {
1019            processor = element.getAttribute(CLASS);
1020        }
1021
1022        // ----------------------------------------------------
1023
// create an instance of RuleInputField based on the
1024
// extracted specifications, then add it to the list
1025
// of UI elements.
1026
// ----------------------------------------------------
1027
if (hasParams)
1028        {
1029            field = new RuleInputField(layout, set, separator, validator, validateParamMap,
1030                    processor, resultFormat, getToolkit(), idata);
1031        }
1032        else
1033        {
1034            field = new RuleInputField(layout, set, separator, validator, processor, resultFormat,
1035                    getToolkit(), idata);
1036
1037        }
1038        TwoColumnConstraints constraints = new TwoColumnConstraints();
1039        constraints.position = TwoColumnConstraints.WEST;
1040
1041        uiElements
1042                .add(new Object JavaDoc[] { null, FIELD_LABEL, null, constraints, label, forPacks, forOs});
1043
1044        TwoColumnConstraints constraints2 = new TwoColumnConstraints();
1045        constraints2.position = TwoColumnConstraints.EAST;
1046
1047        uiElements.add(new Object JavaDoc[] { null, RULE_FIELD, variable, constraints2, field, forPacks,
1048                forOs, null, null, message});
1049    }
1050
1051    /*--------------------------------------------------------------------------*/
1052    /**
1053     * Reads the data from the rule input field and sets the associated variable.
1054     *
1055     * @param field the object array that holds the details of the field.
1056     *
1057     * @return <code>true</code> if there was no problem reading the data or if there was an
1058     * irrecovarable problem. If there was a problem that can be corrected by the operator, an error
1059     * dialog is popped up and <code>false</code> is returned.
1060     */

1061    /*--------------------------------------------------------------------------*/
1062    private boolean readRuleField(Object JavaDoc[] field)
1063    {
1064        RuleInputField ruleField = null;
1065        String JavaDoc variable = null;
1066
1067        try
1068        {
1069            ruleField = (RuleInputField) field[POS_FIELD];
1070            variable = (String JavaDoc) field[POS_VARIABLE];
1071        }
1072        catch (Throwable JavaDoc exception)
1073        {
1074            return (true);
1075        }
1076        if ((variable == null) || (ruleField == null)) { return (true); }
1077
1078        boolean success = ruleField.validateContents();
1079        if (!success)
1080        {
1081            String JavaDoc message = "";
1082            try
1083            {
1084                message = langpack.getString((String JavaDoc) field[POS_MESSAGE]);
1085                if ("".equals(message))
1086                {
1087                    message = (String JavaDoc) field[POS_MESSAGE];
1088                }
1089            }
1090            catch (Throwable JavaDoc t)
1091            {
1092                message = (String JavaDoc) field[POS_MESSAGE];
1093            }
1094            JOptionPane.showMessageDialog(parentFrame, message, parentFrame.langpack
1095                    .getString("UserInputPanel.error.caption"), JOptionPane.WARNING_MESSAGE);
1096            return (false);
1097        }
1098
1099        idata.setVariable(variable, ruleField.getText());
1100        entries.add(new TextValuePair(variable, ruleField.getText()));
1101        return (true);
1102    }
1103
1104    /*--------------------------------------------------------------------------*/
1105    /**
1106     * Adds a text field to the list of UI elements
1107     *
1108     * @param spec a <code>XMLElement</code> containing the specification for the text field.
1109     */

1110    /*--------------------------------------------------------------------------*/
1111    private void addTextField(XMLElement spec)
1112    {
1113        Vector JavaDoc forPacks = spec.getChildrenNamed(SELECTEDPACKS);
1114        Vector JavaDoc forOs = spec.getChildrenNamed(OS);
1115        XMLElement element = spec.getFirstChildNamed(SPEC);
1116        JLabel JavaDoc label;
1117        String JavaDoc set;
1118        int size;
1119
1120        String JavaDoc variable = spec.getAttribute(VARIABLE);
1121        if ((variable == null) || (variable.length() == 0)) { return; }
1122
1123        // ----------------------------------------------------
1124
// extract the specification details
1125
// ----------------------------------------------------
1126
if (element != null)
1127        {
1128            label = new JLabel JavaDoc(getText(element));
1129            set = element.getAttribute(SET);
1130            if (set == null)
1131            {
1132                set = idata.getVariable(variable);
1133                if (set == null)
1134                {
1135                    set = "";
1136                }
1137            }
1138            else
1139            {
1140                if (set != null && !"".equals(set))
1141                {
1142                    VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
1143                    set = vs.substitute(set, null);
1144                }
1145            }
1146
1147            try
1148            {
1149                size = Integer.parseInt(element.getAttribute(TEXT_SIZE));
1150            }
1151            catch (Throwable JavaDoc exception)
1152            {
1153                size = 1;
1154            }
1155        }
1156        // ----------------------------------------------------
1157
// if there is no specification element, return without
1158
// doing anything.
1159
// ----------------------------------------------------
1160
else
1161        {
1162            return;
1163        }
1164
1165        // ----------------------------------------------------
1166
// get the description and add it to the list UI
1167
// elements if it exists.
1168
// ----------------------------------------------------
1169
element = spec.getFirstChildNamed(DESCRIPTION);
1170        addDescription(element, forPacks, forOs);
1171
1172        // ----------------------------------------------------
1173
// construct the UI element and add it to the list
1174
// ----------------------------------------------------
1175
JTextField JavaDoc field = new JTextField JavaDoc(set, size);
1176        field.setCaretPosition(0);
1177
1178        TwoColumnConstraints constraints = new TwoColumnConstraints();
1179        constraints.position = TwoColumnConstraints.WEST;
1180
1181        uiElements
1182                .add(new Object JavaDoc[] { null, FIELD_LABEL, null, constraints, label, forPacks, forOs});
1183
1184        TwoColumnConstraints constraints2 = new TwoColumnConstraints();
1185        constraints2.position = TwoColumnConstraints.EAST;
1186
1187        uiElements.add(new Object JavaDoc[] { null, TEXT_FIELD, variable, constraints2, field, forPacks,
1188                forOs});
1189    }
1190
1191    /*--------------------------------------------------------------------------*/
1192    /**
1193     * Reads data from the text field and sets the associated variable.
1194     *
1195     * @param field the object array that holds the details of the field.
1196     *
1197     * @return <code>true</code> if there was no problem reading the data or if there was an
1198     * irrecovarable problem. If there was a problem that can be corrected by the operator, an error
1199     * dialog is popped up and <code>false</code> is returned.
1200     */

1201    /*--------------------------------------------------------------------------*/
1202    private boolean readTextField(Object JavaDoc[] field)
1203    {
1204        JTextField JavaDoc textField = null;
1205        String JavaDoc variable = null;
1206        String JavaDoc value = null;
1207
1208        try
1209        {
1210            textField = (JTextField JavaDoc) field[POS_FIELD];
1211            variable = (String JavaDoc) field[POS_VARIABLE];
1212            value = textField.getText();
1213        }
1214        catch (Throwable JavaDoc exception)
1215        {
1216            return (true);
1217        }
1218        if ((variable == null) || (value == null)) { return (true); }
1219
1220        idata.setVariable(variable, value);
1221        entries.add(new TextValuePair(variable, value));
1222        return (true);
1223    }
1224
1225    /*--------------------------------------------------------------------------*/
1226    /**
1227     * Adds a combo box to the list of UI elements. <br>
1228     * This is a complete example of a valid XML specification
1229     *
1230     * <pre>
1231     *
1232     *
1233     *
1234     * &lt;field type=&quot;combo&quot; variable=&quot;testVariable&quot;&gt;
1235     * &lt;description text=&quot;Description for the combo box&quot; id=&quot;a key for translated text&quot;/&gt;
1236     * &lt;spec text=&quot;label&quot; id=&quot;key for the label&quot;/&gt;
1237     * &lt;choice text=&quot;choice 1&quot; id=&quot;&quot; value=&quot;combo box 1&quot;/&gt;
1238     * &lt;choice text=&quot;choice 2&quot; id=&quot;&quot; value=&quot;combo box 2&quot; set=&quot;true&quot;/&gt;
1239     * &lt;choice text=&quot;choice 3&quot; id=&quot;&quot; value=&quot;combo box 3&quot;/&gt;
1240     * &lt;choice text=&quot;choice 4&quot; id=&quot;&quot; value=&quot;combo box 4&quot;/&gt;
1241     * &lt;/spec&gt;
1242     * &lt;/field&gt;
1243     *
1244     *
1245     *
1246     * </pre>
1247     *
1248     * @param spec a <code>XMLElement</code> containing the specification for the combo box.
1249     */

1250    /*--------------------------------------------------------------------------*/
1251    private void addComboBox(XMLElement spec)
1252    {
1253        Vector JavaDoc forPacks = spec.getChildrenNamed(SELECTEDPACKS);
1254        Vector JavaDoc forOs = spec.getChildrenNamed(OS);
1255        XMLElement element = spec.getFirstChildNamed(SPEC);
1256        String JavaDoc variable = spec.getAttribute(VARIABLE);
1257        TextValuePair listItem = null;
1258        JComboBox JavaDoc field = new JComboBox JavaDoc();
1259        JLabel JavaDoc label;
1260
1261        // ----------------------------------------------------
1262
// extract the specification details
1263
// ----------------------------------------------------
1264
if (element != null)
1265        {
1266            label = new JLabel JavaDoc(getText(element));
1267
1268            Vector JavaDoc choices = element.getChildrenNamed(COMBO_CHOICE);
1269
1270            if (choices == null) { return; }
1271
1272            for (int i = 0; i < choices.size(); i++)
1273            {
1274                String JavaDoc processorClass = ((XMLElement) choices.elementAt(i))
1275                        .getAttribute("processor");
1276
1277                if (processorClass != null && !"".equals(processorClass))
1278                {
1279                    String JavaDoc choiceValues = "";
1280                    try
1281                    {
1282                        choiceValues = ((Processor) Class.forName(processorClass).newInstance())
1283                                .process(null);
1284                    }
1285                    catch (Throwable JavaDoc t)
1286                    {
1287                        t.printStackTrace();
1288                    }
1289                    String JavaDoc set = ((XMLElement) choices.elementAt(i)).getAttribute(SET);
1290                    if (set == null)
1291                    {
1292                        set = "";
1293                    }
1294                    if (set != null && !"".equals(set))
1295                    {
1296                        VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
1297                        set = vs.substitute(set, null);
1298                    }
1299
1300                    StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(choiceValues, ":");
1301                    int counter = 0;
1302                    while (tokenizer.hasMoreTokens())
1303                    {
1304                        String JavaDoc token = tokenizer.nextToken();
1305                        listItem = new TextValuePair(token, token);
1306                        field.addItem(listItem);
1307                        if (set.equals(token))
1308                        {
1309                            field.setSelectedIndex(field.getItemCount() - 1);
1310                        }
1311                        counter++;
1312                    }
1313                }
1314                else
1315                {
1316                    listItem = new TextValuePair(getText((XMLElement) choices.elementAt(i)),
1317                            ((XMLElement) choices.elementAt(i)).getAttribute(COMBO_VALUE));
1318                    field.addItem(listItem);
1319                    String JavaDoc set = ((XMLElement) choices.elementAt(i)).getAttribute(SET);
1320                    if (set != null)
1321                    {
1322                        if (set != null && !"".equals(set))
1323                        {
1324                            VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
1325                            set = vs.substitute(set, null);
1326                        }
1327                        if (set.equals(TRUE))
1328                        {
1329                            field.setSelectedIndex(i);
1330                        }
1331                    }
1332                }
1333
1334            }
1335        }
1336        // ----------------------------------------------------
1337
// if there is no specification element, return without
1338
// doing anything.
1339
// ----------------------------------------------------
1340
else
1341        {
1342            return;
1343        }
1344
1345        // ----------------------------------------------------
1346
// get the description and add it to the list of UI
1347
// elements if it exists.
1348
// ----------------------------------------------------
1349
element = spec.getFirstChildNamed(DESCRIPTION);
1350        addDescription(element, forPacks, forOs);
1351
1352        TwoColumnConstraints constraints = new TwoColumnConstraints();
1353        constraints.position = TwoColumnConstraints.WEST;
1354
1355        uiElements
1356                .add(new Object JavaDoc[] { null, FIELD_LABEL, null, constraints, label, forPacks, forOs});
1357
1358        TwoColumnConstraints constraints2 = new TwoColumnConstraints();
1359        constraints2.position = TwoColumnConstraints.EAST;
1360
1361        uiElements.add(new Object JavaDoc[] { null, COMBO_FIELD, variable, constraints2, field, forPacks,
1362                forOs});
1363    }
1364
1365    /*--------------------------------------------------------------------------*/
1366    /**
1367     * Reads the content of the combobox field and substitutes the associated variable.
1368     *
1369     * @param field the object array that holds the details of the field.
1370     *
1371     * @return <code>true</code> if there was no problem reading the data or if there was an
1372     * irrecovarable problem. If there was a problem that can be corrected by the operator, an error
1373     * dialog is popped up and <code>false</code> is returned.
1374     */

1375    /*--------------------------------------------------------------------------*/
1376    private boolean readComboBox(Object JavaDoc[] field)
1377    {
1378        String JavaDoc variable;
1379        String JavaDoc value;
1380        JComboBox JavaDoc comboBox;
1381
1382        try
1383        {
1384            variable = (String JavaDoc) field[POS_VARIABLE];
1385            comboBox = (JComboBox JavaDoc) field[POS_FIELD];
1386            value = ((TextValuePair) comboBox.getSelectedItem()).getValue();
1387        }
1388        catch (Throwable JavaDoc exception)
1389        {
1390            return true;
1391        }
1392        if ((variable == null) || (value == null)) { return true; }
1393
1394        idata.setVariable(variable, value);
1395        entries.add(new TextValuePair(variable, value));
1396        return true;
1397    }
1398
1399    /*--------------------------------------------------------------------------*/
1400    /**
1401     * Adds a radio button set to the list of UI elements. <br>
1402     * This is a complete example of a valid XML specification
1403     *
1404     * <pre>
1405     *
1406     *
1407     *
1408     * &lt;field type=&quot;radio&quot; variable=&quot;testVariable&quot;&gt;
1409     * &lt;description text=&quot;Description for the radio buttons&quot; id=&quot;a key for translated text&quot;/&gt;
1410     * &lt;spec text=&quot;label&quot; id=&quot;key for the label&quot;/&gt;
1411     * &lt;choice text=&quot;radio 1&quot; id=&quot;&quot; value=&quot;&quot;/&gt;
1412     * &lt;choice text=&quot;radio 2&quot; id=&quot;&quot; value=&quot;&quot; set=&quot;true&quot;/&gt;
1413     * &lt;choice text=&quot;radio 3&quot; id=&quot;&quot; value=&quot;&quot;/&gt;
1414     * &lt;choice text=&quot;radio 4&quot; id=&quot;&quot; value=&quot;&quot;/&gt;
1415     * &lt;choice text=&quot;radio 5&quot; id=&quot;&quot; value=&quot;&quot;/&gt;
1416     * &lt;/spec&gt;
1417     * &lt;/field&gt;
1418     *
1419     *
1420     *
1421     * </pre>
1422     *
1423     * @param spec a <code>XMLElement</code> containing the specification for the radio button
1424     * set.
1425     */

1426    /*--------------------------------------------------------------------------*/
1427    private void addRadioButton(XMLElement spec)
1428    {
1429        Vector JavaDoc forPacks = spec.getChildrenNamed(SELECTEDPACKS);
1430        Vector JavaDoc forOs = spec.getChildrenNamed(OS);
1431        String JavaDoc variable = spec.getAttribute(VARIABLE);
1432        String JavaDoc value = null;
1433
1434        XMLElement element = null;
1435        ButtonGroup JavaDoc group = new ButtonGroup JavaDoc();
1436
1437        TwoColumnConstraints constraints = new TwoColumnConstraints();
1438        constraints.position = TwoColumnConstraints.BOTH;
1439        constraints.indent = true;
1440        constraints.stretch = true;
1441
1442        // ----------------------------------------------------
1443
// get the description and add it to the list of UI
1444
// elements if it exists.
1445
// ----------------------------------------------------
1446
element = spec.getFirstChildNamed(DESCRIPTION);
1447        addDescription(element, forPacks, forOs);
1448
1449        // ----------------------------------------------------
1450
// extract the specification details
1451
// ----------------------------------------------------
1452
element = spec.getFirstChildNamed(SPEC);
1453
1454        if (element != null)
1455        {
1456            Vector JavaDoc choices = element.getChildrenNamed(RADIO_CHOICE);
1457
1458            if (choices == null) { return; }
1459
1460            // --------------------------------------------------
1461
// process each choice element
1462
// --------------------------------------------------
1463
for (int i = 0; i < choices.size(); i++)
1464            {
1465                JRadioButton JavaDoc choice = new JRadioButton JavaDoc();
1466                choice.setText(getText((XMLElement) choices.elementAt(i)));
1467                value = (((XMLElement) choices.elementAt(i)).getAttribute(RADIO_VALUE));
1468
1469                group.add(choice);
1470
1471                String JavaDoc set = ((XMLElement) choices.elementAt(i)).getAttribute(SET);
1472                if (set != null)
1473                {
1474                    if (set != null && !"".equals(set))
1475                    {
1476                        VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
1477                        set = vs.substitute(set, null);
1478                    }
1479                    if (set.equals(TRUE))
1480                    {
1481                        choice.setSelected(true);
1482                    }
1483                }
1484
1485                buttonGroups.add(group);
1486                uiElements.add(new Object JavaDoc[] { null, RADIO_FIELD, variable, constraints, choice,
1487                        forPacks, forOs, value, null, null, group});
1488            }
1489        }
1490    }
1491
1492    /*--------------------------------------------------------------------------*/
1493    /**
1494     * Reads the content of the radio button field and substitutes the associated variable.
1495     *
1496     * @param field the object array that holds the details of the field.
1497     *
1498     * @return <code>true</code> if there was no problem reading the data or if there was an
1499     * irrecovarable problem. If there was a problem that can be corrected by the operator, an error
1500     * dialog is popped up and <code>false</code> is returned.
1501     */

1502    /*--------------------------------------------------------------------------*/
1503    private boolean readRadioButton(Object JavaDoc[] field)
1504    {
1505        String JavaDoc variable = null;
1506        String JavaDoc value = null;
1507        JRadioButton JavaDoc button = null;
1508
1509        try
1510        {
1511            button = (JRadioButton JavaDoc) field[POS_FIELD];
1512
1513            if (!button.isSelected()) { return (true); }
1514
1515            variable = (String JavaDoc) field[POS_VARIABLE];
1516            value = (String JavaDoc) field[POS_TRUE];
1517        }
1518        catch (Throwable JavaDoc exception)
1519        {
1520            return (true);
1521        }
1522
1523        idata.setVariable(variable, value);
1524        entries.add(new TextValuePair(variable, value));
1525        return (true);
1526    }
1527
1528    /*--------------------------------------------------------------------------*/
1529    /**
1530     * Adds one or more password fields to the list of UI elements. <br>
1531     * This is a complete example of a valid XML specification
1532     *
1533     * <pre>
1534     *
1535     *
1536     *
1537     * &lt;field type=&quot;password&quot; variable=&quot;testVariable&quot;&gt;
1538     * &lt;description align=&quot;left&quot; txt=&quot;Please enter your password&quot; id=&quot;a key for translated text&quot;/&gt;
1539     * &lt;spec&gt;
1540     * &lt;pwd txt=&quot;Password&quot; id=&quot;key for the label&quot; size=&quot;10&quot; set=&quot;&quot;/&gt;
1541     * &lt;pwd txt=&quot;Retype password&quot; id=&quot;another key for the label&quot; size=&quot;10&quot; set=&quot;&quot;/&gt;
1542     * &lt;/spec&gt;
1543     * &lt;validator class=&quot;com.izforge.sample.PWDValidator&quot; txt=&quot;Both versions of the password must match&quot; id=&quot;key for the error text&quot;/&gt;
1544     * &lt;processor class=&quot;com.izforge.sample.PWDEncryptor&quot;/&gt;
1545     * &lt;/field&gt;
1546     *
1547     *
1548     *
1549     * </pre>
1550     *
1551     * @param spec a <code>XMLElement</code> containing the specification for the set of password
1552     * fields.
1553     */

1554    /*--------------------------------------------------------------------------*/
1555    private void addPasswordField(XMLElement spec)
1556    {
1557        Vector JavaDoc forPacks = spec.getChildrenNamed(SELECTEDPACKS);
1558        Vector JavaDoc forOs = spec.getChildrenNamed(OS);
1559        String JavaDoc variable = spec.getAttribute(VARIABLE);
1560        String JavaDoc validator = null;
1561        String JavaDoc message = null;
1562        String JavaDoc processor = null;
1563        XMLElement element = null;
1564        PasswordGroup group = null;
1565        int size = 0;
1566
1567        // ----------------------------------------------------
1568
// get the description and add it to the list of UI
1569
// elements if it exists.
1570
// ----------------------------------------------------
1571
element = spec.getFirstChildNamed(DESCRIPTION);
1572        addDescription(element, forPacks, forOs);
1573
1574        // ----------------------------------------------------
1575
// get the validator and processor if they are defined
1576
// ----------------------------------------------------
1577
element = spec.getFirstChildNamed(VALIDATOR);
1578        if (element != null)
1579        {
1580            validator = element.getAttribute(CLASS);
1581            message = getText(element);
1582        }
1583
1584        element = spec.getFirstChildNamed(PROCESSOR);
1585        if (element != null)
1586        {
1587            processor = element.getAttribute(CLASS);
1588        }
1589
1590        group = new PasswordGroup(validator, processor);
1591
1592        // ----------------------------------------------------
1593
// extract the specification details
1594
// ----------------------------------------------------
1595
element = spec.getFirstChildNamed(SPEC);
1596
1597        if (element != null)
1598        {
1599            Vector JavaDoc inputs = element.getChildrenNamed(PWD_INPUT);
1600
1601            if (inputs == null) { return; }
1602
1603            // --------------------------------------------------
1604
// process each input field
1605
// --------------------------------------------------
1606
XMLElement fieldSpec;
1607            for (int i = 0; i < inputs.size(); i++)
1608            {
1609                fieldSpec = (XMLElement) inputs.elementAt(i);
1610                String JavaDoc set = fieldSpec.getAttribute(SET);
1611                if (set != null && !"".equals(set))
1612                {
1613                    VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
1614                    set = vs.substitute(set, null);
1615                }
1616                JLabel JavaDoc label = new JLabel JavaDoc(getText(fieldSpec));
1617                try
1618                {
1619                    size = Integer.parseInt(fieldSpec.getAttribute(PWD_SIZE));
1620                }
1621                catch (Throwable JavaDoc exception)
1622                {
1623                    size = 1;
1624                }
1625
1626                // ----------------------------------------------------
1627
// construct the UI element and add it to the list
1628
// ----------------------------------------------------
1629
JPasswordField JavaDoc field = new JPasswordField JavaDoc(set, size);
1630                field.setCaretPosition(0);
1631
1632                TwoColumnConstraints constraints = new TwoColumnConstraints();
1633                constraints.position = TwoColumnConstraints.WEST;
1634
1635                uiElements.add(new Object JavaDoc[] { null, FIELD_LABEL, null, constraints, label,
1636                        forPacks, forOs});
1637
1638                TwoColumnConstraints constraints2 = new TwoColumnConstraints();
1639                constraints2.position = TwoColumnConstraints.EAST;
1640
1641                uiElements.add(new Object JavaDoc[] { null, PWD_FIELD, variable, constraints2, field,
1642                        forPacks, forOs, null, null, message, group});
1643                group.addField(field);
1644            }
1645        }
1646
1647        passwordGroups.add(group);
1648    }
1649
1650    /*--------------------------------------------------------------------------*/
1651    /**
1652     * Reads the content of the password field and substitutes the associated variable.
1653     *
1654     * @param field a password group that manages one or more passord fields.
1655     *
1656     * @return <code>true</code> if there was no problem reading the data or if there was an
1657     * irrecovarable problem. If there was a problem that can be corrected by the operator, an error
1658     * dialog is popped up and <code>false</code> is returned.
1659     */

1660    /*--------------------------------------------------------------------------*/
1661    private boolean readPasswordField(Object JavaDoc[] field)
1662    {
1663        PasswordGroup group = null;
1664        String JavaDoc variable = null;
1665        String JavaDoc message = null;
1666
1667        try
1668        {
1669            group = (PasswordGroup) field[POS_GROUP];
1670            variable = (String JavaDoc) field[POS_VARIABLE];
1671            message = (String JavaDoc) field[POS_MESSAGE];
1672        }
1673        catch (Throwable JavaDoc exception)
1674        {
1675            return (true);
1676        }
1677        if ((variable == null) || (passwordGroupsRead.contains(group))) { return (true); }
1678        passwordGroups.add(group);
1679
1680        boolean success = group.validateContents();
1681
1682        if (!success)
1683        {
1684            JOptionPane.showMessageDialog(parentFrame, message, parentFrame.langpack
1685                    .getString("UserInputPanel.error.caption"), JOptionPane.WARNING_MESSAGE);
1686            return (false);
1687        }
1688
1689        idata.setVariable(variable, group.getPassword());
1690        entries.add(new TextValuePair(variable, group.getPassword()));
1691        return (true);
1692    }
1693
1694    /*--------------------------------------------------------------------------*/
1695    /**
1696     * Adds a chackbox to the list of UI elements.
1697     *
1698     * @param spec a <code>XMLElement</code> containing the specification for the checkbox.
1699     */

1700    /*--------------------------------------------------------------------------*/
1701    private void addCheckBox(XMLElement spec)
1702    {
1703        Vector JavaDoc forPacks = spec.getChildrenNamed(SELECTEDPACKS);
1704        Vector JavaDoc forOs = spec.getChildrenNamed(OS);
1705        String JavaDoc label = "";
1706        String JavaDoc set = null;
1707        String JavaDoc trueValue = null;
1708        String JavaDoc falseValue = null;
1709        String JavaDoc variable = spec.getAttribute(VARIABLE);
1710        XMLElement detail = spec.getFirstChildNamed(SPEC);
1711
1712        if (variable == null) { return; }
1713
1714        if (detail != null)
1715        {
1716            label = getText(detail);
1717            set = detail.getAttribute(SET);
1718            trueValue = detail.getAttribute(TRUE);
1719            falseValue = detail.getAttribute(FALSE);
1720        }
1721
1722        JCheckBox JavaDoc checkbox = new JCheckBox JavaDoc(label);
1723
1724        if (set != null)
1725        {
1726            if (set != null && !"".equals(set))
1727            {
1728                VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
1729                set = vs.substitute(set, null);
1730            }
1731            if (set.equals(FALSE))
1732            {
1733                checkbox.setSelected(false);
1734            }
1735            if (set.equals(TRUE))
1736            {
1737                checkbox.setSelected(true);
1738            }
1739        }
1740
1741        // ----------------------------------------------------
1742
// get the description and add it to the list of UI
1743
// elements if it exists.
1744
// ----------------------------------------------------
1745
XMLElement element = spec.getFirstChildNamed(DESCRIPTION);
1746        addDescription(element, forPacks, forOs);
1747
1748        TwoColumnConstraints constraints = new TwoColumnConstraints();
1749        constraints.position = TwoColumnConstraints.BOTH;
1750        constraints.stretch = true;
1751        constraints.indent = true;
1752
1753        uiElements.add(new Object JavaDoc[] { null, CHECK_FIELD, variable, constraints, checkbox, forPacks,
1754                forOs, trueValue, falseValue});
1755    }
1756
1757    /*--------------------------------------------------------------------------*/
1758    /**
1759     * Reads the content of the checkbox field and substitutes the associated variable.
1760     *
1761     * @param field the object array that holds the details of the field.
1762     *
1763     * @return <code>true</code> if there was no problem reading the data or if there was an
1764     * irrecovarable problem. If there was a problem that can be corrected by the operator, an error
1765     * dialog is popped up and <code>false</code> is returned.
1766     */

1767    /*--------------------------------------------------------------------------*/
1768    private boolean readCheckBox(Object JavaDoc[] field)
1769    {
1770        String JavaDoc variable = null;
1771        String JavaDoc trueValue = null;
1772        String JavaDoc falseValue = null;
1773        JCheckBox JavaDoc box = null;
1774
1775        try
1776        {
1777            box = (JCheckBox JavaDoc) field[POS_FIELD];
1778            variable = (String JavaDoc) field[POS_VARIABLE];
1779            trueValue = (String JavaDoc) field[POS_TRUE];
1780            if (trueValue == null)
1781            {
1782                trueValue = "";
1783            }
1784
1785            falseValue = (String JavaDoc) field[POS_FALSE];
1786            if (falseValue == null)
1787            {
1788                falseValue = "";
1789            }
1790        }
1791        catch (Throwable JavaDoc exception)
1792        {
1793            return (true);
1794        }
1795
1796        if (box.isSelected())
1797        {
1798            idata.setVariable(variable, trueValue);
1799            entries.add(new TextValuePair(variable, trueValue));
1800        }
1801        else
1802        {
1803            idata.setVariable(variable, falseValue);
1804            entries.add(new TextValuePair(variable, falseValue));
1805        }
1806
1807        return (true);
1808    }
1809
1810    /*--------------------------------------------------------------------------*/
1811    /**
1812     * Adds a search field to the list of UI elements.
1813     * <p>
1814     * This is a complete example of a valid XML specification
1815     *
1816     * <pre>
1817     *
1818     *
1819     *
1820     * &lt;field type=&quot;search&quot; variable=&quot;testVariable&quot;&gt;
1821     * &lt;description text=&quot;Description for the search field&quot; id=&quot;a key for translated text&quot;/&gt;
1822     * &lt;spec text=&quot;label&quot; id=&quot;key for the label&quot; filename=&quot;the_file_to_search&quot; result=&quot;directory&quot; /&gt; &lt;!-- values for result: directory, file --&gt;
1823     * &lt;choice dir=&quot;directory1&quot; set=&quot;true&quot; /&gt; &lt;!-- default value --&gt;
1824     * &lt;choice dir=&quot;dir2&quot; /&gt;
1825     * &lt;/spec&gt;
1826     * &lt;/field&gt;
1827     *
1828     *
1829     *
1830     * </pre>
1831     *
1832     * @param spec a <code>XMLElement</code> containing the specification for the search field
1833     */

1834    /*--------------------------------------------------------------------------*/
1835    private void addSearch(XMLElement spec)
1836    {
1837        Vector JavaDoc forPacks = spec.getChildrenNamed(SELECTEDPACKS);
1838        Vector JavaDoc forOs = spec.getChildrenNamed(OS);
1839        XMLElement element = spec.getFirstChildNamed(SPEC);
1840        String JavaDoc variable = spec.getAttribute(VARIABLE);
1841        String JavaDoc filename = null;
1842        String JavaDoc check_filename = null;
1843        int search_type = 0;
1844        int result_type = 0;
1845        JComboBox JavaDoc combobox = new JComboBox JavaDoc();
1846        JLabel JavaDoc label = null;
1847
1848        // System.out.println ("adding search combobox, variable "+variable);
1849

1850        // allow the user to enter something
1851
combobox.setEditable(true);
1852
1853        // ----------------------------------------------------
1854
// extract the specification details
1855
// ----------------------------------------------------
1856
if (element != null)
1857        {
1858            label = new JLabel JavaDoc(getText(element));
1859
1860            // search type is optional (default: file)
1861
search_type = SearchField.TYPE_FILE;
1862
1863            String JavaDoc search_type_str = element.getAttribute(SEARCH_TYPE);
1864
1865            if (search_type_str != null)
1866            {
1867                if (search_type_str.equals(SEARCH_FILE))
1868                {
1869                    search_type = SearchField.TYPE_FILE;
1870                }
1871                else if (search_type_str.equals(SEARCH_DIRECTORY))
1872                {
1873                    search_type = SearchField.TYPE_DIRECTORY;
1874                }
1875            }
1876
1877            // result type is mandatory too
1878
String JavaDoc result_type_str = element.getAttribute(SEARCH_RESULT);
1879
1880            if (result_type_str == null)
1881            {
1882                return;
1883            }
1884            else if (result_type_str.equals(SEARCH_FILE))
1885            {
1886                result_type = SearchField.RESULT_FILE;
1887            }
1888            else if (result_type_str.equals(SEARCH_DIRECTORY))
1889            {
1890                result_type = SearchField.RESULT_DIRECTORY;
1891            }
1892            else if (result_type_str.equals(SEARCH_PARENTDIR))
1893            {
1894                result_type = SearchField.RESULT_PARENTDIR;
1895            }
1896            else
1897            {
1898                return;
1899            }
1900
1901            // might be missing - null is okay
1902
filename = element.getAttribute(SEARCH_FILENAME);
1903
1904            check_filename = element.getAttribute(SEARCH_CHECKFILENAME);
1905
1906            Vector JavaDoc choices = element.getChildrenNamed(SEARCH_CHOICE);
1907
1908            if (choices == null) { return; }
1909
1910            for (int i = 0; i < choices.size(); i++)
1911            {
1912                XMLElement choice_el = (XMLElement) choices.elementAt(i);
1913
1914                if (!OsConstraint.oneMatchesCurrentSystem(choice_el)) continue;
1915
1916                String JavaDoc value = choice_el.getAttribute(SEARCH_VALUE);
1917
1918                combobox.addItem(value);
1919
1920                String JavaDoc set = ((XMLElement) choices.elementAt(i)).getAttribute(SET);
1921                if (set != null)
1922                {
1923                    if (set != null && !"".equals(set))
1924                    {
1925                        VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
1926                        set = vs.substitute(set, null);
1927                    }
1928                    if (set.equals(TRUE))
1929                    {
1930                        combobox.setSelectedIndex(i);
1931                    }
1932                }
1933            }
1934        }
1935        // ----------------------------------------------------
1936
// if there is no specification element, return without
1937
// doing anything.
1938
// ----------------------------------------------------
1939
else
1940        {
1941            return;
1942        }
1943
1944        // ----------------------------------------------------
1945
// get the description and add it to the list of UI
1946
// elements if it exists.
1947
// ----------------------------------------------------
1948
element = spec.getFirstChildNamed(DESCRIPTION);
1949        addDescription(element, forPacks, forOs);
1950
1951        TwoColumnConstraints westconstraint1 = new TwoColumnConstraints();
1952        westconstraint1.position = TwoColumnConstraints.WEST;
1953
1954        uiElements.add(new Object JavaDoc[] { null, FIELD_LABEL, null, westconstraint1, label, forPacks,
1955                forOs});
1956
1957        TwoColumnConstraints eastconstraint1 = new TwoColumnConstraints();
1958        eastconstraint1.position = TwoColumnConstraints.EAST;
1959
1960        StringBuffer JavaDoc tooltiptext = new StringBuffer JavaDoc();
1961
1962        if ((filename != null) && (filename.length() > 0))
1963        {
1964            tooltiptext.append(MessageFormat.format(parentFrame.langpack
1965                    .getString("UserInputPanel.search.location"), new String JavaDoc[] { filename}));
1966        }
1967
1968        boolean showAutodetect = (check_filename != null) && (check_filename.length() > 0);
1969        if (showAutodetect)
1970        {
1971            tooltiptext.append(MessageFormat.format(parentFrame.langpack
1972                    .getString("UserInputPanel.search.location.checkedfile"),
1973                    new String JavaDoc[] { check_filename}));
1974        }
1975
1976        if (tooltiptext.length() > 0) combobox.setToolTipText(tooltiptext.toString());
1977
1978        uiElements.add(new Object JavaDoc[] { null, SEARCH_FIELD, variable, eastconstraint1, combobox,
1979                forPacks, forOs});
1980
1981        JPanel JavaDoc buttonPanel = new JPanel JavaDoc();
1982        buttonPanel.setLayout(new com.izforge.izpack.gui.FlowLayout(
1983                com.izforge.izpack.gui.FlowLayout.LEADING));
1984
1985        JButton JavaDoc autodetectButton = ButtonFactory.createButton(parentFrame.langpack
1986                .getString("UserInputPanel.search.autodetect"), idata.buttonsHColor);
1987        autodetectButton.setVisible(showAutodetect);
1988
1989        autodetectButton.setToolTipText(parentFrame.langpack
1990                .getString("UserInputPanel.search.autodetect.tooltip"));
1991
1992        buttonPanel.add(autodetectButton);
1993
1994        JButton JavaDoc browseButton = ButtonFactory.createButton(parentFrame.langpack
1995                .getString("UserInputPanel.search.browse"), idata.buttonsHColor);
1996
1997        buttonPanel.add(browseButton);
1998
1999        TwoColumnConstraints eastonlyconstraint = new TwoColumnConstraints();
2000        eastonlyconstraint.position = TwoColumnConstraints.EASTONLY;
2001
2002        uiElements.add(new Object JavaDoc[] { null, SEARCH_BUTTON_FIELD, null, eastonlyconstraint,
2003                buttonPanel, forPacks, forOs});
2004
2005        searchFields.add(new SearchField(filename, check_filename, parentFrame, combobox,
2006                autodetectButton, browseButton, search_type, result_type));
2007    }
2008
2009    /*--------------------------------------------------------------------------*/
2010    /**
2011     * Reads the content of the search field and substitutes the associated variable.
2012     *
2013     * @param field the object array that holds the details of the field.
2014     *
2015     * @return <code>true</code> if there was no problem reading the data or if there was an
2016     * irrecovarable problem. If there was a problem that can be corrected by the operator, an error
2017     * dialog is popped up and <code>false</code> is returned.
2018     */

2019    /*--------------------------------------------------------------------------*/
2020    private boolean readSearch(Object JavaDoc[] field)
2021    {
2022        String JavaDoc variable = null;
2023        String JavaDoc value = null;
2024        JComboBox JavaDoc comboBox = null;
2025
2026        try
2027        {
2028            variable = (String JavaDoc) field[POS_VARIABLE];
2029            comboBox = (JComboBox JavaDoc) field[POS_FIELD];
2030            for (int i = 0; i < this.searchFields.size(); ++i)
2031            {
2032                SearchField sf = (SearchField) this.searchFields.elementAt(i);
2033                if (sf.belongsTo(comboBox))
2034                {
2035                    value = sf.getResult();
2036                    break;
2037                }
2038            }
2039        }
2040        catch (Throwable JavaDoc exception)
2041        {
2042            return (true);
2043        }
2044        if ((variable == null) || (value == null)) { return (true); }
2045
2046        idata.setVariable(variable, value);
2047        entries.add(new TextValuePair(variable, value));
2048        return (true);
2049    }
2050
2051    /*--------------------------------------------------------------------------*/
2052    /**
2053     * Adds text to the list of UI elements
2054     *
2055     * @param spec a <code>XMLElement</code> containing the specification for the text.
2056     */

2057    /*--------------------------------------------------------------------------*/
2058    private void addText(XMLElement spec)
2059    {
2060        Vector JavaDoc forPacks = spec.getChildrenNamed(SELECTEDPACKS);
2061        Vector JavaDoc forOs = spec.getChildrenNamed(OS);
2062
2063        addDescription(spec, forPacks, forOs);
2064    }
2065
2066    /*--------------------------------------------------------------------------*/
2067    /**
2068     * Adds a dummy field to the list of UI elements to act as spacer.
2069     *
2070     * @param spec a <code>XMLElement</code> containing other specifications. At present this
2071     * information is not used but might be in future versions.
2072     */

2073    /*--------------------------------------------------------------------------*/
2074    private void addSpace(XMLElement spec)
2075    {
2076        Vector JavaDoc forPacks = spec.getChildrenNamed(SELECTEDPACKS);
2077        Vector JavaDoc forOs = spec.getChildrenNamed(OS);
2078        JPanel JavaDoc panel = new JPanel JavaDoc();
2079
2080        TwoColumnConstraints constraints = new TwoColumnConstraints();
2081        constraints.position = TwoColumnConstraints.BOTH;
2082        constraints.stretch = true;
2083
2084        uiElements
2085                .add(new Object JavaDoc[] { null, SPACE_FIELD, null, constraints, panel, forPacks, forOs});
2086    }
2087
2088    /*--------------------------------------------------------------------------*/
2089    /**
2090     * Adds a dividing line to the list of UI elements act as separator.
2091     *
2092     * @param spec a <code>XMLElement</code> containing additional specifications.
2093     */

2094    /*--------------------------------------------------------------------------*/
2095    private void addDivider(XMLElement spec)
2096    {
2097        Vector JavaDoc forPacks = spec.getChildrenNamed(SELECTEDPACKS);
2098        Vector JavaDoc forOs = spec.getChildrenNamed(OS);
2099        JPanel JavaDoc panel = new JPanel JavaDoc();
2100        String JavaDoc alignment = spec.getAttribute(ALIGNMENT);
2101
2102        if (alignment != null)
2103        {
2104            if (alignment.equals(TOP))
2105            {
2106                panel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.gray));
2107            }
2108            else
2109            {
2110                panel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray));
2111            }
2112        }
2113        else
2114        {
2115            panel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray));
2116        }
2117
2118        TwoColumnConstraints constraints = new TwoColumnConstraints();
2119        constraints.position = TwoColumnConstraints.BOTH;
2120        constraints.stretch = true;
2121
2122        uiElements.add(new Object JavaDoc[] { null, DIVIDER_FIELD, null, constraints, panel, forPacks,
2123                forOs});
2124    }
2125
2126    /*--------------------------------------------------------------------------*/
2127    /**
2128     * Adds a description to the list of UI elements.
2129     *
2130     * @param spec a <code>XMLElement</code> containing the specification for the description.
2131     */

2132    /*--------------------------------------------------------------------------*/
2133    private void addDescription(XMLElement spec, Vector JavaDoc forPacks, Vector JavaDoc forOs)
2134    {
2135        String JavaDoc description;
2136        TwoColumnConstraints constraints = new TwoColumnConstraints();
2137        constraints.position = TwoColumnConstraints.BOTH;
2138        constraints.stretch = true;
2139
2140        if (spec != null)
2141        {
2142            description = getText(spec);
2143
2144            // if we have a description, add it to the UI elements
2145
if (description != null)
2146            {
2147                String JavaDoc alignment = spec.getAttribute(ALIGNMENT);
2148                int justify = MultiLineLabel.LEFT;
2149
2150                if (alignment != null)
2151                {
2152                    if (alignment.equals(LEFT))
2153                    {
2154                        justify = MultiLineLabel.LEFT;
2155                    }
2156                    else if (alignment.equals(CENTER))
2157                    {
2158                        justify = MultiLineLabel.CENTER;
2159                    }
2160                    else if (alignment.equals(RIGHT))
2161                    {
2162                        justify = MultiLineLabel.RIGHT;
2163                    }
2164                }
2165
2166                javax.swing.JTextPane JavaDoc label = new javax.swing.JTextPane JavaDoc();
2167                
2168                // Not editable, but still selectable.
2169
label.setEditable(false);
2170                
2171                // If html tags are present enable html rendering, otherwise the JTextPane
2172
// looks exactly like MultiLineLabel.
2173
if(description.startsWith("<html>") && description.endsWith("</html>"))
2174                    label.setContentType("text/html");
2175                label.setText(description);
2176                
2177                // Background color and font to match the label's.
2178
label.setBackground(javax.swing.UIManager.getColor("label.backgroud"));
2179                label.setMargin(new java.awt.Insets JavaDoc(3, 0, 3, 0));
2180                    
2181                uiElements.add(new Object JavaDoc[] { null, DESCRIPTION, null, constraints, label,
2182                        forPacks, forOs});
2183            }
2184        }
2185    }
2186
2187    /*--------------------------------------------------------------------------*/
2188    /**
2189     * Retrieves the value of a boolean attribute. If the attribute is found and the values equals
2190     * the value of the constant <code>TRUE</code> then true is returned. If it equals
2191     * <code>FALSE</code> the false is returned. In all other cases, including when the attribute
2192     * is not found, the default value is returned.
2193     *
2194     * @param element the <code>XMLElement</code> to search for the attribute.
2195     * @param attribute the attribute to search for
2196     * @param defaultValue the default value to use if the attribute does not exist or a illegal
2197     * value was discovered.
2198     *
2199     * @return <code>true</code> if the attribute is found and the value equals the the constant
2200     * <code>TRUE</code>. <<code> if the
2201     * attribute is <code>FALSE</code>. In all other cases the
2202     * default value is returned.
2203     */

2204    /*--------------------------------------------------------------------------*/
2205    private boolean getBoolean(XMLElement element, String JavaDoc attribute, boolean defaultValue)
2206    {
2207        boolean result = defaultValue;
2208
2209        if ((attribute != null) && (attribute.length() > 0))
2210        {
2211            String JavaDoc value = element.getAttribute(attribute);
2212
2213            if (value != null)
2214            {
2215                if (value.equals(TRUE))
2216                {
2217                    result = true;
2218                }
2219                else if (value.equals(FALSE))
2220                {
2221                    result = false;
2222                }
2223            }
2224        }
2225
2226        return (result);
2227    }
2228
2229    /*--------------------------------------------------------------------------*/
2230    /**
2231     * Retrieves the value of an integer attribute. If the attribute is not found or the value is
2232     * non-numeric then the default value is returned.
2233     *
2234     * @param element the <code>XMLElement</code> to search for the attribute.
2235     * @param attribute the attribute to search for
2236     * @param defaultValue the default value to use in case the attribute does not exist.
2237     *
2238     * @return the value of the attribute. If the attribute is not found or the content is not a
2239     * legal integer, then the default value is returned.
2240     */

2241    /*--------------------------------------------------------------------------*/
2242    // private int getInt(XMLElement element, String attribute, int defaultValue)
2243
// {
2244
// int result = defaultValue;
2245
//
2246
// if ((attribute != null) && (attribute.length() > 0))
2247
// {
2248
// try
2249
// {
2250
// result = Integer.parseInt(element.getAttribute(attribute));
2251
// }
2252
// catch (Throwable exception)
2253
// {}
2254
// }
2255
//
2256
// return (result);
2257
// }
2258
/*--------------------------------------------------------------------------*/
2259    /**
2260     * Retrieves the value of a floating point attribute. If the attribute is not found or the value
2261     * is non-numeric then the default value is returned.
2262     *
2263     * @param element the <code>XMLElement</code> to search for the attribute.
2264     * @param attribute the attribute to search for
2265     * @param defaultValue the default value to use in case the attribute does not exist.
2266     *
2267     * @return the value of the attribute. If the attribute is not found or the content is not a
2268     * legal integer, then the default value is returned.
2269     */

2270    /*--------------------------------------------------------------------------*/
2271    private float getFloat(XMLElement element, String JavaDoc attribute, float defaultValue)
2272    {
2273        float result = defaultValue;
2274
2275        if ((attribute != null) && (attribute.length() > 0))
2276        {
2277            try
2278            {
2279                result = Float.parseFloat(element.getAttribute(attribute));
2280            }
2281            catch (Throwable JavaDoc exception)
2282            {}
2283        }
2284
2285        return (result);
2286    }
2287
2288    /*--------------------------------------------------------------------------*/
2289    /**
2290     * Extracts the text from an <code>XMLElement</code>. The text must be defined in the
2291     * resource file under the key defined in the <code>id</code> attribute or as value of the
2292     * attribute <code>text</code>.
2293     *
2294     * @param element the <code>XMLElement</code> from which to extract the text.
2295     *
2296     * @return The text defined in the <code>XMLElement</code>. If no text can be located,
2297     * <code>null</code> is returned.
2298     */

2299    /*--------------------------------------------------------------------------*/
2300    private String JavaDoc getText(XMLElement element)
2301    {
2302        if (element == null) { return (null); }
2303
2304        String JavaDoc key = element.getAttribute(KEY);
2305        String JavaDoc text = null;
2306
2307        if ((key != null) && (langpack != null))
2308        {
2309            try
2310            {
2311                text = langpack.getString(key);
2312            }
2313            catch (Throwable JavaDoc exception)
2314            {
2315                text = null;
2316            }
2317        }
2318
2319        // if there is no text in the description, then
2320
// we were unable to retrieve it form the resource.
2321
// In this case try to get the text directly from
2322
// the XMLElement
2323
if (text == null)
2324        {
2325            text = element.getAttribute(TEXT);
2326        }
2327
2328        return (text);
2329    }
2330
2331    /*--------------------------------------------------------------------------*/
2332    /**
2333     * Retreives the alignment setting for the <code>XMLElement</code>. The default value in case
2334     * the <code>ALIGNMENT</code> attribute is not found or the value is illegal is
2335     * <code>TwoColumnConstraints.LEFT</code>.
2336     *
2337     * @param element the <code>XMLElement</code> from which to extract the alignment setting.
2338     *
2339     * @return the alignement setting for the <code>XMLElement</code>. The value is either
2340     * <code>TwoColumnConstraints.LEFT</code>, <code>TwoColumnConstraints.CENTER</code> or
2341     * <code>TwoColumnConstraints.RIGHT</code>.
2342     *
2343     * @see com.izforge.izpack.gui.TwoColumnConstraints
2344     */

2345    /*--------------------------------------------------------------------------*/
2346    private int getAlignment(XMLElement element)
2347    {
2348        int result = TwoColumnConstraints.LEFT;
2349
2350        String JavaDoc value = element.getAttribute(ALIGNMENT);
2351
2352        if (value != null)
2353        {
2354            if (value.equals(LEFT))
2355            {
2356                result = TwoColumnConstraints.LEFT;
2357            }
2358            else if (value.equals(CENTER))
2359            {
2360                result = TwoColumnConstraints.CENTER;
2361            }
2362            else if (value.equals(RIGHT))
2363            {
2364                result = TwoColumnConstraints.RIGHT;
2365            }
2366        }
2367
2368        return (result);
2369    }
2370
2371    /**
2372     * Verifies if an item is required for the operating system the installer executed. The
2373     * configuration for this feature is: <br/> &lt;os family="unix"/&gt; <br>
2374     * <br>
2375     * <b>Note:</b><br>
2376     * If the list of the os is empty then <code>true</code> is always returnd.
2377     *
2378     * @param os The <code>Vector</code> of <code>String</code>s. containing the os names
2379     *
2380     * @return <code>true</code> if the item is required for the os, otherwise returns
2381     * <code>false</code>.
2382     */

2383    public boolean itemRequiredForOs(Vector JavaDoc os)
2384    {
2385        if (os.size() == 0) { return true; }
2386
2387        for (int i = 0; i < os.size(); i++)
2388        {
2389            String JavaDoc family = ((XMLElement) os.elementAt(i)).getAttribute(FAMILY);
2390            boolean match = false;
2391
2392            if ("windows".equals(family))
2393            {
2394                match = OsVersion.IS_WINDOWS;
2395            }
2396            else if ("mac".equals(family))
2397            {
2398                match = OsVersion.IS_OSX;
2399            }
2400            else if ("unix".equals(family))
2401            {
2402                match = OsVersion.IS_UNIX;
2403            }
2404            if (match) { return true; }
2405        }
2406        return false;
2407    }
2408
2409    /*--------------------------------------------------------------------------*/
2410    /**
2411     * Verifies if an item is required for any of the packs listed. An item is required for a pack
2412     * in the list if that pack is actually selected for installation. <br>
2413     * <br>
2414     * <b>Note:</b><br>
2415     * If the list of selected packs is empty then <code>true</code> is always returnd. The same
2416     * is true if the <code>packs</code> list is empty.
2417     *
2418     * @param packs a <code>Vector</code> of <code>String</code>s. Each of the strings denotes
2419     * a pack for which an item should be created if the pack is actually installed.
2420     *
2421     * @return <code>true</code> if the item is required for at least one pack in the list,
2422     * otherwise returns <code>false</code>.
2423     */

2424    /*--------------------------------------------------------------------------*/
2425    /*
2426     * $ @design
2427     *
2428     * The information about the installed packs comes from InstallData.selectedPacks. This assumes
2429     * that this panel is presented to the user AFTER the PacksPanel.
2430     * --------------------------------------------------------------------------
2431     */

2432    private boolean itemRequiredFor(Vector JavaDoc packs)
2433    {
2434
2435        String JavaDoc selected;
2436        String JavaDoc required;
2437
2438        if (packs.size() == 0) { return (true); }
2439
2440        // ----------------------------------------------------
2441
// We are getting to this point if any packs have been
2442
// specified. This means that there is a possibility
2443
// that some UI elements will not get added. This
2444
// means that we can not allow to go back to the
2445
// PacksPanel, because the process of building the
2446
// UI is not reversable.
2447
// ----------------------------------------------------
2448
// packsDefined = true;
2449

2450        // ----------------------------------------------------
2451
// analyze if the any of the packs for which the item
2452
// is required have been selected for installation.
2453
// ----------------------------------------------------
2454
for (int i = 0; i < idata.selectedPacks.size(); i++)
2455        {
2456            selected = ((Pack) idata.selectedPacks.get(i)).name;
2457
2458            for (int k = 0; k < packs.size(); k++)
2459            {
2460                required = (String JavaDoc) ((XMLElement) packs.elementAt(k)).getAttribute(NAME, "");
2461                if (selected.equals(required)) { return (true); }
2462            }
2463        }
2464
2465        return (false);
2466    }
2467
2468    /*--------------------------------------------------------------------------*/
2469    /**
2470     * Verifies if an item is required for any of the packs listed. An item is required for a pack
2471     * in the list if that pack is actually NOT selected for installation. <br>
2472     * <br>
2473     * <b>Note:</b><br>
2474     * If the list of selected packs is empty then <code>true</code> is always returnd. The same
2475     * is true if the <code>packs</code> list is empty.
2476     *
2477     * @param packs a <code>Vector</code> of <code>String</code>s. Each of the strings denotes
2478     * a pack for which an item should be created if the pack is actually installed.
2479     *
2480     * @return <code>true</code> if the item is required for at least one pack in the list,
2481     * otherwise returns <code>false</code>.
2482     */

2483    /*--------------------------------------------------------------------------*/
2484    /*
2485     * $ @design
2486     *
2487     * The information about the installed packs comes from InstallData.selectedPacks. This assumes
2488     * that this panel is presented to the user AFTER the PacksPanel.
2489     * --------------------------------------------------------------------------
2490     */

2491    private boolean itemRequiredForUnselected(Vector JavaDoc packs)
2492    {
2493
2494        String JavaDoc selected;
2495        String JavaDoc required;
2496
2497        if (packs.size() == 0) { return (true); }
2498
2499        // ----------------------------------------------------
2500
// analyze if the any of the packs for which the item
2501
// is required have been selected for installation.
2502
// ----------------------------------------------------
2503
for (int i = 0; i < idata.selectedPacks.size(); i++)
2504        {
2505            selected = ((Pack) idata.selectedPacks.get(i)).name;
2506
2507            for (int k = 0; k < packs.size(); k++)
2508            {
2509                required = (String JavaDoc) ((XMLElement) packs.elementAt(k)).getAttribute(NAME, "");
2510                if (selected.equals(required)) { return (false); }
2511            }
2512        }
2513
2514        return (true);
2515    }
2516
2517    // ----------- Inheritance stuff -----------------------------------------
2518
/**
2519     * Returns the uiElements.
2520     *
2521     * @return Returns the uiElements.
2522     */

2523    protected Vector JavaDoc getUiElements()
2524    {
2525        return uiElements;
2526    }
2527
2528    // --------------------------------------------------------------------------
2529
// Inner Classes
2530
// --------------------------------------------------------------------------
2531

2532    /*---------------------------------------------------------------------------*/
2533    /**
2534     * This class can be used to associate a text string and a (text) value.
2535     */

2536    /*---------------------------------------------------------------------------*/
2537    private static class TextValuePair
2538    {
2539
2540        private String JavaDoc text = "";
2541
2542        private String JavaDoc value = "";
2543
2544        /*--------------------------------------------------------------------------*/
2545        /**
2546         * Constructs a new Text/Value pair, initialized with the text and a value.
2547         *
2548         * @param text the text that this object should represent
2549         * @param value the value that should be associated with this object
2550         */

2551        /*--------------------------------------------------------------------------*/
2552        public TextValuePair(String JavaDoc text, String JavaDoc value)
2553        {
2554            this.text = text;
2555            this.value = value;
2556        }
2557
2558        /*--------------------------------------------------------------------------*/
2559        /**
2560         * Sets the text
2561         *
2562         * @param text the text for this object
2563         */

2564        /*--------------------------------------------------------------------------*/
2565        public void setText(String JavaDoc text)
2566        {
2567            this.text = text;
2568        }
2569
2570        /*--------------------------------------------------------------------------*/
2571        /**
2572         * Sets the value of this object
2573         *
2574         * @param value the value for this object
2575         */

2576        /*--------------------------------------------------------------------------*/
2577        public void setValue(String JavaDoc value)
2578        {
2579            this.value = value;
2580        }
2581
2582        /*--------------------------------------------------------------------------*/
2583        /**
2584         * This method returns the text that was set for the object
2585         *
2586         * @return the object's text
2587         */

2588        /*--------------------------------------------------------------------------*/
2589        public String JavaDoc toString()
2590        {
2591            return (text);
2592        }
2593
2594        /*--------------------------------------------------------------------------*/
2595        /**
2596         * This method returns the value that was associated with this object
2597         *
2598         * @return the object's value
2599         */

2600        /*--------------------------------------------------------------------------*/
2601        public String JavaDoc getValue()
2602        {
2603            return (value);
2604        }
2605    }
2606
2607    /*---------------------------------------------------------------------------*/
2608    /**
2609     * This class encapsulates a lot of search field functionality.
2610     *
2611     * A search field supports searching directories and files on the target system. This is a
2612     * helper class to manage all data belonging to a search field.
2613     */

2614    /*---------------------------------------------------------------------------*/
2615
2616    private class SearchField implements ActionListener JavaDoc
2617    {
2618
2619        /** used in constructor - we search for a directory. */
2620        public static final int TYPE_DIRECTORY = 1;
2621
2622        /** used in constructor - we search for a file. */
2623        public static final int TYPE_FILE = 2;
2624
2625        /** used in constructor - result of search is the directory. */
2626        public static final int RESULT_DIRECTORY = 1;
2627
2628        /** used in constructor - result of search is the whole file name. */
2629        public static final int RESULT_FILE = 2;
2630
2631        /** used in constructor - result of search is the parent directory. */
2632        public static final int RESULT_PARENTDIR = 3;
2633
2634        private String JavaDoc filename = null;
2635
2636        private String JavaDoc checkFilename = null;
2637
2638        private JButton JavaDoc autodetectButton = null;
2639
2640        private JButton JavaDoc browseButton = null;
2641
2642        private JComboBox JavaDoc pathComboBox = null;
2643
2644        private int searchType = TYPE_DIRECTORY;
2645
2646        private int resultType = RESULT_DIRECTORY;
2647
2648        private InstallerFrame parent = null;
2649
2650        /*---------------------------------------------------------------------------*/
2651        /**
2652         * Constructor - initializes the object, adds it as action listener to the "autodetect"
2653         * button.
2654         *
2655         * @param filename the name of the file to search for (might be null for searching
2656         * directories)
2657         * @param checkFilename the name of the file to check when searching for directories (the
2658         * checkFilename is appended to a found directory to figure out whether it is the right
2659         * directory)
2660         * @param combobox the <code>JComboBox</code> holding the list of choices; it should be
2661         * editable and contain only Strings
2662         * @param autobutton the autodetection button for triggering autodetection
2663         * @param browsebutton the browse button to look for the file
2664         * @param search_type what to search for - TYPE_FILE or TYPE_DIRECTORY
2665         * @param result_type what to return as the result - RESULT_FILE or RESULT_DIRECTORY or
2666         * RESULT_PARENTDIR
2667         */

2668        /*---------------------------------------------------------------------------*/
2669        public SearchField(String JavaDoc filename, String JavaDoc checkFilename, InstallerFrame parent,
2670                JComboBox JavaDoc combobox, JButton JavaDoc autobutton, JButton JavaDoc browsebutton, int search_type,
2671                int result_type)
2672        {
2673            this.filename = filename;
2674            this.checkFilename = checkFilename;
2675            this.parent = parent;
2676            this.autodetectButton = autobutton;
2677            this.browseButton = browsebutton;
2678            this.pathComboBox = combobox;
2679            this.searchType = search_type;
2680            this.resultType = result_type;
2681
2682            this.autodetectButton.addActionListener(this);
2683            this.browseButton.addActionListener(this);
2684
2685            autodetect();
2686        }
2687
2688        /**
2689         * Check whether the given combobox belongs to this searchfield. This is used when reading
2690         * the results.
2691         */

2692        public boolean belongsTo(JComboBox JavaDoc combobox)
2693        {
2694            return (this.pathComboBox == combobox);
2695        }
2696
2697        /** check whether the given path matches */
2698        private boolean pathMatches(String JavaDoc path)
2699        {
2700            if (path != null)
2701            { // Make sure, path is not null
2702
// System.out.println ("checking path " + path);
2703

2704                File JavaDoc file = null;
2705
2706                if ((this.filename == null) || (this.searchType == TYPE_DIRECTORY))
2707                {
2708                    file = new File JavaDoc(path);
2709                }
2710                else
2711                {
2712                    file = new File JavaDoc(path, this.filename);
2713                }
2714
2715                if (file.exists())
2716                {
2717
2718                    if (((this.searchType == TYPE_DIRECTORY) && (file.isDirectory()))
2719                            || ((this.searchType == TYPE_FILE) && (file.isFile())))
2720                    {
2721                        // no file to check for
2722
if (this.checkFilename == null) return true;
2723
2724                        file = new File JavaDoc(file, this.checkFilename);
2725
2726                        return file.exists();
2727                    }
2728
2729                }
2730
2731                // System.out.println (path + " did not match");
2732
} // end if
2733
return false;
2734        }
2735
2736        /** perform autodetection */
2737        public boolean autodetect()
2738        {
2739            Vector JavaDoc items = new Vector JavaDoc();
2740
2741            /*
2742             * Check if the user has entered data into the ComboBox and add it to the Itemlist
2743             */

2744            String JavaDoc selected = (String JavaDoc) this.pathComboBox.getSelectedItem();
2745            if (selected == null) { return false; }
2746            boolean found = false;
2747            for (int x = 0; x < this.pathComboBox.getItemCount(); x++)
2748            {
2749                if (((String JavaDoc) this.pathComboBox.getItemAt(x)).equals(selected))
2750                {
2751                    found = true;
2752                }
2753            }
2754            if (!found)
2755            {
2756                // System.out.println("Not found in Itemlist");
2757
this.pathComboBox.addItem(this.pathComboBox.getSelectedItem());
2758            }
2759
2760            // Checks whether a placeholder item is in the combobox
2761
// and resolve the pathes automatically:
2762
// /usr/lib/* searches all folders in usr/lib to find
2763
// /usr/lib/*/lib/tools.jar
2764
for (int i = 0; i < this.pathComboBox.getItemCount(); ++i)
2765            {
2766                String JavaDoc path = (String JavaDoc) this.pathComboBox.getItemAt(i);
2767
2768                if (path.endsWith("*"))
2769                {
2770                    path = path.substring(0, path.length() - 1);
2771                    File JavaDoc dir = new File JavaDoc(path);
2772
2773                    if (dir.isDirectory())
2774                    {
2775                        File JavaDoc[] subdirs = dir.listFiles();
2776                        for (int x = 0; x < subdirs.length; x++)
2777                        {
2778                            String JavaDoc search = subdirs[x].getAbsolutePath();
2779                            if (this.pathMatches(search))
2780                            {
2781                                items.add(search);
2782                            }
2783                        }
2784                    }
2785                }
2786                else
2787                {
2788                    if (this.pathMatches(path))
2789                    {
2790                        items.add(path);
2791                    }
2792                }
2793            }
2794            // Make the enties in the vector unique
2795
items = new Vector JavaDoc(new HashSet JavaDoc(items));
2796
2797            // Now clear the combobox and add the items out of the newly
2798
// generated vector
2799
this.pathComboBox.removeAllItems();
2800            VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
2801            for (int i = 0; i < items.size(); i++)
2802            {
2803                this.pathComboBox.addItem(vs.substitute((String JavaDoc) items.get(i), "plain"));
2804            }
2805
2806            // loop through all items
2807
for (int i = 0; i < this.pathComboBox.getItemCount(); ++i)
2808            {
2809                String JavaDoc path = (String JavaDoc) this.pathComboBox.getItemAt(i);
2810
2811                if (this.pathMatches(path))
2812                {
2813                    this.pathComboBox.setSelectedIndex(i);
2814                    return true;
2815                }
2816
2817            }
2818
2819            // if the user entered something else, it's not listed as an item
2820
return this.pathMatches((String JavaDoc) this.pathComboBox.getSelectedItem());
2821
2822        }
2823
2824        /*--------------------------------------------------------------------------*/
2825        /**
2826         * This is called if one of the buttons has bee pressed.
2827         *
2828         * It checks, which button caused the action and acts accordingly.
2829         */

2830        /*--------------------------------------------------------------------------*/
2831        public void actionPerformed(ActionEvent JavaDoc event)
2832        {
2833            // System.out.println ("autodetection button pressed.");
2834

2835            if (event.getSource() == this.autodetectButton)
2836            {
2837                if (!autodetect())
2838                    JOptionPane.showMessageDialog(parent, parent.langpack
2839                            .getString("UserInputPanel.search.autodetect.failed.message"),
2840                            parent.langpack
2841                                    .getString("UserInputPanel.search.autodetect.failed.caption"),
2842                            JOptionPane.WARNING_MESSAGE);
2843            }
2844            else if (event.getSource() == this.browseButton)
2845            {
2846                JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
2847
2848                if (this.resultType != TYPE_FILE)
2849                    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
2850
2851                int result = chooser.showOpenDialog(this.parent);
2852
2853                if (result == JFileChooser.APPROVE_OPTION)
2854                {
2855                    File JavaDoc f = chooser.getSelectedFile();
2856
2857                    this.pathComboBox.setSelectedItem(f.getAbsolutePath());
2858
2859                    // use any given directory directly
2860
if (this.resultType != TYPE_FILE && !this.pathMatches(f.getAbsolutePath()))
2861                    {
2862                        JOptionPane.showMessageDialog(parent, parent.langpack
2863                                .getString("UserInputPanel.search.wrongselection.message"),
2864                                parent.langpack
2865                                        .getString("UserInputPanel.search.wrongselection.caption"),
2866                                JOptionPane.WARNING_MESSAGE);
2867                    }
2868                }
2869
2870            }
2871
2872            // we don't care for anything more here - getResult() does the rest
2873
}
2874
2875        /*--------------------------------------------------------------------------*/
2876        /**
2877         * Return the result of the search according to result type.
2878         *
2879         * Sometimes, the whole path of the file is wanted, sometimes only the directory where the
2880         * file is in, sometimes the parent directory.
2881         *
2882         * @return null on error
2883         */

2884        /*--------------------------------------------------------------------------*/
2885        public String JavaDoc getResult()
2886        {
2887            String JavaDoc item = (String JavaDoc) this.pathComboBox.getSelectedItem();
2888            if (item != null) item = item.trim();
2889            String JavaDoc path = item;
2890
2891            File JavaDoc f = new File JavaDoc(item);
2892
2893            if (!f.isDirectory())
2894            {
2895                path = f.getParent();
2896            }
2897
2898            // path now contains the final content of the combo box
2899
if (this.resultType == RESULT_DIRECTORY)
2900            {
2901                return path;
2902            }
2903            else if (this.resultType == RESULT_FILE)
2904            {
2905                if (this.filename != null)
2906                {
2907                    return path + File.separatorChar + this.filename;
2908                }
2909                else
2910                {
2911                    return item;
2912                }
2913            }
2914            else if (this.resultType == RESULT_PARENTDIR)
2915            {
2916                File JavaDoc dir = new File JavaDoc(path);
2917                return dir.getParent();
2918            }
2919
2920            return null;
2921        }
2922
2923    } // private class SearchFile
2924

2925    protected void updateVariables()
2926    {
2927        /**
2928         * Look if there are new variables defined
2929         */

2930        Vector JavaDoc variables = spec.getChildrenNamed(VARIABLE_NODE);
2931        RulesEngine rules = parent.getRules();
2932
2933        VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
2934        for (int i = 0; i < variables.size(); i++)
2935        {
2936            XMLElement variable = (XMLElement) variables.elementAt(i);
2937            String JavaDoc vname = variable.getAttribute(ATTRIBUTE_VARIABLE_NAME);
2938            String JavaDoc vvalue = variable.getAttribute(ATTRIBUTE_VARIABLE_VALUE);
2939            String JavaDoc conditionid = variable.getAttribute(ATTRIBUTE_CONDITIONID_NAME);
2940            if (conditionid != null)
2941            {
2942                // check if condition for this variable is fulfilled
2943
if (!rules.isConditionTrue(conditionid, idata.getVariables()))
2944                {
2945                    continue;
2946                }
2947            }
2948            // are there any OS-Constraints?
2949
if (OsConstraint.oneMatchesCurrentSystem(variable))
2950            {
2951                if (vname == null)
2952                {
2953                    continue;
2954                }
2955                else
2956                {
2957                    // vname is given
2958
if (vvalue != null)
2959                    {
2960                        // try to substitute variables in value field
2961
vvalue = vs.substitute(vvalue, null);
2962                        // to cut out circular references
2963
idata.setVariable(vname, "");
2964                        vvalue = vs.substitute(vvalue, null);
2965                    }
2966                    // try to set variable
2967
idata.setVariable(vname, vvalue);
2968
2969                    //
2970
}
2971            }
2972        }
2973    }
2974
2975} // public class UserInputPanel
2976
/*---------------------------------------------------------------------------*/
2977
2978
Popular Tags