List:Commits« Previous MessageNext Message »
From:Mike Lischke Date:March 21 2011 10:02am
Subject:bzr commit into wex-installer-1.0 branch (mike.lischke:373)
View as plain text  
#At file:///D:/Work/MySQL/installer/ based on revid:mike.lischke@stripped

  373 Mike Lischke	2011-03-21
      - ProductManager: initialize parent-child relationship for product features too.
      - FeatureTreeView + FeatureBox: properly update checkboxes with least possible repaints.
      - FeatureBox: switch on hidden features if at least one normal feature is about to be installed and switch them off if none is.

    modified:
      WexInstaller.Core/ProductManager.cs
      WexInstaller/Controls/FeatureBox.cs
      WexInstaller/Controls/FeatureTreeView.cs
=== modified file 'WexInstaller.Core/ProductManager.cs'
=== modified file 'WexInstaller.Core/ProductManager.cs'
--- a/WexInstaller.Core/ProductManager.cs	2011-03-18 10:29:04 +0000
+++ b/WexInstaller.Core/ProductManager.cs	2011-03-21 10:02:47 +0000
@@ -82,6 +82,8 @@
         {
           p.PostInitialize(true);
           p.SetParent(pc);
+          foreach (ProductFeature feature in p.GetProductFeatures())
+            feature.SetParent(p);
 
           // Initialize the controller if there are any
           if (p.Controller != null)

=== modified file 'WexInstaller/Controls/FeatureBox.cs'
--- a/WexInstaller/Controls/FeatureBox.cs	2011-03-18 17:04:52 +0000
+++ b/WexInstaller/Controls/FeatureBox.cs	2011-03-21 10:02:47 +0000
@@ -34,7 +34,20 @@
 
     #region Properties
 
-    internal FeatureTreeView FeatureTree { get; set; }
+    private FeatureTreeView featureTreeview = null;
+    internal FeatureTreeView FeatureTree
+    {
+      get { return featureTreeview; }
+      set
+      {
+        if (featureTreeview != null)
+          featureTreeview.ProductInstallationProposalChanged -= featureTreeview_ProductInstallationProposalChanged;
+        featureTreeview = value;
+        if (featureTreeview != null)
+          featureTreeview.ProductInstallationProposalChanged +=
+            new EventHandler<FeatureTreeView.ProductChangedEventArgs>(featureTreeview_ProductInstallationProposalChanged);
+      }
+    }
 
     public ProductElement SelectedObject
     {
@@ -173,7 +186,7 @@
           }
         }
 
-        // No iterate over all categories and their products and see if any of the products matches
+        // Now iterate over all categories and their products and see if any of the products matches
         // any of the products in the reference catalog(s).
         Dictionary<string, Product> products = new Dictionary<string, Product>();
         foreach (Product p in category.Products)
@@ -190,6 +203,17 @@
       return result;
     }
 
+    private void InvalidateCheckbox(TreeNode child)
+    {
+      // The checkbox place is before the text centered in an area twice as wide as 
+      // the checkbox itself.
+      Rectangle checkBoxRectangle = new Rectangle();
+      checkBoxRectangle.Location = new Point(CBGlyphSize.Width / 2,
+        child.Bounds.Top + ((featureList.ItemHeight - CBGlyphSize.Height) / 2));
+      checkBoxRectangle.Size = CBGlyphSize;
+      featureList.Invalidate(checkBoxRectangle);
+    }
+
     #endregion
 
     #region Drawing
@@ -225,33 +249,6 @@
       g.DrawString(SelectedObject.Description, smallFont, blackBrush, textPt);
     }
 
