[izpack-changes] r1576 - in izpack-src/trunk: . src src/dist-files src/doc-ng/XHTML src/lib/com/izforge/izpack/panels

noreply at berlios.de noreply at berlios.de
Thu Sep 7 03:04:55 CEST 2006


Author: jponge
Date: 2006-09-07 03:04:39 +0200 (Thu, 07 Sep 2006)
New Revision: 1576

Added:
   izpack-src/trunk/src/lib/com/izforge/izpack/panels/InstallationGroupPanel.java
   izpack-src/trunk/src/lib/com/izforge/izpack/panels/InstallationGroupPanelAutomationHelper.java
Modified:
   izpack-src/trunk/IzPack-head.iml
   izpack-src/trunk/IzPack-head.ipr
   izpack-src/trunk/Versions.txt
   izpack-src/trunk/src/build.xml
   izpack-src/trunk/src/dist-files/IzPack-install.xml
   izpack-src/trunk/src/doc-ng/XHTML/izpack-doc.html
   izpack-src/trunk/src/doc-ng/XHTML/node4.html
Log:
New InstallationGroupPanel for grouping packs together (Amit Bhayani, Scott Starks,  Alex Pinkin @JBoss/RedHat).

Modified: izpack-src/trunk/IzPack-head.iml
===================================================================
--- izpack-src/trunk/IzPack-head.iml	2006-09-06 21:22:14 UTC (rev 1575)
+++ izpack-src/trunk/IzPack-head.iml	2006-09-07 01:04:39 UTC (rev 1576)
@@ -30,7 +30,7 @@
         <SOURCES />
       </library>
     </orderEntry>
-    <orderEntry type="library" name="JUnit" level="application" />
+    <orderEntry type="library" name="Junit" level="application" />
     <orderEntryProperties />
   </component>
 </module>

Modified: izpack-src/trunk/IzPack-head.ipr
===================================================================
--- izpack-src/trunk/IzPack-head.ipr	2006-09-06 21:22:14 UTC (rev 1575)
+++ izpack-src/trunk/IzPack-head.ipr	2006-09-07 01:04:39 UTC (rev 1576)
@@ -188,7 +188,7 @@
       <module fileurl="file://$PROJECT_DIR$/IzPack-head.iml" filepath="$PROJECT_DIR$/IzPack-head.iml" />
     </modules>
   </component>
-  <component name="ProjectRootManager" version="2" assert-keyword="true" jdk-15="false" project-jdk-name="IDEA 4267" />
+  <component name="ProjectRootManager" version="2" assert-keyword="true" jdk-15="false" project-jdk-name="1.5.0_05" />
   <component name="RmicSettings">
     <option name="IS_EANABLED" value="false" />
     <option name="DEBUGGING_INFO" value="true" />

Modified: izpack-src/trunk/Versions.txt
===================================================================
--- izpack-src/trunk/Versions.txt	2006-09-06 21:22:14 UTC (rev 1575)
+++ izpack-src/trunk/Versions.txt	2006-09-07 01:04:39 UTC (rev 1576)
@@ -47,13 +47,15 @@
 - Merged normal installer and registry-enabled installers (Julien Ponge).
 - A potential null pointer exception has been discovered in Unpacker with a
   custom action. (Dennis Reil, via Julien Ponge).
-- implemented  the X-KDE subsitute user - shortcut attribute (see Unix_shortcutSpec.xml) 
+- Implemented the X-KDE subsitute user - shortcut attribute (see Unix_shortcutSpec.xml)
   (Marc Eppelmann).
-- write Desktop shortcuts to all known local and ypbinded users "desktop" folders. 
+- Write Desktop shortcuts to all known local and ypbinded users "desktop" folders.
   (Marc Eppelmann)
-- write common shortcuts and their icons to the new freedesktop.org common 
+- Write common shortcuts and their icons to the new freedesktop.org common
   "/usr/share/applications"   and "/usr/share/pixmaps" folders to display 
   these in the commons [start].menu (Marc Eppelmann)
