Index: src/lib/com/izforge/izpack/panels/InstallationGroupPanel.java =================================================================== --- src/lib/com/izforge/izpack/panels/InstallationGroupPanel.java (revision 2776) +++ src/lib/com/izforge/izpack/panels/InstallationGroupPanel.java (working copy) @@ -18,27 +18,42 @@ */ package com.izforge.izpack.panels; -import com.izforge.izpack.Pack; -import com.izforge.izpack.installer.InstallData; -import com.izforge.izpack.installer.InstallerFrame; -import com.izforge.izpack.installer.IzPanel; -import com.izforge.izpack.util.AbstractUIHandler; -import com.izforge.izpack.util.Debug; -import com.izforge.izpack.util.OsConstraint; -import com.izforge.izpack.adaptator.IXMLElement; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; -import javax.swing.*; +import javax.swing.BorderFactory; +import javax.swing.ButtonGroup; +import javax.swing.JRadioButton; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextPane; +import javax.swing.ListSelectionModel; +import javax.swing.SwingConstants; import javax.swing.border.EmptyBorder; import javax.swing.border.TitledBorder; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import javax.swing.table.*; -import java.awt.*; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.*; -import java.util.List; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumnModel; +import javax.swing.table.TableModel; +import com.izforge.izpack.adaptator.IXMLElement; +import com.izforge.izpack.installer.InstallData; +import com.izforge.izpack.installer.InstallerFrame; +import com.izforge.izpack.installer.IzPanel; +import com.izforge.izpack.util.AbstractUIHandler; +import com.izforge.izpack.util.Debug; + /** * A panel which displays the available installGroups found on the packs to @@ -53,17 +68,20 @@ implements ListSelectionListener { private static final long serialVersionUID = 1L; + + /** * HashMap of the InstallData.availablePacks */ - private HashMap packsByName; private TableModel groupTableModel; private JTextPane descriptionField; private JScrollPane groupScrollPane; private JTable groupsTable; - private GroupData[] rows; + private InstallationGroupPanelUtil.GroupData[] rows; private int selectedGroup = -1; + + private InstallationGroupPanelUtil util = new InstallationGroupPanelUtil(); public InstallationGroupPanel(InstallerFrame parent, InstallData idata) { @@ -77,19 +95,18 @@ */ public void panelActivate() { - // Set/restore availablePacks from allPacks; consider OS constraints - idata.availablePacks = new ArrayList(); - for (Pack p : idata.allPacks) - { - if (OsConstraint.oneMatchesCurrentSystem(p.osConstraints)) - { - idata.availablePacks.add(p); - } - } - + Debug.trace("InstallationGroupPanel.panelActivate, selectedGroup=" + selectedGroup); // If there are no groups, skip this panel - HashMap installGroups = getInstallGroups(idata); + HashMap installGroups=null; + try + { + installGroups = util.getInstallGroups(idata); + } + catch (UnsupportedEncodingException e) + { + emitWarning("Problem converting value", e.getMessage()); + } if (installGroups.size() == 0) { super.askQuestion("Skip InstallGroup selection", @@ -174,7 +191,7 @@ if (selectedGroup >= 0) { removeUnusedPacks(); - GroupData group = this.rows[selectedGroup]; + InstallationGroupPanelUtil.GroupData group = this.rows[selectedGroup]; idata.setVariable("INSTALL_GROUP", group.name); Debug.trace("Added variable INSTALL_GROUP=" + group.name); } @@ -211,7 +228,7 @@ selectedGroup = lsm.getMinSelectionIndex(); if (selectedGroup >= 0) { - GroupData data = rows[selectedGroup]; + InstallationGroupPanelUtil.GroupData data = rows[selectedGroup]; descriptionField.setText(data.description); ((JRadioButton) groupTableModel.getValueAt(selectedGroup, 0)).setSelected(true); } @@ -225,11 +242,8 @@ */ public void makeXMLData(IXMLElement panelRoot) { - InstallationGroupPanelAutomationHelper helper = new InstallationGroupPanelAutomationHelper(); - idata.setAttribute("GroupData", rows); - idata.setAttribute("packsByName", packsByName); - helper.makeXMLData(idata, panelRoot); - } + util.makeXMLData(panelRoot, idata, rows); + } /** * Create the panel ui. @@ -271,262 +285,12 @@ protected void removeUnusedPacks() { - GroupData data = rows[selectedGroup]; - Debug.trace("InstallationGroupPanel.removeUnusedPacks, GroupData=" + data.name); - - // Now remove the packs not in groupPackNames - Iterator iter = idata.availablePacks.iterator(); - while (iter.hasNext()) - { - Pack p = (Pack) iter.next(); - - //reverse dependencies must be reset in case the user is going - //back and forth between the group selection panel and the packs selection panel - p.revDependencies = null; - - if (!data.packNames.contains(p.name)) - { - iter.remove(); - Debug.trace("Removed AvailablePack: " + p.name); - } - } - - idata.selectedPacks.clear(); - if (!"no".equals(idata.getVariable("InstallationGroupPanel.selectPacks"))) - { - idata.selectedPacks.addAll(idata.availablePacks); - } - else - { - for (Object availablePack : idata.availablePacks) - { - Pack p = (Pack) availablePack; - if (p.preselected) - { - idata.selectedPacks.add(p); - } - } - } - } - - protected void addDependents(Pack p, HashMap packsByName, GroupData data) - { - data.packNames.add(p.name); - data.size += p.nbytes; - Debug.trace("addDependents, added pack: " + p.name); - if (p.dependencies == null || p.dependencies.size() == 0) - { - return; - } - - Iterator iter = p.dependencies.iterator(); - Debug.trace(p.name + " dependencies: " + p.dependencies); - while (iter.hasNext()) - { - String dependent = iter.next(); - if (!data.packNames.contains(dependent)) - { - Debug.trace("Need dependent: " + dependent); - Pack dependentPack = packsByName.get(dependent); - addDependents(dependentPack, packsByName, data); - } - } - } - - /** - * Build the set of unique installGroups data. The GroupData description - * is taken from the InstallationGroupPanel.description.[name] property - * where [name] is the installGroup name. The GroupData size is built - * from the Pack.nbytes sum. - * - * @param idata - the panel install data - * @return HashMap of unique install group names - */ - protected HashMap getInstallGroups(InstallData idata) - { - /* First create a packsByName of all packs and identify - the unique install group names. - */ - packsByName = new HashMap(); - HashMap installGroups = new HashMap(); - for (int n = 0; n < idata.availablePacks.size(); n++) - { - Pack p = (Pack) idata.availablePacks.get(n); - packsByName.put(p.name, p); - Set groups = p.installGroups; - Iterator iter = groups.iterator(); - Debug.trace("Pack: " + p.name + ", installGroups: " + groups); - while (iter.hasNext()) - { - String group = iter.next(); - GroupData data = (GroupData) installGroups.get(group); - if (data == null) - { - String description = getGroupDescription(group); - String sortKey = getGroupSortKey(group); - data = new GroupData(group, description, sortKey); - installGroups.put(group, data); - } - } - } - Debug.trace("Found installGroups: " + installGroups.keySet()); - - /* Build up a set of the packs to include in the installation by finding - all packs in the selected group, and then include their dependencies. - */ - Iterator gditer = installGroups.values().iterator(); - while (gditer.hasNext()) - { - GroupData data = (GroupData) gditer.next(); - Debug.trace("Adding dependents for: " + data.name); - Iterator iter = idata.availablePacks.iterator(); - while (iter.hasNext()) - { - Pack p = (Pack) iter.next(); - Set groups = p.installGroups; - if (groups.size() == 0 || groups.contains(data.name)) - { - // The pack may have already been added while traversing dependencies - if (!data.packNames.contains(p.name)) - { - addDependents(p, packsByName, data); - } - } - } - Debug.trace("Completed dependents for: " + data); - if (Debug.tracing()) - { - Debug.trace(data); - } - } - - return installGroups; - } - - /** - * Look for a key = InstallationGroupPanel.description.[group] entry: - * first using idata.langpack.getString(key+".html") - * next using idata.langpack.getString(key) - * next using idata.getVariable(key) - * lastly, defaulting to group + " installation" - * - * @param group - the installation group name - * @return the group description - */ - protected String getGroupDescription(String group) - { - String description = null; - String key = "InstallationGroupPanel.description." + group; - if (idata.langpack != null) - { - String htmlKey = key + ".html"; - String html = idata.langpack.getString(htmlKey); - // This will equal the key if there is no entry - if (htmlKey.equalsIgnoreCase(html)) - { - description = idata.langpack.getString(key); - } - else - { - description = html; - } - } - if (description == null || key.equalsIgnoreCase(description)) - { - description = idata.getVariable(key); - } - if (description == null) - { - description = group + " installation"; - } - try - { - description = URLDecoder.decode(description, "UTF-8"); - } - catch (UnsupportedEncodingException e) - { - emitWarning("Failed to convert description", e.getMessage()); - } - - return description; + + InstallationGroupPanelUtil.GroupData data = rows[selectedGroup]; + util.removeUnusedPacks(idata, data); + } - /** - * Look for a key = InstallationGroupPanel.sortKey.[group] entry: - * by using idata.getVariable(key) - * if this variable is not defined, defaults to group - * - * @param group - the installation group name - * @return the group sortkey - */ - protected String getGroupSortKey(String group) - { - String key = "InstallationGroupPanel.sortKey." + group; - String sortKey = idata.getVariable(key); - if (sortKey == null) - { - sortKey = group; - } - try - { - sortKey = URLDecoder.decode(sortKey, "UTF-8"); - } - catch (UnsupportedEncodingException e) - { - emitWarning("Failed to convert sortKey", e.getMessage()); - } - - return sortKey; - } - - - /** - * Look for a key = InstallationGroupPanel.group.[group] entry: - * first using idata.langpackgetString(key+".html") - * next using idata.langpack.getString(key) - * next using idata.getVariable(key) - * lastly, defaulting to group - * - * @param group - the installation group name - * @return the localized group name - */ - protected String getLocalizedGroupName(String group) - { - String gname = null; - String key = "InstallationGroupPanel.group." + group; - if (idata.langpack != null) - { - String htmlKey = key + ".html"; - String html = idata.langpack.getString(htmlKey); - // This will equal the key if there is no entry - if (htmlKey.equalsIgnoreCase(html)) - { - gname = idata.langpack.getString(key); - } - else - { - gname = html; - } - } - if (gname == null || key.equalsIgnoreCase(gname)) - { - gname = idata.getVariable(key); - } - if (gname == null) - { - gname = group; - } - try - { - gname = URLDecoder.decode(gname, "UTF-8"); - } - catch (UnsupportedEncodingException e) - { - emitWarning("Failed to convert localized group name", e.getMessage()); - } - - return gname; - } protected TableModel getModel(HashMap groupData) { @@ -541,26 +305,13 @@ return false; } }; - rows = new GroupData[groupData.size()]; + rows = new InstallationGroupPanelUtil.GroupData[groupData.size()]; // The name of the group to select if there is no current selection String defaultGroup = idata.getVariable("InstallationGroupPanel.defaultGroup"); Debug.trace("InstallationGroupPanel.defaultGroup=" + defaultGroup + ", selectedGroup=" + selectedGroup); + List values = new ArrayList(groupData.values()); - Collections.sort(values, new Comparator() - { - public int compare(Object o1, Object o2) - { - GroupData g1 = (GroupData) o1; - GroupData g2 = (GroupData) o2; - - if (g1.sortKey == null || g2.sortKey == null) - { - return 0; - } - - return g1.sortKey.compareTo(g2.sortKey); - } - }); + util.sortGroups(values); Iterator iter = values.iterator(); ButtonGroup buttonGroup = new ButtonGroup(); @@ -568,10 +319,18 @@ int count = 0; while (iter.hasNext()) { - GroupData gd = (GroupData) iter.next(); + InstallationGroupPanelUtil.GroupData gd = (InstallationGroupPanelUtil.GroupData) iter.next(); rows[count] = gd; Debug.trace("Creating button#" + count + ", group=" + gd.name); - JRadioButton btn = new JRadioButton(getLocalizedGroupName(gd.name)); + JRadioButton btn=null; + try + { + btn = new JRadioButton(util.getLocalizedGroupName(gd.name, idata)); + } + catch (UnsupportedEncodingException e) + { + emitWarning("Failed to convert value", e.getMessage()); + } if (selectedGroup == count) { btn.setSelected(true); @@ -611,64 +370,5 @@ return model; } - protected static class GroupData - { - static final long ONEK = 1024; - static final long ONEM = 1024 * 1024; - static final long ONEG = 1024 * 1024 * 1024; - - String name; - String description; - String sortKey; - long size; - HashSet packNames = new HashSet(); - - GroupData(String name, String description, String sortKey) - { - this.name = name; - this.description = description; - this.sortKey = sortKey; - } - - String getSizeString() - { - String s; - if (size < ONEK) - { - s = size + " bytes"; - } - else if (size < ONEM) - { - s = size / ONEK + " KB"; - } - else if (size < ONEG) - { - s = size / ONEM + " MB"; - } - else - { - s = size / ONEG + " GB"; - } - return s; - } - - public String toString() - { - StringBuffer tmp = new StringBuffer("GroupData("); - tmp.append(name); - tmp.append("){description="); - tmp.append(description); - tmp.append(", sortKey="); - tmp.append(sortKey); - tmp.append(", size="); - tmp.append(size); - tmp.append(", sizeString="); - tmp.append(getSizeString()); - tmp.append(", packNames="); - tmp.append(packNames); - tmp.append("}"); - return tmp.toString(); - } - } } Index: src/lib/com/izforge/izpack/panels/InstallationGroupPanelConsoleHelper.java =================================================================== --- src/lib/com/izforge/izpack/panels/InstallationGroupPanelConsoleHelper.java (revision 0) +++ src/lib/com/izforge/izpack/panels/InstallationGroupPanelConsoleHelper.java (revision 0) @@ -0,0 +1,163 @@ +/* + * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved. + * + * http://izpack.org/ + * http://izpack.codehaus.org/ + * + * Copyright 2002 Jan Blok + * + * 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. + */ +package com.izforge.izpack.panels; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import com.izforge.izpack.installer.AutomatedInstallData; +import com.izforge.izpack.installer.PanelConsole; +import com.izforge.izpack.installer.PanelConsoleHelper; +import com.izforge.izpack.util.Debug; +/** + * Installation Group Panel console helper + * + */ +public class InstallationGroupPanelConsoleHelper extends PanelConsoleHelper implements PanelConsole +{ + + private InstallationGroupPanelUtil util = new InstallationGroupPanelUtil(); + + + public boolean runGeneratePropertiesFile(AutomatedInstallData installData,PrintWriter printWriter) + { + return true; + } + + public boolean runConsoleFromPropertiesFile(AutomatedInstallData installData, Properties p) + { + return true; + } + + public boolean runConsole(AutomatedInstallData idata) + { + Map groups = null; + try + { + groups = util.getInstallGroups(idata); + } + catch (UnsupportedEncodingException e) + { + System.out.println("Problem converting value, msg: "+ e.getMessage()); + } + + if (groups == null || groups.size() == 0) + { + Debug.trace("No installation group choices were defined"); + return true; + } + + processGroupChoices(groups, idata); + + return true; + + } + + + boolean processGroupChoices(Map groups, AutomatedInstallData idata) + { + System.out.println("Select Installation option:"); + + List values = new ArrayList(groups.values()); + util.sortGroups(values); + + boolean anypreselected = false; + int selectedChoice = -1; + + int i = 0; + Map choiceMap = new HashMap(values.size()); + Iterator groupIterator = values.iterator(); + while (groupIterator.hasNext()) { + InstallationGroupPanelUtil.GroupData group = groupIterator.next(); + + System.out.println(i + " [" + (group.preselected? "x" : " ") + "] " + + (group.name != null ? group.name : "")); + + if (group.preselected) { + anypreselected = true; + selectedChoice = i; + } + + choiceMap.put(String.valueOf(i), group); + i++; + } + + + try + { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + boolean bKeepAsking = true; + + while (bKeepAsking) + { + if (selectedChoice < 0) { + System.out.println("input selection:"); + } else { + System.out.println("input selection [" + selectedChoice + "]:"); + } + String strIn = br.readLine(); + // take default value if default value exists and no user input + if (strIn.trim().equals("") && anypreselected) + { + bKeepAsking = false; + continue; + } + int j = -1; + try + { + j = Integer.valueOf(strIn).intValue(); + } + catch (Exception ex) + {} + // take user input if user input is valid + if (j >= 0 && j < values.size()) + { + selectedChoice = j; + bKeepAsking = false; + } + } + } + catch (IOException e) + { + e.printStackTrace(); + return false; + } + + + Debug.trace("Installation group choice selected was " + choiceMap.get(String.valueOf(selectedChoice)).name ); + + idata.setVariable("INSTALL_GROUP", choiceMap.get(String.valueOf(selectedChoice)).name); + + return true; + + } + + +} Index: src/lib/com/izforge/izpack/panels/InstallationGroupPanelAutomationHelper.java =================================================================== --- src/lib/com/izforge/izpack/panels/InstallationGroupPanelAutomationHelper.java (revision 2776) +++ src/lib/com/izforge/izpack/panels/InstallationGroupPanelAutomationHelper.java (working copy) @@ -23,7 +23,6 @@ import com.izforge.izpack.Pack; import com.izforge.izpack.installer.AutomatedInstallData; import com.izforge.izpack.installer.PanelAutomation; -import com.izforge.izpack.panels.InstallationGroupPanel.GroupData; import com.izforge.izpack.util.Debug; import com.izforge.izpack.adaptator.IXMLElement; import com.izforge.izpack.adaptator.impl.XMLElementImpl; @@ -46,10 +45,10 @@ */ public void makeXMLData(AutomatedInstallData idata, IXMLElement panelRoot) { - GroupData[] rows = (GroupData[]) idata.getAttribute("GroupData"); + InstallationGroupPanelUtil.GroupData[] rows = (InstallationGroupPanelUtil.GroupData[]) idata.getAttribute("GroupData"); HashMap packsByName = (HashMap) idata.getAttribute("packsByName"); // Write out the group to pack mappings - for (GroupData gd : rows) + for (InstallationGroupPanelUtil.GroupData gd : rows) { IXMLElement xgroup = new XMLElementImpl("group",panelRoot); xgroup.setAttribute("name", gd.name); Index: src/lib/com/izforge/izpack/panels/InstallationGroupPanelUtil.java =================================================================== --- src/lib/com/izforge/izpack/panels/InstallationGroupPanelUtil.java (revision 0) +++ src/lib/com/izforge/izpack/panels/InstallationGroupPanelUtil.java (revision 0) @@ -0,0 +1,430 @@ +/* + * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved. + * + * http://izpack.org/ + * http://izpack.codehaus.org/ + * + * 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. + */ +package com.izforge.izpack.panels; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import com.izforge.izpack.Pack; +import com.izforge.izpack.adaptator.IXMLElement; +import com.izforge.izpack.installer.AutomatedInstallData; +import com.izforge.izpack.installer.InstallData; +import com.izforge.izpack.util.Debug; +import com.izforge.izpack.util.OsConstraint; + + +/** + * This utility class is used as common code between the gui installation and the console mode installation. + * + */ +public class InstallationGroupPanelUtil +{ + private static final long serialVersionUID = 1L; + + private HashMap packsByName; + + + /* Add the installation group to pack mappings + * @see com.izforge.izpack.installer.IzPanel#makeXMLData(com.izforge.izpack.adaptator.IXMLElement) + */ + public void makeXMLData(IXMLElement panelRoot, AutomatedInstallData idata, GroupData[] groups ) + { + InstallationGroupPanelAutomationHelper helper = new InstallationGroupPanelAutomationHelper(); + idata.setAttribute("GroupData", groups); + idata.setAttribute("packsByName", packsByName); + helper.makeXMLData(idata, panelRoot); + } + + private void addDependents(Pack p, HashMap packsByName, GroupData data) + { + data.packNames.add(p.name); + data.size += p.nbytes; + Debug.trace("addDependents, added pack: " + p.name); + if (p.dependencies == null || p.dependencies.size() == 0) + { + return; + } + + Iterator iter = p.dependencies.iterator(); + Debug.trace(p.name + " dependencies: " + p.dependencies); + while (iter.hasNext()) + { + String dependent = iter.next(); + if (!data.packNames.contains(dependent)) + { + Debug.trace("Need dependent: " + dependent); + Pack dependentPack = packsByName.get(dependent); + addDependents(dependentPack, packsByName, data); + } + } + } + + public HashMap getPacksByName() { + return this.packsByName; + } + + public HashMap getInstallGroups(AutomatedInstallData idata) throws UnsupportedEncodingException + { + + return getInstallGroupsMap(idata); + + } + + /** + * Build the set of unique installGroups data. The GroupData description + * is taken from the InstallationGroupPanel.description.[name] property + * where [name] is the installGroup name. The GroupData size is built + * from the Pack.nbytes sum. + * + * @param idata - the panel install data + * @return HashMap of unique install group names + */ + public HashMap getInstallGroups(InstallData idata) throws UnsupportedEncodingException + { + + return getInstallGroupsMap(idata); + + + } + + /** + * Call to sort {@link GroupData GroupData} + * @param values + */ + public void sortGroups(List values) { + + Collections.sort(values, new Comparator() + { + public int compare(final Object o1, final Object o2) + { + final InstallationGroupPanelUtil.GroupData g1 = (InstallationGroupPanelUtil.GroupData) o1; + final InstallationGroupPanelUtil.GroupData g2 = (InstallationGroupPanelUtil.GroupData) o2; + + if (g1.sortKey == null || g2.sortKey == null) + { + return 0; + } + + return g1.sortKey.compareTo(g2.sortKey); + } + }); + } + + + public void removeUnusedPacks(AutomatedInstallData idata, GroupData data) + { + + Debug.trace("InstallationGroupPanel.removeUnusedPacks, GroupData=" + data.name); + + // Now remove the packs not in groupPackNames + Iterator iter = idata.availablePacks.iterator(); + while (iter.hasNext()) + { + Pack p = (Pack) iter.next(); + + //reverse dependencies must be reset in case the user is going + //back and forth between the group selection panel and the packs selection panel + p.revDependencies = null; + + if (!data.packNames.contains(p.name)) + { + iter.remove(); + Debug.trace("Removed AvailablePack: " + p.name); + } + } + + idata.selectedPacks.clear(); + if (!"no".equals(idata.getVariable("InstallationGroupPanel.selectPacks"))) + { + idata.selectedPacks.addAll(idata.availablePacks); + } + else + { + for (Object availablePack : idata.availablePacks) + { + Pack p = (Pack) availablePack; + if (p.preselected) + { + idata.selectedPacks.add(p); + } + } + } + } + + /** + * Build the set of unique installGroups data. The GroupData description + * is taken from the InstallationGroupPanel.description.[name] property + * where [name] is the installGroup name. The GroupData size is built + * from the Pack.nbytes sum. + * + * @param idata - the panel install data + * @return HashMap of unique install group names + */ + private HashMap getInstallGroupsMap(AutomatedInstallData idata) throws UnsupportedEncodingException + { + + // Set/restore availablePacks from allPacks; consider OS constraints + idata.availablePacks = new ArrayList(); + for (Pack p : idata.allPacks) + { + if (OsConstraint.oneMatchesCurrentSystem(p.osConstraints)) + { + idata.availablePacks.add(p); + } + } + /* First create a packsByName of all packs and identify + the unique install group names. + */ + packsByName = new HashMap(); + HashMap installGroups = new HashMap(); + for (int n = 0; n < idata.availablePacks.size(); n++) + { + Pack p = (Pack) idata.availablePacks.get(n); + packsByName.put(p.name, p); + Set groups = p.installGroups; + Iterator iter = groups.iterator(); + Debug.trace("Pack: " + p.name + ", installGroups: " + groups); + while (iter.hasNext()) + { + String group = iter.next(); + GroupData data = (GroupData) installGroups.get(group); + if (data == null) + { + String description = getGroupDescription(group, idata); + String sortKey = getGroupSortKey(group, idata); + data = new GroupData(group, description, sortKey, p.preselected); + installGroups.put(group, data); + } + } + } + Debug.trace("Found installGroups: " + installGroups.keySet()); + + /* Build up a set of the packs to include in the installation by finding + all packs in the selected group, and then include their dependencies. + */ + Iterator gditer = installGroups.values().iterator(); + while (gditer.hasNext()) + { + GroupData data = (GroupData) gditer.next(); + Debug.trace("Adding dependents for: " + data.name); + Iterator iter = idata.availablePacks.iterator(); + while (iter.hasNext()) + { + Pack p = (Pack) iter.next(); + Set groups = p.installGroups; + if (groups.size() == 0 || groups.contains(data.name)) + { + // The pack may have already been added while traversing dependencies + if (!data.packNames.contains(p.name)) + { + addDependents(p, packsByName, data); + } + } + } + Debug.trace("Completed dependents for: " + data); + if (Debug.tracing()) + { + Debug.trace(data); + } + } + + return installGroups; + } + + /** + * Look for a key = InstallationGroupPanel.sortKey.[group] entry: + * by using idata.getVariable(key) + * if this variable is not defined, defaults to group + * + * @param group - the installation group name + * @return the group sortkey + */ + private String getGroupSortKey(String group, AutomatedInstallData idata) throws UnsupportedEncodingException + { + String key = "InstallationGroupPanel.sortKey." + group; + String sortKey = idata.getVariable(key); + if (sortKey == null) + { + sortKey = group; + } + + sortKey = URLDecoder.decode(sortKey, "UTF-8"); + + return sortKey; + } + + + /** + * Look for a key = InstallationGroupPanel.description.[group] entry: + * first using idata.langpack.getString(key+".html") + * next using idata.langpack.getString(key) + * next using idata.getVariable(key) + * lastly, defaulting to group + " installation" + * + * @param group - the installation group name + * @return the group description + */ + private String getGroupDescription(String group, AutomatedInstallData idata) throws UnsupportedEncodingException + { + String description = null; + String key = "InstallationGroupPanel.description." + group; + if (idata.langpack != null) + { + String htmlKey = key + ".html"; + String html = idata.langpack.getString(htmlKey); + // This will equal the key if there is no entry + if (htmlKey.equalsIgnoreCase(html)) + { + description = idata.langpack.getString(key); + } + else + { + description = html; + } + } + if (description == null || key.equalsIgnoreCase(description)) + { + description = idata.getVariable(key); + } + if (description == null) + { + description = group + " installation"; + } + + description = URLDecoder.decode(description, "UTF-8"); + + + return description; + } + + + /** + * Look for a key = InstallationGroupPanel.group.[group] entry: + * first using idata.langpackgetString(key+".html") + * next using idata.langpack.getString(key) + * next using idata.getVariable(key) + * lastly, defaulting to group + * + * @param group - the installation group name + * @return the localized group name + */ + String getLocalizedGroupName(String group, AutomatedInstallData idata) throws UnsupportedEncodingException + { + String gname = null; + String key = "InstallationGroupPanel.group." + group; + if (idata.langpack != null) + { + String htmlKey = key + ".html"; + String html = idata.langpack.getString(htmlKey); + // This will equal the key if there is no entry + if (htmlKey.equalsIgnoreCase(html)) + { + gname = idata.langpack.getString(key); + } + else + { + gname = html; + } + } + if (gname == null || key.equalsIgnoreCase(gname)) + { + gname = idata.getVariable(key); + } + if (gname == null) + { + gname = group; + } + + gname = URLDecoder.decode(gname, "UTF-8"); + + + return gname; + } + + protected static class GroupData + { + static final long ONEK = 1024; + static final long ONEM = 1024 * 1024; + static final long ONEG = 1024 * 1024 * 1024; + + String name; + String description; + String sortKey; + boolean preselected; + long size; + HashSet packNames = new HashSet(); + + GroupData(String name, String description, String sortKey, boolean preselected) + { + this.name = name; + this.description = description; + this.sortKey = sortKey; + this.preselected = preselected; + } + + String getSizeString() + { + String s; + if (size < ONEK) + { + s = size + " bytes"; + } + else if (size < ONEM) + { + s = size / ONEK + " KB"; + } + else if (size < ONEG) + { + s = size / ONEM + " MB"; + } + else + { + s = size / ONEG + " GB"; + } + return s; + } + + public String toString() + { + StringBuffer tmp = new StringBuffer("GroupData("); + tmp.append(name); + tmp.append("){description="); + tmp.append(description); + tmp.append(", sortKey="); + tmp.append(sortKey); + tmp.append(", size="); + tmp.append(size); + tmp.append(", sizeString="); + tmp.append(getSizeString()); + tmp.append(", packNames="); + tmp.append(packNames); + tmp.append("}"); + return tmp.toString(); + } + } + +}