KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * 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
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 package com.izforge.izpack.panels;
21
22 import com.izforge.izpack.installer.InstallData;
23 import com.izforge.izpack.installer.InstallerFrame;
24
25 /**
26  * This panel adds some conditional behavior to the standard UserInputPanel. <br/> <b>Usage:</b><br/>
27  * In the "panels" list, just use ConditionalUserInputPanel like the normal UserInputPanel. The
28  * specification goes also into userInputSpec.xml and userInputLang.xml_XXX. To specify a condition
29  * for a certain ConditionalUserInputPanel, you have to specify the condition in the
30  * "variables"-section by defining the following variables:<br/>
31  * <li><i>compareToVariable."panel-order"</i>: The variable name containing the value to compare
32  * with
33  * <li><i>compareToOperator."panel-order"</i>: The compare operator to use, currently only "=" and
34  * "!=" are allowed
35  * <li><i>compareToValue."panel-order"</i>: The value to compare with<br/> If the compare fails,
36  * the panel will be skipped.
37  *
38  * @see UserInputPanel
39  *
40  * @author $author$
41  * @version $Revision: 1708 $
42  */

43 public class ConditionalUserInputPanel extends UserInputPanel
44 {
45
46     private static final long serialVersionUID = 3257283617406465844L;
47
48     /**
49      * Creates a new ConditionalUserInputPanel object.
50      *
51      * @param parent
52      * @param installData
53      */

54     public ConditionalUserInputPanel(InstallerFrame parent, InstallData installData)
55     {
56         super(parent, installData);
57     }
58
59     /**
60      * Panel is only activated, if the configured condition is true
61      */

62     public void panelActivate()
63     {
64         // get configured condition for this panel
65
String JavaDoc compareToValue = idata.getVariable("compareToValue." + instanceNumber);
66         String JavaDoc compareToVariable = idata.getVariable("compareToVariable." + instanceNumber);
67         String JavaDoc compareToOperator = idata.getVariable("compareToOperator." + instanceNumber);
68         String JavaDoc compareValue = null;
69
70         // get value of the compareVariable
71
if (null != compareToVariable)
72         {
73             compareValue = idata.getVariable(compareToVariable);
74         }
75
76         if ("=".equalsIgnoreCase(compareToOperator))
77         {
78             // compare using equal
79
if (((null != compareToValue) && compareToValue.equalsIgnoreCase(compareValue))
80                     || ((null != compareValue) && compareValue.equalsIgnoreCase(compareToValue)))
81             {
82                 super.panelActivate();
83             }
84             else
85             {
86                 parent.skipPanel();
87             }
88         }
89         else if ("!=".equalsIgnoreCase(compareToOperator))
90         {
91             // compare using un-equal
92
if (((null != compareToValue) && !compareToValue.equalsIgnoreCase(compareValue))
93                     || ((null != compareValue) && !compareValue.equalsIgnoreCase(compareToValue)))
94             {
95                 super.panelActivate();
96             }
97             else
98             {
99                 parent.skipPanel();
100             }
101         }
102         else
103         {
104             // wrong operator!
105
emitError("Invalid operator specified for compareToOperator." + instanceNumber,
106                     "Only '=' and '!=' are currently allowed!");
107             parent.skipPanel();
108         }
109     }
110 }
111
Popular Tags