+- New InstallationGroupPanel for grouping packs together (Amit Bhayani, Scott Starks,
+  Alex Pinkin @JBoss/RedHat).
 
   > 3.8.1 (build 2006.01.06)
 - Added Greek language support (Fabrice Mirabile, thanks to Panayotis

Modified: izpack-src/trunk/src/build.xml
===================================================================
--- izpack-src/trunk/src/build.xml	2006-09-06 21:22:14 UTC (rev 1575)
+++ izpack-src/trunk/src/build.xml	2006-09-07 01:04:39 UTC (rev 1576)
@@ -626,6 +626,10 @@
         <build-panel name="SummaryPanel">
             <include name="com/izforge/izpack/panels/SummaryPanel.java" />
         </build-panel>
+        <build-panel name="InstallationGroupPanel">
+         <include name="com/izforge/izpack/panels/InstallationGroupPanel.java"/>
+         <include name="com/izforge/izpack/panels/InstallationGroupPanelAutomationHelper.java"/>
+        </build-panel>
     </target>
 
     <!-- 

Modified: izpack-src/trunk/src/dist-files/IzPack-install.xml
===================================================================
--- izpack-src/trunk/src/dist-files/IzPack-install.xml	2006-09-06 21:22:14 UTC (rev 1575)
+++ izpack-src/trunk/src/dist-files/IzPack-install.xml	2006-09-07 01:04:39 UTC (rev 1576)
@@ -36,6 +36,8 @@
             <author email="" name="Ryan Shillington (contributor)" />
             <author email="" name="Eric Rose (contributor)" />
             <author email="" name="Amit Bhayani @JBoss/RedHat (contributors)" />
+            <author email="" name="Scott Starks @JBoss/RedHat (contributors)" />
+            <author email="" name="Alex Pinkin @JBoss/RedHat (contributors)" />
             <author email="" name="Dennis Reil (contributor)" />
 
             <author email=""

Modified: izpack-src/trunk/src/doc-ng/XHTML/izpack-doc.html
===================================================================
--- izpack-src/trunk/src/doc-ng/XHTML/izpack-doc.html	2006-09-06 21:22:14 UTC (rev 1575)
+++ izpack-src/trunk/src/doc-ng/XHTML/izpack-doc.html	2006-09-07 01:04:39 UTC (rev 1576)
@@ -50,7 +50,7 @@
       </span> <a name="tex2html2" href="http://www.izforge.com/izpack/"></a><a name="tex2html1" href="http://www.izforge.com/izpack/">http://www.izforge.com/izpack/</a><br />
       <br />
       <br />
-       Edition of August 22, 2005<br />
+       Edition of September 7th, 2006<br />
       <br />
       <br />
     </div>

Modified: izpack-src/trunk/src/doc-ng/XHTML/node4.html
===================================================================
--- izpack-src/trunk/src/doc-ng/XHTML/node4.html	2006-09-06 21:22:14 UTC (rev 1575)
+++ izpack-src/trunk/src/doc-ng/XHTML/node4.html	2006-09-07 01:04:39 UTC (rev 1576)
@@ -162,6 +162,8 @@
 <li><a name="tex2html416" href="node4.html#SECTION004417000000000000000">DataCheckPanel</a></li>
 
 <li><a name="tex2html417" href="node4.html#SECTION004418000000000000000">SummaryPanel</a></li>
+
+<li><a name="tex2html418" href="node4.html#SECTION004419000000000000000">InstallationGroupPanel</a></li>
 </ul>
 </li>
 </ul>
@@ -1301,6 +1303,45 @@
 </p>
 <p>Additional it is possible to <a href="node9.html#SECTION00970000000000000000">log the contents</a> of the summary panel into a HTML file.</p>
 
+<h2><a name="SECTION004419000000000000000">InstallationGroupPanel</a></h2>
+<p> This Panel groups the pack together. A panel which displays the available <em>installGroups</em> found on the packs to
+    allow the user to select a subset of the packs based on the pack <em>installGroups</em> attribute. This panel will be
+    skipped if there are no pack elements with an <em>installGroups</em> attribute. For example
+    <pre>
+    &lt;installation version="1.0"&gt;
+       (...)
+        &lt;panels&gt;
+            (...)
+            &lt;panel classname="InstallationGroupPanel"/&gt;
+            &lt;panel classname="PacksPanel"/&gt;
+            (...)
+        &lt;/panels&gt;
+
+        &lt;packs&gt;
+            &lt;pack name="Base"
+                installGroups="Group1" required="yes"&gt;
+                (...)
+            &lt;/pack&gt;
+            &lt;pack name="Docs"
+                installGroups="Group1,Group2" required="no"&gt;
+                (...)
+            &lt;/pack&gt;
+            &lt;pack name="Sources"
+                installGroups="Group3,Group2" required="no"&gt;
+                (...)
+            &lt;/pack&gt;
+        &lt;/packs&gt;
+    &lt;/installation&gt;
+    </pre>
+
+    In above example when InstallationGroupPanel is displayed, it contains three radios named Group1, Group2 and Group3.
+    Depending on what user selects respective Packs will be displayed in PacksPanel. InstallationGroupPanel will look
+    for description corresponding to key InstallationGroupPanel.description.Group1,
+    InstallationGroupPanel.description.Group2 etc in installation langpacks and displays this description for each of
+    the Group_i.
+
+</p>
+
 <hr />
 <!--Navigation Panel-->
 <table width="100%">

Added: izpack-src/trunk/src/lib/com/izforge/izpack/panels/InstallationGroupPanel.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/panels/InstallationGroupPanel.java	2006-09-06 21:22:14 UTC (rev 1575)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/panels/InstallationGroupPanel.java	2006-09-07 01:04:39 UTC (rev 1576)
@@ -0,0 +1,593 @@
+/*
+ * IzPack - Copyright 2001-2005 Julien Ponge, All Rights Reserved.
+ * 
+ * http://www.izforge.com/izpack/
+ * http://developer.berlios.de/projects/izpack/
+ * 
+ * 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.awt.Component;
+import java.awt.Dimension;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.List;
+import java.util.HashSet;
+
+import javax.swing.AbstractCellEditor;
+import javax.swing.BorderFactory;
+import javax.swing.ButtonGroup;
+import javax.swing.JRadioButton;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
+import javax.swing.JTextPane;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.TitledBorder;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.table.DefaultTableModel;
+import javax.swing.table.TableCellEditor;
+import javax.swing.table.TableCellRenderer;
+import javax.swing.table.TableColumnModel;
+import javax.swing.table.TableModel;
+
+import net.n3.nanoxml.XMLElement;
+
+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.Debug;
+import com.izforge.izpack.util.AbstractUIHandler;
+
+import java.util.ArrayList;
+import java.net.URLDecoder;
+import java.io.UnsupportedEncodingException;
+
+
+/**
+ * A panel which displays the available installGroups found on the packs to
+ * allow the user to select a subset of the packs based on the pack
+ * installGroups attribute. This panel will be skipped if there are no
+ * pack elements with an installGroups attribute.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 1.1.1.1 $
+ */
+public class InstallationGroupPanel extends IzPanel
+    implements ListSelectionListener
+{
+    private static final long serialVersionUID = 1L;
+
+    /** HashMap<String, Pack> of the InstallData.availablePacks */
+    private HashMap packsByName;
+    private TableModel groupTableModel;
+    private JTextPane descriptionField;
+    private JScrollPane groupScrollPane;
+    private JTable groupsTable;
+    private GroupData[] rows;
+    private int selectedGroup = -1;
+
+    public InstallationGroupPanel(InstallerFrame parent, InstallData idata)
+    {
+        super(parent, idata);
+        buildLayout();
+    }
+
+    /**
+     * If there are no packs with an installGroups attribute, this panel is
+     * skipped. Otherwise, the unique installGroups are displayed in a table.
+     */
+    public void panelActivate()
+    {
+        // Set/restore availablePacks from allPacks
+        idata.availablePacks = new ArrayList(idata.allPacks);
+
+        Debug.trace("InstallationGroupPanel.panelActivate, selectedGroup="+selectedGroup);
+        // If there are no groups, skip this panel
+        HashMap installGroups = getInstallGroups(idata);
+        if (installGroups.size() == 0)
+        {
+            super.askQuestion("Skip InstallGroup selection",
+                "Skip InstallGroup selection", AbstractUIHandler.CHOICES_YES_NO);
+            parent.skipPanel();
+            return;
+        }
+
+
+        // Build the table model from the unique groups
+        groupTableModel = getModel(installGroups);
+        groupsTable.setModel(groupTableModel);
+        TableColumnModel tcm = groupsTable.getColumnModel();
+        tcm.getColumn(0).setCellRenderer(new RadioButtonRenderer());
+        tcm.getColumn(0).setCellEditor(new RadioButtonEditor());
+        //groupsTable.setColumnSelectionAllowed(false);
+        //groupsTable.setRowSelectionAllowed(true);
+        groupsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+        groupsTable.getSelectionModel().addListSelectionListener (this);
+        groupsTable.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2));
+        groupsTable.setIntercellSpacing(new Dimension(0, 0));
+        groupsTable.setShowGrid(false);
+        if( selectedGroup >= 0 )
+        {
+            groupsTable.getSelectionModel().setSelectionInterval(selectedGroup, selectedGroup);
+            descriptionField.setText(rows[selectedGroup].description);
+        }
+        else
+        {
+            descriptionField.setText(rows[0].description);
+        }
+    }
+
+    /**
+     * Remove all packs from the InstallData availablePacks and selectedPacks
+     * that do not list the selected installation group. Packs without any
+     * installGroups are always included.
+     */
+    public void panelDeactivate()
+    {
+        Debug.trace("InstallationGroupPanel.panelDeactivate, selectedGroup="+selectedGroup);
+        if( selectedGroup >= 0 )
+        {
+            removeUnusedPacks();
+            GroupData group = this.rows[selectedGroup];
+            idata.setVariable("INSTALL_GROUP", group.name);
+            Debug.trace("Added variable INSTALL_GROUP="+group.name);
+        }
+    }
+
+    /**
+     * There needs to be a valid selectedGroup to go to the next panel
+     * @return true if selectedGroup >= 0, false otherwise
+     */
+    public boolean isValidated()
+    {
+        Debug.trace("InstallationGroupPanel.isValidated, selectedGroup="+selectedGroup);
+        return selectedGroup >= 0;
+    }
+
+    /**
+     * Update the current selected install group index.
+     * @param e
+     */
+    public void valueChanged(ListSelectionEvent e)
+    {
+        Debug.trace("valueChanged: " + e);
+        if (e.getValueIsAdjusting() == false)
+        {
+            ListSelectionModel lsm = (ListSelectionModel) e.getSource();
+            if( lsm.isSelectionEmpty()  )
+            {
+                descriptionField.setText("");
+            }
+            else
+            {
+                selectedGroup = lsm.getMinSelectionIndex();
+                if( selectedGroup >= 0 )
+                {
+                    GroupData data = rows[selectedGroup];
+                    descriptionField.setText(data.description);
+                }
+                Debug.trace("selectedGroup set to: "+selectedGroup);
+            }
+        }
+    }
+
+    /* Add the installation group to pack mappings
+	 * @see com.izforge.izpack.installer.IzPanel#makeXMLData(net.n3.nanoxml.XMLElement)
+	 */
+	public void makeXMLData(XMLElement panelRoot)
+	{
+		InstallationGroupPanelAutomationHelper helper = new InstallationGroupPanelAutomationHelper();
+		idata.setAttribute("GroupData", rows);
+		idata.setAttribute("packsByName", packsByName);
+		helper.makeXMLData(idata, panelRoot);
+	}
+
+	/**
+     * Create the panel ui.
+     */
+    protected void buildLayout()
+    {
+        GridBagConstraints gridBagConstraints;
+
+        descriptionField = new JTextPane();
+        groupScrollPane = new JScrollPane();
+        groupsTable = new JTable();
+
+        setLayout(new GridBagLayout());
+
+        descriptionField.setMargin(new Insets(2, 2, 2, 2));
+        descriptionField.setAlignmentX(LEFT_ALIGNMENT);
+        descriptionField.setCaretPosition(0);
+        descriptionField.setEditable(false);
+        descriptionField.setOpaque(false);
+        descriptionField.setText("<b>Install group description text</b>");
+        descriptionField.setContentType("text/html");
+        descriptionField.setBorder(new TitledBorder("Description"));
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridy = 2;
+        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
+        gridBagConstraints.weightx = 1.0;
+        gridBagConstraints.weighty = 0.3;
+        add(descriptionField, gridBagConstraints);
+
+        groupScrollPane.setBorder(new EmptyBorder(1, 1, 1, 1));
+        groupScrollPane.setViewportView(groupsTable);
+
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
+        gridBagConstraints.weightx = 1.0;
+        gridBagConstraints.weighty = 1.0;
+        add(groupScrollPane, gridBagConstraints);
+    }
+
+    protected void removeUnusedPacks()
+    {
+        GroupData data = rows[selectedGroup];
+        Debug.trace("InstallationGroupPanel.removeUnusedPacks, GroupData="+data.name);
+
+        // Now remove the packs not in groupPackNames
+        idata.selectedPacks.clear();
+        idata.selectedPacks.addAll(idata.availablePacks);
+        Iterator iter = idata.availablePacks.iterator();
+        while( iter.hasNext() )
+        {
+            Pack p = (Pack) iter.next();
+            if( data.packNames.contains(p.name) == false )
+            {
+                iter.remove();
+                Debug.trace("Removed AvailablePack: "+p.name);
+            }
+        }
+
+        List selectedPacks = idata.selectedPacks;
+        iter = selectedPacks.iterator();
+        while( iter.hasNext() )
+        {
+            Pack p = (Pack) iter.next();
+            if( data.packNames.contains(p.name) == false )
+            {
+                iter.remove();
+                Debug.trace("Removed selectedPack: "+p.name);
+            }
+        }
+    }
+    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 = (String) iter.next();
+            if( data.packNames.contains(dependent) == false )
+            {
+                Debug.trace("Need dependent: "+dependent);
+                Pack dependentPack = (Pack) 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<String, GroupData> of unique install group names
+     */
+    protected HashMap getInstallGroups(InstallData idata)
+    {
+        /* First create a packsByName<String, Pack> 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 = (String) iter.next();
+                GroupData data = (GroupData) installGroups.get(group);
+                if (data == null)
+                {
+                    String description = getGroupDescription(group);
+                    data = new GroupData(group, description);
+                    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) == true )
+                {
+                    // The pack may have already been added while traversing dependencies
+                    if( data.packNames.contains(p.name) == false )
+                        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)
+            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;
+    }
+
+    protected TableModel getModel(HashMap groupData)
+    {
+        String[] columns = { "Selected", "InstallType", "Size"};
+         DefaultTableModel model = new DefaultTableModel (columns, 0)
+         {
+            public boolean isCellEditable (int row, int column)
+            {
+               return column == 0;
+            }
+        };
+        rows = new 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.name == null || g2.name==null)
+               {
+                   return 0;
+               }
+
+               return g1.name.compareTo(g2.name);
+           }
+        });
+
+        Iterator iter = values.iterator();
+        ButtonGroup buttonGroup = new ButtonGroup();
+        boolean madeSelection = false;
+        int count = 0;
+        while (iter.hasNext())
+        {
+            GroupData gd = (GroupData) iter.next();
+            rows[count] = gd;
+            Debug.trace("Creating button#"+count+", group="+gd.name);
+            JRadioButton btn = new JRadioButton(gd.name);
+            if( selectedGroup == count )
+            {
+                btn.setSelected(true);
+                Debug.trace("Selected button#"+count);
+            }
+            else if ( selectedGroup < 0 && madeSelection == false )
+            {
+                if( defaultGroup != null )
+                {
+                   if( defaultGroup.equals(gd.name) )
+                     madeSelection = true;
+                }
+                else if( count == 0 )
+                    madeSelection = true;
+                if( madeSelection )
+                {
+                    btn.setSelected(true);
+                    Debug.trace("Selected button#"+count);
+                    selectedGroup = count;
+                }
+            }
+            else
+            {
+                btn.setSelected(false);
+            }
+            buttonGroup.add(btn);
+            String sizeText = gd.getSizeString();
+            Object[] data = { btn, gd.description, sizeText};
+            model.addRow(data);
+            count ++;
+        }
+        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;
+        long size;
+        HashSet packNames = new HashSet();
+
+        GroupData(String name, String description)
+        {
+            this.name = name;
+            this.description = description;
+        }
+
+        String getSizeString()
+        {
+            String s;
+            if (size < ONEK)
+            {
+                s = size + " bytes";
+            }
+            else if (size < ONEM)
+            {
+                s = size / ONEK + " KBytes";
+            }
+            else if (size < ONEG)
+            {
+                s = size / ONEM + " MBytes";
+            }
+            else
+            {
+                s = size / ONEG + " GBytes";
+            }
+            return s;
+        }
+        public String toString()
+        {
+            StringBuffer tmp = new StringBuffer("GroupData(");
+            tmp.append(name);
+            tmp.append("){description=");
+            tmp.append(description);
+            tmp.append(", size=");
+            tmp.append(size);
+            tmp.append(", sizeString=");
+            tmp.append(getSizeString());
+            tmp.append(", packNames=");
+            tmp.append(packNames);
+            tmp.append("}");
+            return tmp.toString();
+        }
+    }
+
+    class RadioButtonRenderer implements TableCellRenderer
+    {
+        public Component getTableCellRendererComponent (JTable table, Object value,
+                                                        boolean isSelected, boolean hasFocus,
+                                                        int row, int column)
+        {
+            if (value==null) {
+                return null;
+            }
+
+            JRadioButton button = (JRadioButton) value;
+
+            button.setForeground(isSelected ?
+                                 table.getSelectionForeground() : table.getForeground());
+            button.setBackground(isSelected ?
+                                 table.getSelectionBackground() : table.getBackground());
+
+            return button;
+        }
+    }
+
+    class RadioButtonEditor
+        extends AbstractCellEditor
+        implements ItemListener,
+                   TableCellEditor
+    {
+        private JRadioButton button;
+
+        public Component getTableCellEditorComponent (JTable table, Object value,
+                                                      boolean isSelected, int row, int column)
+        {
+            Debug.trace("getTableCellEditorComponent, row="+row);
+            if (value==null) {
+                return null;
+            }
+
+            button = (JRadioButton) value;
+            button.addItemListener(this);
+
+            button.setForeground(isSelected ?
+                                 table.getSelectionForeground() : table.getForeground());
+            button.setBackground(isSelected ?
+                                 table.getSelectionBackground() : table.getBackground());
+
+            return button;
+        }
+
+        public Object getCellEditorValue ()
+        {
+            button.removeItemListener (this);
+            return button;
+        }
+
+        public void itemStateChanged (ItemEvent e)
+        {
+            Debug.trace("itemStateChanged, e="+e);
+            super.fireEditingStopped ();
+            groupsTable.repaint();
+        }
+    }
+
+}

Added: izpack-src/trunk/src/lib/com/izforge/izpack/panels/InstallationGroupPanelAutomationHelper.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/panels/InstallationGroupPanelAutomationHelper.java	2006-09-06 21:22:14 UTC (rev 1575)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/panels/InstallationGroupPanelAutomationHelper.java	2006-09-07 01:04:39 UTC (rev 1576)
@@ -0,0 +1,115 @@
+/*
+ * IzPack - Copyright 2006 JBoss Inc, All Rights Reserved.
+ * 
+ * http://www.izforge.com/izpack/
+ * http://developer.berlios.de/projects/izpack/
+ * 
+ * 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.util.HashMap;
+import java.util.Iterator;
+import java.util.Vector;
+
+import net.n3.nanoxml.XMLElement;
+
+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;
+
+/**
+ * An automation helper for the InstallationGroupPanel
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class InstallationGroupPanelAutomationHelper
+	implements PanelAutomation
+{
+	/**
+	 * 
+	 */
+	public void makeXMLData(AutomatedInstallData idata, XMLElement panelRoot)
+	{
+		GroupData[] rows = (GroupData[]) idata.getAttribute("GroupData");
+		HashMap packsByName = (HashMap) idata.getAttribute("packsByName");
+        // Write out the group to pack mappings
+        for(int n = 0; n < rows.length; n ++)
+        {
+        	GroupData gd = rows[n];
+        	XMLElement xgroup = new XMLElement("group");
+        	xgroup.setAttribute("name", gd.name);
+        	Iterator names = gd.packNames.iterator();
+        	while( names.hasNext() )
+        	{
+        		String name = (String) names.next();
+        		Pack pack = (Pack) packsByName.get(name);
+        		int index = idata.availablePacks.indexOf(pack);
+        		XMLElement xpack = new XMLElement("pack");
+        		xpack.setAttribute("name", name);
+        		xpack.setAttribute("index", ""+index);
+        		xgroup.addChild(xpack);
+        	}
+        	panelRoot.addChild(xgroup);
+        }
+	}
+
+	/**
+	 * TODO Need to add a InstallationGroupPanelAutomationHelper to read the
+	 * xml data to allow an install group to specify the selected packs.
+	 */
+	public boolean runAutomated(AutomatedInstallData idata,
+			XMLElement panelRoot)
+	{
+		String installGroup = idata.getVariable("INSTALL_GROUP");
+		Debug.trace("InstallationGroupPanelAutomationHelper: runAutomated, INSTALL_GROUP: "+installGroup);
+		if( installGroup != null )
+		{
+			Vector groups = panelRoot.getChildrenNamed("group");
+			for(int i = 0; i < groups.size(); i ++)
+			{
+				XMLElement group = (XMLElement) groups.get(i);
+				String name = group.getAttribute("name");
+				Debug.trace("InstallationGroupPanelAutomationHelper: Checking INSTALL_GROUP against: "+name);
+				if( name.equalsIgnoreCase(installGroup) )
+				{
+					Debug.trace("Found INSTALL_GROUP match for: "+installGroup);
+					idata.selectedPacks.clear();
+					Vector packs = group.getChildrenNamed("pack");
+					Debug.trace(name+" pack count: "+packs.size());
+					Debug.trace("Available pack count: "+idata.availablePacks.size());
+					for(int j = 0; j < packs.size(); j ++)
+					{
+						XMLElement xpack = (XMLElement) packs.get(j);
+						String pname = xpack.getAttribute("name");
+						String indexStr = xpack.getAttribute("index");
+						int index = Integer.parseInt(indexStr);
+						if( index >= 0 )
+						{
+							Pack pack = (Pack) idata.availablePacks.get(index);
+							idata.selectedPacks.add(pack);
+							Debug.trace("Added pack: "+pack.name);
+						}
+					}
+					Debug.trace("Set selectedPacks to: "+idata.selectedPacks);
+					break;
+				}
+			}
+		}
+        return true;
+	}
+
+}




More information about the izpack-changes mailing list