-    #endregion
-
-    #region Event handling
-
-    private void featureList_AfterCheck(object sender, TreeViewEventArgs e)
-    {
-      Product p = e.Node.Tag as Product;
-      if (p != null)
-      {
-        if (p.Installed)
-          return;
-        p.ProposedInstalled = !p.ProposedInstalled;
-
-        List<ProductFeature> productFeatures = p.GetProductFeatures();
-        foreach (ProductFeature pf in productFeatures)
-          pf.ProposedInstalled = p.ProposedInstalled;
-      }
-      else
-      {
-        ProductFeature pf = e.Node.Tag as ProductFeature;
-        pf.ProposedInstalled = !pf.ProposedInstalled;
-      }
-      featureList.Refresh();
-      if (FeatureTree != null)
-        FeatureTree.Refresh();
-    }
-
     private void featureList_DrawNode(object sender, DrawTreeNodeEventArgs e)
     {
       if (e.Bounds.Width <= 0 || e.Bounds.Height <= 0)
@@ -287,5 +284,60 @@
 
     #endregion
 
+    #region Event handling
+
+    private void featureList_AfterCheck(object sender, TreeViewEventArgs e)
+    {
+      Product p = e.Node.Tag as Product;
+      if (p != null)
+      {
+        if (p.Installed)
+          return;
+        p.ProposedInstalled = !p.ProposedInstalled;
+
+        List<ProductFeature> productFeatures = p.GetProductFeatures();
+        foreach (ProductFeature pf in productFeatures)
+          pf.ProposedInstalled = p.ProposedInstalled;
+
+        InvalidateCheckbox(e.Node); // Redraw only the single node whose state was changed.
+      }
+      else
+      {
+        ProductFeature pf = e.Node.Tag as ProductFeature;
+        pf.ProposedInstalled = !pf.ProposedInstalled;
+
+        // Check if at least one (visible) product feature for the owning product is proposed for installation.
+        // If so set also all invisible features too. Otherwise remove invisible features from the 
+        // installation list so that the entire product is set to no-installation.
+        ProductElement element = pf;
+        do
+        {
+          element = element.Parent;
+        } while (element != null && !(element is Product));
+
+        if (element is Product)
+        {
+          Product product = element as Product;
+          bool anyFeatureInstalled = false;
+          foreach (TreeNode node in featureList.Nodes)
+            anyFeatureInstalled |= (node.Tag as ProductFeature).ProposedInstalled;
+          foreach (ProductFeature feature in product.GetProductFeatures())
+            if (feature.Display == "0") // Invisible feature.
+              feature.ProposedInstalled = anyFeatureInstalled;
+        }
+
+        featureList.Invalidate(); // There can be sub features that changed state too, so redraw everything.
+      }
+      if (FeatureTree != null)
+        FeatureTree.Invalidate();
+    }
+
+    void featureTreeview_ProductInstallationProposalChanged(object sender, FeatureTreeView.ProductChangedEventArgs e)
+    {
+      featureList.Invalidate();
+    }
+
+    #endregion
+
   }
 }

=== modified file 'WexInstaller/Controls/FeatureTreeView.cs'
--- a/WexInstaller/Controls/FeatureTreeView.cs	2011-03-18 17:04:52 +0000
+++ b/WexInstaller/Controls/FeatureTreeView.cs	2011-03-21 10:02:47 +0000
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 using System.Drawing;
 using System.Windows.Forms;
 using System.Windows.Forms.VisualStyles;
@@ -19,6 +20,16 @@
 
     public CatalogArchitecture Architecture { get; set; }
 
+    public class ProductChangedEventArgs : EventArgs
+    {
+      public ProductChangedEventArgs(Product product)
+      {
+        this.Product = product;
+      }
+
+      public Product Product{ get; set; }
+    }
+
     #endregion
 
     #region Construction and setup
@@ -127,6 +138,8 @@
 
       foreach (ProductFeature pf in productFeatures)
         pf.ProposedInstalled = doInstall;
+
+      OnProductInstallationProposalChanged(p);
     }
 
     private CheckBoxState GetNodeCheckboxState(TreeNode node)
@@ -382,6 +395,16 @@
       base.OnNodeMouseClick(e);
     }
 
+    public event EventHandler<ProductChangedEventArgs> ProductInstallationProposalChanged;
+    protected internal void OnProductInstallationProposalChanged(Product product)
+    {
+      if (ProductInstallationProposalChanged != null)
+      {
+        ProductChangedEventArgs args = new ProductChangedEventArgs(product);
+        ProductInstallationProposalChanged(this, args);
+      }
+    }
+
     #endregion
 
     private void InitializeComponent()

Attachment: [text/bzr-bundle] bzr/mike.lischke@oracle.com-20110321100247-r4xsqtdgr4xi5i62.bundle
Thread
bzr commit into wex-installer-1.0 branch (mike.lischke:373) Mike Lischke21 Mar