[izpack-changes] r1651 - izpack-src/trunk/src/lib/com/izforge/izpack/panels
noreply at berlios.de
noreply at berlios.de
Fri Nov 24 14:18:48 CET 2006
Author: dreil
Date: 2006-11-24 14:18:47 +0100 (Fri, 24 Nov 2006)
New Revision: 1651
Modified:
izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java
Log:
added conditions to UserinputPanel fields
Modified: izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java 2006-11-24 13:16:54 UTC (rev 1650)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java 2006-11-24 13:18:47 UTC (rev 1651)
@@ -1,22 +1,19 @@
/*
* IzPack - Copyright 2001-2006 Julien Ponge, All Rights Reserved.
*
- * http://www.izforge.com/izpack/
- * http://developer.berlios.de/projects/izpack/
+ * http://www.izforge.com/izpack/ http://developer.berlios.de/projects/izpack/
*
* Copyright 2002 Elmar Grom
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
*/
package com.izforge.izpack.panels;
@@ -293,6 +290,8 @@
private static final String UNSELECTEDPACKS = "createForUnselectedPack"; // new
+ protected static final String ATTRIBUTE_CONDITIONID_NAME = "conditionid";
+
// node
private static final String NAME = "name";
@@ -366,13 +365,17 @@
*/
/*--------------------------------------------------------------------------*/
public UserInputPanel(InstallerFrame parent, InstallData installData)
-
{
super(parent, installData);
-
instanceNumber = instanceCount++;
this.parentFrame = parent;
+ }
+ protected void init()
+ {
+ super.removeAll();
+ uiElements.clear();
+
// ----------------------------------------------------
// ----------------------------------------------------
TwoColumnLayout layout = new TwoColumnLayout(10, 5, 30, 25, TwoColumnLayout.LEFT);
@@ -424,7 +427,15 @@
{
XMLElement field = (XMLElement) fields.elementAt(i);
String attribute = field.getAttribute(TYPE);
-
+ String conditionid = field.getAttribute(ATTRIBUTE_CONDITIONID_NAME);
+ if (conditionid != null)
+ {
+ // check if condition is fulfilled
+ if (!this.parent.getRules().isConditionTrue(conditionid, idata.getVariables()))
+ {
+ continue;
+ }
+ }
if (attribute != null)
{
if (attribute.equals(RULE_FIELD))
@@ -475,6 +486,81 @@
}
}
+ protected void updateUIElements()
+ {
+ boolean updated = false;
+ VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
+
+ for (int i = 0; i < uiElements.size(); i++)
+ {
+ Object[] element = (Object[]) uiElements.get(i);
+ if (element[POS_VARIABLE] == null)
+ {
+ continue;
+ }
+ String value = idata.getVariable((String) element[POS_VARIABLE]);
+
+ if (RADIO_FIELD.equals(element[POS_TYPE]))
+ {
+ // we have a radio field, which should be updated
+ JRadioButton choice = (JRadioButton) element[POS_FIELD];
+ if (value == null)
+ {
+ continue;
+ }
+ if (value.equals(element[POS_TRUE]))
+ {
+ choice.setSelected(true);
+ }
+ else
+ {
+ choice.setSelected(false);
+ }
+ element[POS_FIELD] = choice;
+ }
+ else if (TEXT_FIELD.equals(element[POS_TYPE]))
+ {
+ // update TextField
+ JTextField textf = (JTextField) element[POS_FIELD];
+
+ // System.out.println("Textfield: " + value);
+ if (value == null)
+ {
+ value = textf.getText();
+ }
+ textf.setText(vs.substitute(value, null));
+ element[POS_FIELD] = textf;
+ }
+ else if (CHECK_FIELD.equals(element[POS_TYPE]))
+ {
+ // TODO: HAS TO BE IMPLEMENTED
+ }
+ else if (SEARCH_FIELD.equals(element[POS_TYPE]))
+ {
+ // TODO: HAS TO BE IMPLEMENTED
+ }
+ else if (RULE_FIELD.equals(element[POS_TYPE]))
+ {
+
+ RuleInputField rulef = (RuleInputField) element[POS_FIELD];
+ // System.out.println("RuleInputField: " + value);
+ if (value == null)
+ {
+ value = rulef.getText();
+ }
+ }
+ // overwrite entry;
+ uiElements.set(i, element);
+ updated = true;
+ }
+ if (updated)
+ {
+ // super.removeAll();
+ super.invalidate();
+ // buildUI();
+ }
+ }
+
/*--------------------------------------------------------------------------*/
/**
* Indicates wether the panel has been validated or not. The installer won't let the user go
@@ -496,6 +582,8 @@
/*--------------------------------------------------------------------------*/
public void panelActivate()
{
+ this.init();
+
if (spec == null)
{
// TODO: translate
@@ -503,7 +591,8 @@
"The specification for the user input panel could not be found. Please contact the packager.");
parentFrame.skipPanel();
}
-
+ // update UI with current values of associated variables
+ updateUIElements();
Vector forPacks = spec.getChildrenNamed(SELECTEDPACKS);
Vector forUnselectedPacks = spec.getChildrenNamed(UNSELECTEDPACKS);
Vector forOs = spec.getChildrenNamed(OS);
@@ -528,7 +617,7 @@
if (packsDefined)
{
parentFrame.lockPrevButton();
- }
+ }
}
/*--------------------------------------------------------------------------*/
@@ -894,13 +983,12 @@
// If so, then add them to validateParamMap.
// ----------------------------------------------------------
validateParams = element.getChildrenNamed(RULE_PARAM);
- if (validateParams != null && validateParams.size() > 0)
+ if (validateParams != null && validateParams.size() > 0)
{
hasParams = true;
-
- if (validateParamMap == null)
- validateParamMap = new HashMap();
+ if (validateParamMap == null) validateParamMap = new HashMap();
+
for (Iterator it = validateParams.iterator(); it.hasNext();)
{
element = (XMLElement) it.next();
@@ -908,7 +996,7 @@
paramValue = element.getAttribute(RULE_PARAM_VALUE);
validateParamMap.put(paramName, paramValue);
}
-
+
}
}
@@ -1034,13 +1122,16 @@
{
set = "";
}
- }else{
- if (set != null && !"".equals(set)){
+ }
+ else
+ {
+ if (set != null && !"".equals(set))
+ {
VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
set = vs.substitute(set, null);
}
}
-
+
try
{
size = Integer.parseInt(element.getAttribute(TEXT_SIZE));
@@ -1125,21 +1216,21 @@
* This is a complete example of a valid XML specification
*
* <pre>
- *
*
*
- * <field type="combo" variable="testVariable">
- * <description text="Description for the combo box" id="a key for translated text"/>
- * <spec text="label" id="key for the label"/>
- * <choice text="choice 1" id="" value="combo box 1"/>
- * <choice text="choice 2" id="" value="combo box 2" set="true"/>
- * <choice text="choice 3" id="" value="combo box 3"/>
- * <choice text="choice 4" id="" value="combo box 4"/>
- * </spec>
- * </field>
*
+ * <field type="combo" variable="testVariable">
+ * <description text="Description for the combo box" id="a key for translated text"/>
+ * <spec text="label" id="key for the label"/>
+ * <choice text="choice 1" id="" value="combo box 1"/>
+ * <choice text="choice 2" id="" value="combo box 2" set="true"/>
+ * <choice text="choice 3" id="" value="combo box 3"/>
+ * <choice text="choice 4" id="" value="combo box 4"/>
+ * </spec>
+ * </field>
+ *
+ *
*
- *
* </pre>
*
* @param spec a <code>XMLElement</code> containing the specification for the combo box.
@@ -1188,11 +1279,12 @@
{
set = "";
}
- if (set != null && !"".equals(set)){
+ if (set != null && !"".equals(set))
+ {
VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
set = vs.substitute(set, null);
}
-
+
StringTokenizer tokenizer = new StringTokenizer(choiceValues, ":");
int counter = 0;
while (tokenizer.hasMoreTokens())
@@ -1215,7 +1307,8 @@
String set = ((XMLElement) choices.elementAt(i)).getAttribute(SET);
if (set != null)
{
- if (set != null && !"".equals(set)){
+ if (set != null && !"".equals(set))
+ {
VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
set = vs.substitute(set, null);
}
@@ -1297,22 +1390,22 @@
* This is a complete example of a valid XML specification
*
* <pre>
- *
*
*
- * <field type="radio" variable="testVariable">
- * <description text="Description for the radio buttons" id="a key for translated text"/>
- * <spec text="label" id="key for the label"/>
- * <choice text="radio 1" id="" value=""/>
- * <choice text="radio 2" id="" value="" set="true"/>
- * <choice text="radio 3" id="" value=""/>
- * <choice text="radio 4" id="" value=""/>
- * <choice text="radio 5" id="" value=""/>
- * </spec>
- * </field>
*
+ * <field type="radio" variable="testVariable">
+ * <description text="Description for the radio buttons" id="a key for translated text"/>
+ * <spec text="label" id="key for the label"/>
+ * <choice text="radio 1" id="" value=""/>
+ * <choice text="radio 2" id="" value="" set="true"/>
+ * <choice text="radio 3" id="" value=""/>
+ * <choice text="radio 4" id="" value=""/>
+ * <choice text="radio 5" id="" value=""/>
+ * </spec>
+ * </field>
+ *
+ *
*
- *
* </pre>
*
* @param spec a <code>XMLElement</code> containing the specification for the radio button
@@ -1366,7 +1459,8 @@
String set = ((XMLElement) choices.elementAt(i)).getAttribute(SET);
if (set != null)
{
- if (set != null && !"".equals(set)){
+ if (set != null && !"".equals(set))
+ {
VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
set = vs.substitute(set, null);
}
@@ -1425,21 +1519,21 @@
* This is a complete example of a valid XML specification
*
* <pre>
- *
*
*
- * <field type="password" variable="testVariable">
- * <description align="left" txt="Please enter your password" id="a key for translated text"/>
- * <spec>
- * <pwd txt="Password" id="key for the label" size="10" set=""/>
- * <pwd txt="Retype password" id="another key for the label" size="10" set=""/>
- * </spec>
- * <validator class="com.izforge.sample.PWDValidator" txt="Both versions of the password must match" id="key for the error text"/>
- * <processor class="com.izforge.sample.PWDEncryptor"/>
- * </field>
*
+ * <field type="password" variable="testVariable">
+ * <description align="left" txt="Please enter your password" id="a key for translated text"/>
+ * <spec>
+ * <pwd txt="Password" id="key for the label" size="10" set=""/>
+ * <pwd txt="Retype password" id="another key for the label" size="10" set=""/>
+ * </spec>
+ * <validator class="com.izforge.sample.PWDValidator" txt="Both versions of the password must match" id="key for the error text"/>
+ * <processor class="com.izforge.sample.PWDEncryptor"/>
+ * </field>
+ *
+ *
*
- *
* </pre>
*
* @param spec a <code>XMLElement</code> containing the specification for the set of password
@@ -1502,7 +1596,8 @@
{
fieldSpec = (XMLElement) inputs.elementAt(i);
String set = fieldSpec.getAttribute(SET);
- if (set != null && !"".equals(set)){
+ if (set != null && !"".equals(set))
+ {
VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
set = vs.substitute(set, null);
}
@@ -1616,7 +1711,8 @@
if (set != null)
{
- if (set != null && !"".equals(set)){
+ if (set != null && !"".equals(set))
+ {
VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
set = vs.substitute(set, null);
}
@@ -1706,19 +1802,19 @@
* This is a complete example of a valid XML specification
*
* <pre>
- *
*
*
- * <field type="search" variable="testVariable">
- * <description text="Description for the search field" id="a key for translated text"/>
- * <spec text="label" id="key for the label" filename="the_file_to_search" result="directory" /> <!-- values for result: directory, file -->
- * <choice dir="directory1" set="true" /> <!-- default value -->
- * <choice dir="dir2" />
- * </spec>
- * </field>
*
+ * <field type="search" variable="testVariable">
+ * <description text="Description for the search field" id="a key for translated text"/>
+ * <spec text="label" id="key for the label" filename="the_file_to_search" result="directory" /> <!-- values for result: directory, file -->
+ * <choice dir="directory1" set="true" /> <!-- default value -->
+ * <choice dir="dir2" />
+ * </spec>
+ * </field>
+ *
+ *
*
- *
* </pre>
*
* @param spec a <code>XMLElement</code> containing the specification for the search field
@@ -1812,7 +1908,8 @@
String set = ((XMLElement) choices.elementAt(i)).getAttribute(SET);
if (set != null)
{
- if (set != null && !"".equals(set)){
+ if (set != null && !"".equals(set))
+ {
VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
set = vs.substitute(set, null);
}
@@ -2117,23 +2214,22 @@
* legal integer, then the default value is returned.
*/
/*--------------------------------------------------------------------------*/
-// private int getInt(XMLElement element, String attribute, int defaultValue)
-// {
-// int result = defaultValue;
-//
-// if ((attribute != null) && (attribute.length() > 0))
-// {
-// try
-// {
-// result = Integer.parseInt(element.getAttribute(attribute));
-// }
-// catch (Throwable exception)
-// {}
-// }
-//
-// return (result);
-// }
-
+ // private int getInt(XMLElement element, String attribute, int defaultValue)
+ // {
+ // int result = defaultValue;
+ //
+ // if ((attribute != null) && (attribute.length() > 0))
+ // {
+ // try
+ // {
+ // result = Integer.parseInt(element.getAttribute(attribute));
+ // }
+ // catch (Throwable exception)
+ // {}
+ // }
+ //
+ // return (result);
+ // }
/*--------------------------------------------------------------------------*/
/**
* Retrieves the value of a floating point attribute. If the attribute is not found or the value
@@ -2280,10 +2376,7 @@
{
match = OsVersion.IS_UNIX;
}
- if (match)
- {
- return true;
- }
+ if (match) { return true; }
}
return false;
}
@@ -2624,10 +2717,7 @@
* Check if the user has entered data into the ComboBox and add it to the Itemlist
*/
String selected = (String) this.pathComboBox.getSelectedItem();
- if (selected == null)
- {
- return false;
- }
+ if (selected == null) { return false; }
boolean found = false;
for (int x = 0; x < this.pathComboBox.getItemCount(); x++)
{
More information about the izpack-changes
mailing list