[izpack-changes] r1699 - in izpack-src/trunk: . src/lib/com/izforge/izpack/panels src/lib/com/izforge/izpack/rules
noreply at berlios.de
noreply at berlios.de
Wed Jan 10 13:57:26 CET 2007
Author: dreil
Date: 2007-01-10 13:57:20 +0100 (Wed, 10 Jan 2007)
New Revision: 1699
Modified:
izpack-src/trunk/Versions.txt
izpack-src/trunk/src/lib/com/izforge/izpack/panels/PacksModel.java
izpack-src/trunk/src/lib/com/izforge/izpack/panels/PacksPanelBase.java
izpack-src/trunk/src/lib/com/izforge/izpack/rules/RulesEngine.java
Log:
Added pack conditions to PacksPanel base implementation
Modified: izpack-src/trunk/Versions.txt
===================================================================
--- izpack-src/trunk/Versions.txt 2007-01-09 11:54:51 UTC (rev 1698)
+++ izpack-src/trunk/Versions.txt 2007-01-10 12:57:20 UTC (rev 1699)
@@ -45,6 +45,7 @@
- PathInputPanel: logged a stacktrace on Linux systems when no defaultInstallDir was specified and
no TargetPanel.dir.x resource was present (Stefan Wachter via Julien Ponge)
- Added MultiVolumePackager, MultiVolumeUnpacker, MultiVolumeInstaller to support splitting the installer (Dennis Reil)
+- Added conditions for packs to PacksPanel (Dennis Reil)
> 3.9.0 (build 2006.09.25)
- Fix NullPointerException in CompilerConfig, if you specify a
Modified: izpack-src/trunk/src/lib/com/izforge/izpack/panels/PacksModel.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/panels/PacksModel.java 2007-01-09 11:54:51 UTC (rev 1698)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/panels/PacksModel.java 2007-01-10 12:57:20 UTC (rev 1699)
@@ -26,11 +26,15 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import javax.swing.table.AbstractTableModel;
import com.izforge.izpack.LocaleDatabase;
import com.izforge.izpack.Pack;
+import com.izforge.izpack.installer.InstallData;
+import com.izforge.izpack.rules.RulesEngine;
+import com.izforge.izpack.util.Debug;
/**
* User: Gaganis Giorgos Date: Sep 17, 2004 Time: 8:33:21 AM
@@ -60,9 +64,22 @@
// Map to hold the object name relationship
Map namesPos;
+ // reference to the RulesEngine for validating conditions
+ private RulesEngine rules;
+
+ // reference to the current variables, needed for condition validation
+ private Properties variables;
+
+ public PacksModel(PacksPanelInterface panel, InstallData idata, RulesEngine rules)
+ {
+ this(idata.allPacks, idata.selectedPacks, panel);
+ this.rules = rules;
+ this.variables = idata.getVariables();
+ this.updateConditions(true);
+ }
+
public PacksModel(List packs, List packsToInstall, PacksPanelInterface panel)
{
-
this.packs = packs;
this.packsToInstall = packsToInstall;
this.panel = panel;
@@ -72,6 +89,45 @@
initvalues();
}
+ public void updateConditions()
+ {
+ this.updateConditions(false);
+ }
+
+ private void updateConditions(boolean initial)
+ {
+ // look for packages,
+ for (int i = 0; i < packs.size(); i++)
+ {
+ Pack pack = (Pack) packs.get(i);
+ int pos = getPos(pack.name);
+ Debug.trace("Conditions fulfilled for: " + pack.name + "?");
+ if (!this.rules.canInstallPack(pack.id, this.variables))
+ {
+ Debug.trace("no");
+ if (this.rules.canInstallPackOptional(pack.id, this.variables))
+ {
+ Debug.trace("optional");
+ Debug.trace(pack.id + " can be installed optionally.");
+ if (initial)
+ {
+ checkValues[pos] = 0;
+ }
+ else
+ {
+ // just do nothing
+ }
+ }
+ else
+ {
+ Debug.trace(pack.id + " can not be installed.");
+ checkValues[pos] = -2;
+ }
+ }
+ }
+ refreshPacksToInstall();
+ }
+
/**
* Creates the reverse dependency graph
*/
@@ -131,15 +187,15 @@
}
// for mutual exclusion, uncheck uncompatible packs too
// (if available in the current installGroup)
-
- if(checkValues[i] > 0 && pack.excludeGroup != null)
+
+ if (checkValues[i] > 0 && pack.excludeGroup != null)
{
for (int q = 0; q < packs.size(); q++)
{
- if(q != i)
+ if (q != i)
{
Pack otherpack = (Pack) packs.get(q);
- if(pack.excludeGroup.equals(otherpack.excludeGroup))
+ if (pack.excludeGroup.equals(otherpack.excludeGroup))
{
if (checkValues[q] == 1) checkValues[q] = 0;
}
@@ -223,15 +279,15 @@
{
return false;
}
- else return columnIndex == 0;
+ else
+ return columnIndex == 0;
}
/*
* @see TableModel#getValueAt(int, int)
*/
public Object getValueAt(int rowIndex, int columnIndex)
- {
-
+ {
Pack pack = (Pack) packs.get(rowIndex);
switch (columnIndex)
{
@@ -265,25 +321,37 @@
{
if (columnIndex == 0)
{
+ System.out.println("Change value: " + aValue);
if (aValue instanceof Integer)
{
Pack pack = (Pack) packs.get(rowIndex);
+
if (((Integer) aValue).intValue() == 1)
{
- checkValues[rowIndex] = 1;
+ String packid = pack.id;
+ if (packid != null){
+ System.out.println("packid="+packid);
+ if (this.rules.canInstallPack(packid, this.variables) || this.rules.canInstallPackOptional(packid, this.variables)){
+ System.out.println("can install");
+ checkValues[rowIndex] = 1;
+ }
+ }
+ else {
+ checkValues[rowIndex] = 1;
+ }
updateExcludes(rowIndex);
updateDeps();
-
+ this.updateConditions();
int bytes = panel.getBytes();
bytes += pack.nbytes;
panel.setBytes(bytes);
- }
+ }
else
{
checkValues[rowIndex] = 0;
updateExcludes(rowIndex);
updateDeps();
-
+ this.updateConditions();
int bytes = panel.getBytes();
bytes -= pack.nbytes;
panel.setBytes(bytes);
@@ -301,8 +369,17 @@
packsToInstall.clear();
for (int i = 0; i < packs.size(); i++)
{
- Object pack = packs.get(i);
- if (Math.abs(checkValues[i]) == 1) packsToInstall.add(pack);
+ Pack pack = (Pack) packs.get(i);
+ if (Math.abs(checkValues[i]) == 1) {
+ String packid = pack.id;
+
+ if ((packid != null) && (this.rules != null) && (this.rules.canInstallPack(packid, this.variables) || this.rules.canInstallPackOptional(packid, this.variables))){
+ packsToInstall.add(pack);
+ }
+ else {
+ packsToInstall.add(pack);
+ }
+ }
}
@@ -334,49 +411,58 @@
for (int i = 0; i < packs.size(); i++)
{
Pack pack = (Pack) packs.get(i);
- if (pack.required == true) propRequirement(pack.name);
+ if (pack.required == true){
+ String packid = pack.id;
+ if (packid != null){
+ if (!(!this.rules.canInstallPack(packid, this.variables) && this.rules.canInstallPackOptional(packid, this.variables))){
+ propRequirement(pack.name);
+ }
+ }
+ }
}
}
+
/*
* Sees which packs (if any) should be unchecked and updates checkValues
*/
private void updateExcludes(int rowindex)
{
- int value = checkValues [rowindex];
+ int value = checkValues[rowindex];
Pack pack = (Pack) packs.get(rowindex);
- if( value > 0 && pack.excludeGroup != null)
+ if (value > 0 && pack.excludeGroup != null)
{
- for( int q = 0; q < packs.size(); q++)
+ for (int q = 0; q < packs.size(); q++)
{
- if( rowindex != q )
+ if (rowindex != q)
{
- Pack otherpack = (Pack)packs.get(q);
+ Pack otherpack = (Pack) packs.get(q);
String name1 = otherpack.excludeGroup;
String name2 = pack.excludeGroup;
- if( name2.equals(name1) )
+ if (name2.equals(name1))
{
- if( checkValues [q] == 1) checkValues [q] = 0;
+ if (checkValues[q] == 1) checkValues[q] = 0;
}
}
}
}
this.UpdateBytes();
}
-
+
private void UpdateBytes()
{
int bytes = 0;
- for(int q=0; q<packs.size(); q++)
+ for (int q = 0; q < packs.size(); q++)
{
- if(Math.abs(checkValues[q]) == 1)
+ if (Math.abs(checkValues[q]) == 1)
{
- Pack pack = (Pack)packs.get(q);
+ Pack pack = (Pack) packs.get(q);
bytes += pack.nbytes;
}
}
panel.setBytes(bytes);
}
+
/**
* We use a modified dfs graph search algorithm as described in: Thomas H. Cormen, Charles
* Leiserson, Ronald Rivest and Clifford Stein. Introduction to algorithms 2nd Edition
Modified: izpack-src/trunk/src/lib/com/izforge/izpack/panels/PacksPanelBase.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/panels/PacksPanelBase.java 2007-01-09 11:54:51 UTC (rev 1698)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/panels/PacksPanelBase.java 2007-01-10 12:57:20 UTC (rev 1699)
@@ -7,6 +7,7 @@
* Copyright 2002 Marcus Wolschon
* Copyright 2002 Jan Blok
* Copyright 2004 Klaus Bartz
+ * Copyright 2007 Dennis Reil
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -74,9 +75,10 @@
* panels together. This class handles the common logic of pack selection. The derived class should
* be create the layout and other specific actions. There are some helper methods to simplify layout
* creation in the derived class.
- *
+ *
* @author Julien Ponge
* @author Klaus Bartz
+ * @author Dennis Reil
*/
public abstract class PacksPanelBase extends IzPanel implements PacksPanelInterface,
ListSelectionListener
@@ -146,9 +148,9 @@
/**
* The constructor.
- *
+ *
* @param parent The parent window.
- * @param idata The installation data.
+ * @param idata The installation data.
*/
public PacksPanelBase(InstallerFrame parent, InstallData idata)
{
@@ -226,11 +228,9 @@
{
String msg = null;
freeBytes = IoHelper.getFreeSpace(IoHelper.existingParent(
- new
- File(idata.getInstallPath())).getAbsolutePath());
+ new File(idata.getInstallPath())).getAbsolutePath());
if (freeBytes < 0)
- msg =
- parent.langpack.getString("PacksPanel.notAscertainable");
+ msg = parent.langpack.getString("PacksPanel.notAscertainable");
else
msg = Pack.toByteUnitsString(freeBytes);
freeSpaceLabel.setText(msg);
@@ -239,7 +239,7 @@
/**
* Indicates wether the panel has been validated or not.
- *
+ *
* @return true if the needed space is less than the free space, else false
*/
public boolean isValidated()
@@ -256,7 +256,7 @@
/**
* Asks to make the XML panel data.
- *
+ *
* @param panelRoot The XML tree to write the data in.
*/
public void makeXMLData(XMLElement panelRoot)
@@ -270,9 +270,9 @@
* @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
*/
public void valueChanged(ListSelectionEvent e)
- {
- VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
-
+ {
+ VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables());
+
int i = packsTable.getSelectedRow();
if (i < 0) return;
// Operations for the description
@@ -298,9 +298,10 @@
Pack pack = (Pack) idata.availablePacks.get(i);
List dep = pack.dependencies;
String list = "";
- if(dep != null )
+ if (dep != null)
{
- list += ( langpack == null ) ? "Dependencies: " : langpack.getString("PacksPanel.dependencies");
+ list += (langpack == null) ? "Dependencies: " : langpack
+ .getString("PacksPanel.dependencies");
}
for (int j = 0; dep != null && j < dep.size(); j++)
{
@@ -308,41 +309,42 @@
list += getI18NPackName((Pack) names.get(name));
if (j != dep.size() - 1) list += ", ";
}
-
- //add the list of the packs to be excluded
- String excludeslist = (langpack == null) ?"Excludes: " : langpack.getString("PacksPanel.excludes");
+
+ // add the list of the packs to be excluded
+ String excludeslist = (langpack == null) ? "Excludes: " : langpack
+ .getString("PacksPanel.excludes");
int numexcludes = 0;
- if(pack.excludeGroup != null)
+ if (pack.excludeGroup != null)
{
- for(int q=0; q<idata.availablePacks.size(); q++)
+ for (int q = 0; q < idata.availablePacks.size(); q++)
{
Pack otherpack = (Pack) idata.availablePacks.get(q);
String exgroup = otherpack.excludeGroup;
- if(exgroup != null)
+ if (exgroup != null)
{
- if( q != i && pack.excludeGroup.equals(exgroup))
+ if (q != i && pack.excludeGroup.equals(exgroup))
{
-
+
excludeslist += getI18NPackName(otherpack) + ", ";
- numexcludes ++;
+ numexcludes++;
}
}
}
}
- //concatenate
- if(dep != null) excludeslist = " " + excludeslist;
- if(numexcludes > 0) list += excludeslist;
- if(list.endsWith(", ")) list = list.substring(0, list.length()-2);
-
- //and display the result
+ // concatenate
+ if (dep != null) excludeslist = " " + excludeslist;
+ if (numexcludes > 0) list += excludeslist;
+ if (list.endsWith(", ")) list = list.substring(0, list.length() - 2);
+
+ // and display the result
dependencyArea.setText(list);
}
}
/**
- * This method tries to resolve the localized name of the given pack.
- * If this is not possible, the name given in the installation description
- * file in ELEMENT <pack> will be used.
+ * This method tries to resolve the localized name of the given pack. If this is not possible,
+ * the name given in the installation description file in ELEMENT <pack> will be used.
+ *
* @param pack for which the name should be resolved
* @return localized name of the pack
*/
@@ -359,22 +361,23 @@
{
packName = pack.name;
}
- return( packName );
+ return (packName);
}
+
/**
* Layout helper method:<br>
* Creates an label with a message given by msgId and an icon given by the iconId. If layout and
* constraints are not null, the label will be added to layout with the given constraints. The
* label will be added to this object.
- *
- * @param msgId identifier for the IzPack langpack
- * @param iconId identifier for the IzPack icons
- * @param layout layout to be used
+ *
+ * @param msgId identifier for the IzPack langpack
+ * @param iconId identifier for the IzPack icons
+ * @param layout layout to be used
* @param constraints constraints to be used
* @return the created label
*/
protected JLabel createLabel(String msgId, String iconId, GridBagLayout layout,
- GridBagConstraints constraints)
+ GridBagConstraints constraints)
{
JLabel label = LabelFactory.create(parent.langpack.getString(msgId), parent.icons
.getImageIcon(iconId), TRAILING);
@@ -388,14 +391,14 @@
* and a label on the right side with initial no text. The right label will be returned. If
* layout and constraints are not null, the label will be added to layout with the given
* constraints. The panel will be added to this object.
- *
- * @param msgId identifier for the IzPack langpack
- * @param layout layout to be used
+ *
+ * @param msgId identifier for the IzPack langpack
+ * @param layout layout to be used
* @param constraints constraints to be used
* @return the created (right) label
*/
protected JLabel createPanelWithLabel(String msgId, GridBagLayout layout,
- GridBagConstraints constraints)
+ GridBagConstraints constraints)
{
JPanel panel = new JPanel();
JLabel label = new JLabel();
@@ -416,18 +419,18 @@
* else the text area will be added directly to this object. If layout and constraints are not
* null, the text area or scroller will be added to layout with the given constraints. The text
* area will be returned.
- *
- * @param msgId identifier for the IzPack langpack
- * @param scroller the scroller to be used
- * @param layout layout to be used
+ *
+ * @param msgId identifier for the IzPack langpack
+ * @param scroller the scroller to be used
+ * @param layout layout to be used
* @param constraints constraints to be used
* @return the created text area
*/
protected JTextArea createTextArea(String msgId, JScrollPane scroller, GridBagLayout layout,
- GridBagConstraints constraints)
+ GridBagConstraints constraints)
{
JTextArea area = new JTextArea();
- //area.setMargin(new Insets(2, 2, 2, 2));
+ // area.setMargin(new Insets(2, 2, 2, 2));
area.setAlignmentX(LEFT_ALIGNMENT);
area.setCaretPosition(0);
area.setEditable(false);
@@ -460,15 +463,15 @@
/**
* Creates the table for the packs. All parameters are required. The table will be returned.
- *
- * @param width of the table
- * @param scroller the scroller to be used
- * @param layout layout to be used
+ *
+ * @param width of the table
+ * @param scroller the scroller to be used
+ * @param layout layout to be used
* @param constraints constraints to be used
* @return the created table
*/
protected JTable createPacksTable(int width, JScrollPane scroller, GridBagLayout layout,
- GridBagConstraints constraints)
+ GridBagConstraints constraints)
{
JTable table = new JTable();
@@ -491,7 +494,7 @@
/**
* Computes pack related data like the names or the dependencies state.
- *
+ *
* @param packs
*/
private void computePacks(List packs)
@@ -514,44 +517,17 @@
{
try
{
- packsTable.setModel(new PacksModel(idata.availablePacks, idata.selectedPacks, this));
+
+ packsTable.setModel(new PacksModel(this, idata, this.parent.getRules()));
CheckBoxEditorRenderer packSelectedRenderer = new CheckBoxEditorRenderer(false);
packsTable.getColumnModel().getColumn(0).setCellRenderer(packSelectedRenderer);
CheckBoxEditorRenderer packSelectedEditor = new CheckBoxEditorRenderer(true);
packsTable.getColumnModel().getColumn(0).setCellEditor(packSelectedEditor);
packsTable.getColumnModel().getColumn(0).setMaxWidth(40);
- DefaultTableCellRenderer renderer1 = new DefaultTableCellRenderer()
- {
-
- /**
- *
- */
- private static final long serialVersionUID = 3256438101604710708L;
-
- public void setBorder(Border b)
- {
- // TODO: border support?
- }
- };
- packsTable.getColumnModel().getColumn(1).setCellRenderer(renderer1);
- DefaultTableCellRenderer renderer2 = new DefaultTableCellRenderer()
- {
-
- /**
- *
- */
- private static final long serialVersionUID = 4121128130480976185L;
-
- public void setBorder(Border b)
- {
- // TODO: border support?
- }
-
- // public void setFont(Font f)
- // {
- // super.setFont(new Font("Monospaced",Font.PLAIN,11));
- // }
- };
+
+ //packsTable.getColumnModel().getColumn(1).setCellRenderer(renderer1);
+ packsTable.getColumnModel().getColumn(1).setCellRenderer(new PacksPanelTableCellRenderer());
+ PacksPanelTableCellRenderer renderer2 = new PacksPanelTableCellRenderer();
renderer2.setHorizontalAlignment(RIGHT);
packsTable.getColumnModel().getColumn(2).setCellRenderer(renderer2);
packsTable.getColumnModel().getColumn(2).setMaxWidth(100);
@@ -624,8 +600,9 @@
private JCheckBox display;
/**
- * Creates a check box renderer. If useAsEditor is set,
- * an action listener will be added, else not.
+ * Creates a check box renderer. If useAsEditor is set, an action listener will be added,
+ * else not.
+ *
* @param useAsEditor
*/
public CheckBoxEditorRenderer(boolean useAsEditor)
@@ -637,7 +614,7 @@
}
public Component getTableCellRendererComponent(JTable table, Object value,
- boolean isSelected, boolean hasFocus, int row, int column)
+ boolean isSelected, boolean hasFocus, int row, int column)
{
if (isSelected)
{
@@ -650,6 +627,11 @@
display.setBackground(table.getBackground());
}
int state = ((Integer) value).intValue();
+ if (state == -2)
+ {
+ // condition not fulfilled
+ display.setForeground(Color.GRAY);
+ }
display.setSelected((value != null && Math.abs(state) == 1));
display.setEnabled(state >= 0);
return display;
@@ -657,10 +639,10 @@
/**
* @see javax.swing.table.TableCellEditor#getTableCellEditorComponent(javax.swing.JTable,
- * Object, boolean, int, int)
+ * Object, boolean, int, int)
*/
public Component getTableCellEditorComponent(JTable table, Object value,
- boolean isSelected, int row, int column)
+ boolean isSelected, int row, int column)
{
return getTableCellRendererComponent(table, value, isSelected, false, row, column);
}
@@ -676,4 +658,41 @@
}
}
+ static class PacksPanelTableCellRenderer extends DefaultTableCellRenderer
+ {
+
+
+ public Component getTableCellRendererComponent(JTable table, Object value,
+ boolean isSelected, boolean hasFocus, int row, int column)
+ {
+ Component renderer = super.getTableCellRendererComponent(table, value, isSelected, hasFocus,row, column);
+
+ int state = ((Integer) table.getModel().getValueAt(row, 0)).intValue();
+ if (state == -2)
+ {
+ // condition not fulfilled
+ renderer.setForeground(Color.GRAY);
+ if (isSelected){
+ renderer.setBackground(table.getSelectionBackground());
+ }
+ else {
+ renderer.setBackground(table.getBackground());
+ }
+ }
+ else {
+ if (isSelected){
+ renderer.setForeground(table.getSelectionForeground());
+ renderer.setBackground(table.getSelectionBackground());
+ }
+ else {
+ renderer.setForeground(table.getForeground());
+ renderer.setBackground(table.getBackground());
+ }
+ }
+
+ return renderer;
+ }
+
+ }
+
}
Modified: izpack-src/trunk/src/lib/com/izforge/izpack/rules/RulesEngine.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/rules/RulesEngine.java 2007-01-09 11:54:51 UTC (rev 1698)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/rules/RulesEngine.java 2007-01-10 12:57:20 UTC (rev 1699)
@@ -193,6 +193,9 @@
* false - there is a condition and the condition was not met
*/
public boolean canInstallPack(String packid, Properties variables) {
+ if (packid == null){
+ return true;
+ }
Debug.trace("can install pack with id " + packid + "?");
if (!this.packconditions.containsKey(packid)) {
Debug.trace("no condition, can install pack");
More information about the izpack-changes
mailing list