001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019:
020: package com.izforge.izpack.panels;
021:
022: import com.izforge.izpack.installer.InstallData;
023: import com.izforge.izpack.installer.InstallerFrame;
024:
025: /**
026: * This panel adds some conditional behavior to the standard UserInputPanel. <br/> <b>Usage:</b><br/>
027: * In the "panels" list, just use ConditionalUserInputPanel like the normal UserInputPanel. The
028: * specification goes also into userInputSpec.xml and userInputLang.xml_XXX. To specify a condition
029: * for a certain ConditionalUserInputPanel, you have to specify the condition in the
030: * "variables"-section by defining the following variables:<br/>
031: * <li><i>compareToVariable."panel-order"</i>: The variable name containing the value to compare
032: * with
033: * <li><i>compareToOperator."panel-order"</i>: The compare operator to use, currently only "=" and
034: * "!=" are allowed
035: * <li><i>compareToValue."panel-order"</i>: The value to compare with<br/> If the compare fails,
036: * the panel will be skipped.
037: *
038: * @see UserInputPanel
039: *
040: * @author $author$
041: * @version $Revision: 2036 $
042: */
043: public class ConditionalUserInputPanel extends UserInputPanel {
044:
045: private static final long serialVersionUID = 3257283617406465844L;
046:
047: /**
048: * Creates a new ConditionalUserInputPanel object.
049: *
050: * @param parent
051: * @param installData
052: */
053: public ConditionalUserInputPanel(InstallerFrame parent,
054: InstallData installData) {
055: super (parent, installData);
056: }
057:
058: /**
059: * Panel is only activated, if the configured condition is true
060: */
061: public void panelActivate() {
062: // get configured condition for this panel
063: String compareToValue = idata.getVariable("compareToValue."
064: + instanceNumber);
065: String compareToVariable = idata
066: .getVariable("compareToVariable." + instanceNumber);
067: String compareToOperator = idata
068: .getVariable("compareToOperator." + instanceNumber);
069: String compareValue = null;
070:
071: // get value of the compareVariable
072: if (null != compareToVariable) {
073: compareValue = idata.getVariable(compareToVariable);
074: }
075:
076: if ("=".equalsIgnoreCase(compareToOperator)) {
077: // compare using equal
078: if (((null != compareToValue) && compareToValue
079: .equalsIgnoreCase(compareValue))
080: || ((null != compareValue) && compareValue
081: .equalsIgnoreCase(compareToValue))) {
082: super .panelActivate();
083: } else {
084: parent.skipPanel();
085: }
086: } else if ("!=".equalsIgnoreCase(compareToOperator)) {
087: // compare using un-equal
088: if (((null != compareToValue) && !compareToValue
089: .equalsIgnoreCase(compareValue))
090: || ((null != compareValue) && !compareValue
091: .equalsIgnoreCase(compareToValue))) {
092: super .panelActivate();
093: } else {
094: parent.skipPanel();
095: }
096: } else {
097: // wrong operator!
098: emitError(
099: "Invalid operator specified for compareToOperator."
100: + instanceNumber,
101: "Only '=' and '!=' are currently allowed!");
102: parent.skipPanel();
103: }
104: }
105: }
|