[izpack-changes] r1719 - izpack-src/trunk/src/lib/com/izforge/izpack/panels
noreply at berlios.de
noreply at berlios.de
Wed Jan 24 11:05:59 CET 2007
Author: dreil
Date: 2007-01-24 11:05:54 +0100 (Wed, 24 Jan 2007)
New Revision: 1719
Modified:
izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java
Log:
Selection in combo-fields dynamically adapted
Modified: izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java 2007-01-20 18:21:13 UTC (rev 1718)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java 2007-01-24 10:05:54 UTC (rev 1719)
@@ -292,7 +292,7 @@
private static final String UNSELECTEDPACKS = "createForUnselectedPack"; // new
protected static final String ATTRIBUTE_CONDITIONID_NAME = "conditionid";
-
+
protected static final String VARIABLE_NODE = "variable";
protected static final String ATTRIBUTE_VARIABLE_NAME = "name";
@@ -425,7 +425,7 @@
// refresh variables specified in spec
updateVariables();
-
+
// ----------------------------------------------------
// process all field nodes. Each field node is analyzed
// for its type, then an appropriate memeber function
@@ -509,7 +509,7 @@
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
@@ -557,7 +557,7 @@
if (value == null)
{
value = rulef.getText();
- }
+ }
}
// overwrite entry;
uiElements.set(i, element);
@@ -592,8 +592,8 @@
/*--------------------------------------------------------------------------*/
public void panelActivate()
{
- this.init();
-
+ this.init();
+
if (spec == null)
{
// TODO: translate
@@ -601,7 +601,7 @@
"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
+ // update UI with current values of associated variables
updateUIElements();
Vector forPacks = spec.getChildrenNamed(SELECTEDPACKS);
Vector forUnselectedPacks = spec.getChildrenNamed(UNSELECTEDPACKS);
@@ -624,12 +624,12 @@
// }
buildUI();
- //need a validation, else ui is scrambled
+ // need a validation, else ui is scrambled
validate();
if (packsDefined)
{
parentFrame.lockPrevButton();
- }
+ }
}
/*--------------------------------------------------------------------------*/
@@ -1228,21 +1228,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.
@@ -1258,6 +1258,7 @@
JComboBox field = new JComboBox();
JLabel label;
+ boolean userinput = false; // is there already user input?
// ----------------------------------------------------
// extract the specification details
// ----------------------------------------------------
@@ -1268,7 +1269,13 @@
Vector choices = element.getChildrenNamed(COMBO_CHOICE);
if (choices == null) { return; }
-
+ // get current value of associated variable
+ String currentvariablevalue = idata.getVariable(variable);
+ if (currentvariablevalue != null)
+ {
+ // there seems to be user input
+ userinput = true;
+ }
for (int i = 0; i < choices.size(); i++)
{
String processorClass = ((XMLElement) choices.elementAt(i))
@@ -1313,21 +1320,37 @@
}
else
{
- listItem = new TextValuePair(getText((XMLElement) choices.elementAt(i)),
- ((XMLElement) choices.elementAt(i)).getAttribute(COMBO_VALUE));
+ String value = ((XMLElement) choices.elementAt(i)).getAttribute(COMBO_VALUE);
+ listItem = new TextValuePair(getText((XMLElement) choices.elementAt(i)), value);
field.addItem(listItem);
- String set = ((XMLElement) choices.elementAt(i)).getAttribute(SET);
- if (set != null)
+ if (userinput)
+ {
+ // is the current value identical to the value associated with this element
+ if ((value != null) && (value.length() > 0)
+ && (currentvariablevalue.equals(value)))
+ {
+ // select it
+ field.setSelectedIndex(i);
+ }
+ // else do nothing
+ }
+ else
{
- if (set != null && !"".equals(set))
+ // there is no user input
+ String set = ((XMLElement) choices.elementAt(i)).getAttribute(SET);
+ if (set != null)
{
- VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
- set = vs.substitute(set, null);
+ if (set != null && !"".equals(set))
+ {
+ VariableSubstitutor vs = new VariableSubstitutor(idata
+ .getVariables());
+ set = vs.substitute(set, null);
+ }
+ if (set.equals(TRUE))
+ {
+ field.setSelectedIndex(i);
+ }
}
- if (set.equals(TRUE))
- {
- field.setSelectedIndex(i);
- }
}
}
@@ -1402,22 +1425,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
@@ -1531,21 +1554,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
@@ -1814,19 +1837,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
@@ -2164,20 +2187,20 @@
}
javax.swing.JTextPane label = new javax.swing.JTextPane();
-
+
// Not editable, but still selectable.
label.setEditable(false);
-
+
// If html tags are present enable html rendering, otherwise the JTextPane
// looks exactly like MultiLineLabel.
- if(description.startsWith("<html>") && description.endsWith("</html>"))
- label.setContentType("text/html");
+ if (description.startsWith("<html>") && description.endsWith("</html>"))
+ label.setContentType("text/html");
label.setText(description);
-
+
// Background color and font to match the label's.
label.setBackground(javax.swing.UIManager.getColor("label.backgroud"));
label.setMargin(new java.awt.Insets(3, 0, 3, 0));
-
+
uiElements.add(new Object[] { null, DESCRIPTION, null, constraints, label,
forPacks, forOs});
}
@@ -2921,7 +2944,7 @@
}
} // private class SearchFile
-
+
protected void updateVariables()
{
/**
More information about the izpack-changes
mailing list