Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/04/10 16:37:10 (14 years ago)
Author:
gkronber
Message:

Changed plugin manager GUI as suggested by reviewers. #989 (Implement review comments in plugin infrastructure)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.PluginInfrastructure/Advanced/RemotePluginInstaller.cs

    r3600 r3608  
    4343    private BackgroundWorker updateOrInstallPluginsBackgroundWorker;
    4444
    45     private ListViewGroup newPluginsGroup;
    46     private ListViewGroup productsGroup;
    47     private ListViewGroup allPluginsGroup;
    48 
    49     private bool showAllPlugins;
    50     public bool ShowAllPlugins {
    51       get { return showAllPlugins; }
    52       set {
    53         if (value != showAllPlugins) {
    54           showAllPlugins = value;
    55           UpdateControl();
    56         }
    57       }
    58     }
    59 
    6045    private IEnumerable<DeploymentService.ProductDescription> products;
    61     public IEnumerable<DeploymentService.ProductDescription> Products {
    62       get { return products ?? Enumerable.Empty<DeploymentService.ProductDescription>(); }
    63       set {
    64         if (value != this.products) {
    65           this.products = value;
    66           UpdateControl();
    67         }
    68       }
    69     }
    70 
    7146    private IEnumerable<IPluginDescription> plugins;
    72     public IEnumerable<IPluginDescription> AllPlugins {
    73       get { return plugins ?? Enumerable.Empty<IPluginDescription>(); }
    74       set {
    75         if (value != this.plugins) {
    76           this.plugins = value;
    77           UpdateControl();
    78         }
    79       }
    80     }
    81 
    82     private IEnumerable<IPluginDescription> newPlugins;
    83     public IEnumerable<IPluginDescription> NewPlugins {
    84       get { return newPlugins ?? Enumerable.Empty<IPluginDescription>(); }
    85       set {
    86         if (value != this.newPlugins) {
    87           this.newPlugins = value;
    88           UpdateControl();
    89         }
    90       }
    91     }
    92 
    93     public IEnumerable<IPluginDescription> CheckedPlugins {
     47
     48    private IEnumerable<IPluginDescription> CheckedPlugins {
    9449      get {
    95         return (from item in remotePluginsListView.Items.OfType<ListViewItem>()
     50        return (from item in pluginsListView.Items.OfType<ListViewItem>()
    9651                where item.Checked
    9752                let plugin = item.Tag as IPluginDescription
     
    11368    public RemotePluginInstallerView() {
    11469      InitializeComponent();
    115 
     70      productImageList.Images.Add(HeuristicLab.PluginInfrastructure.Resources.Resources.Setup_Install);
     71      productLargeImageList.Images.Add(HeuristicLab.PluginInfrastructure.Resources.Resources.Setup_Install);
     72      pluginsImageList.Images.Add(HeuristicLab.PluginInfrastructure.Resources.Resources.plugin_16);
    11673      refreshServerPluginsBackgroundWorker = new BackgroundWorker();
    11774      refreshServerPluginsBackgroundWorker.DoWork += new DoWorkEventHandler(refreshServerPluginsBackgroundWorker_DoWork);
     
    12178      updateOrInstallPluginsBackgroundWorker.DoWork += new DoWorkEventHandler(updateOrInstallPluginsBackgroundWorker_DoWork);
    12279      updateOrInstallPluginsBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(updateOrInstallPluginsBackgroundWorker_RunWorkerCompleted);
    123 
    124       newPluginsGroup = remotePluginsListView.Groups["newPluginsGroup"];
    125       productsGroup = remotePluginsListView.Groups["productsGroup"];
    126       allPluginsGroup = remotePluginsListView.Groups["allPluginsGroup"];
    12780    }
    12881
     
    13689      } else {
    13790        RefreshBackgroundWorkerResult refreshResult = (RefreshBackgroundWorkerResult)e.Result;
    138         UpdateRemotePluginList(refreshResult.RemoteProducts, refreshResult.RemotePlugins);
     91        products = refreshResult.RemoteProducts;
     92        plugins = refreshResult.RemotePlugins;
     93        UpdateControl();
    13994      }
    14095      StatusView.UnlockUI();
     
    183138      refreshServerPluginsBackgroundWorker.RunWorkerAsync();
    184139    }
    185     private void installButton_Click(object sender, EventArgs e) {
     140    private void installPluginsButton_Click(object sender, EventArgs e) {
    186141      StatusView.LockUI();
    187142      StatusView.ShowProgressIndicator();
     
    205160      updateOrInstallPluginsBackgroundWorker.RunWorkerAsync(updateOrInstallInfo);
    206161    }
     162    private void installProductsButton_Click(object sender, EventArgs e) {
     163      StatusView.LockUI();
     164      StatusView.ShowProgressIndicator();
     165      var updateOrInstallInfo = new UpdateOrInstallPluginsBackgroundWorkerArgument();
     166      var selectedProduct = (DeploymentService.ProductDescription)productsListView.SelectedItems[0].Tag;
     167      // if there is a local plugin with same name and same major and minor version then it's an update
     168      var pluginsToUpdate = from plugin in selectedProduct.Plugins
     169                            let matchingLocalPlugins = from localPlugin in pluginManager.Plugins
     170                                                       where localPlugin.Name == plugin.Name
     171                                                       where localPlugin.Version.Major == plugin.Version.Major
     172                                                       where localPlugin.Version.Minor == plugin.Version.Minor
     173                                                       where IsNewerThan(plugin, localPlugin)
     174                                                       select localPlugin
     175                            where matchingLocalPlugins.Count() > 0
     176                            select plugin;
     177
     178      // otherwise install a new plugin
     179      var pluginsToInstall = selectedProduct.Plugins.Except(pluginsToUpdate);
     180
     181      updateOrInstallInfo.PluginsToInstall = (IEnumerable<IPluginDescription>)pluginsToInstall.ToList();
     182      updateOrInstallInfo.PluginsToUpdate = (IEnumerable<IPluginDescription>)pluginsToUpdate.ToList();
     183      updateOrInstallPluginsBackgroundWorker.RunWorkerAsync(updateOrInstallInfo);
     184    }
     185
     186    private void showLargeIconsButton_CheckedChanged(object sender, EventArgs e) {
     187      productsListView.View = View.LargeIcon;
     188    }
     189
     190    private void showDetailsButton_CheckedChanged(object sender, EventArgs e) {
     191      productsListView.View = View.Details;
     192    }
     193
    207194    #endregion
    208195
    209196    private void UpdateControl() {
    210       ClearListView();
    211       remotePluginsListView.SuppressItemCheckedEvents = true;
    212       foreach (var newPlugin in NewPlugins) {
    213         var item = CreateListViewItem(newPlugin);
    214         item.Group = newPluginsGroup;
    215         remotePluginsListView.Items.Add(item);
    216       }
    217 
    218       foreach (var product in Products) {
     197      // clear products view
     198      List<ListViewItem> productItemsToDelete = new List<ListViewItem>(productsListView.Items.OfType<ListViewItem>());
     199      productItemsToDelete.ForEach(item => productsListView.Items.Remove(item));
     200
     201      // populate products list view
     202      foreach (var product in products) {
    219203        var item = CreateListViewItem(product);
    220         item.Group = productsGroup;
    221         remotePluginsListView.Items.Add(item);
    222       }
    223 
    224       if (showAllPlugins) {
    225         foreach (var plugin in AllPlugins) {
    226           var item = CreateListViewItem(plugin);
    227           item.Group = allPluginsGroup;
    228           remotePluginsListView.Items.Add(item);
    229         }
    230       }
    231       foreach (ColumnHeader column in remotePluginsListView.Columns)
    232         if (remotePluginsListView.Items.Count > 0)
     204        productsListView.Items.Add(item);
     205      }
     206      var allPluginsListViewItem = new ListViewItem();
     207      allPluginsListViewItem.Text = "All Plugins";
     208      allPluginsListViewItem.ImageIndex = 0;
     209      productsListView.Items.Add(allPluginsListViewItem);
     210      foreach (ColumnHeader column in productsListView.Columns)
     211        if (productsListView.Items.Count > 0)
    233212          column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
    234213        else column.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
    235 
    236       remotePluginsListView.SuppressItemCheckedEvents = false;
    237     }
    238 
    239     private void ClearListView() {
    240       List<ListViewItem> itemsToDelete = new List<ListViewItem>(remotePluginsListView.Items.OfType<ListViewItem>());
    241       itemsToDelete.ForEach(item => remotePluginsListView.Items.Remove(item));
     214    }
     215
     216    private void UpdatePluginsList() {
     217      // clear plugins list view
     218      List<ListViewItem> pluginItemsToDelete = new List<ListViewItem>(pluginsListView.Items.OfType<ListViewItem>());
     219      pluginItemsToDelete.ForEach(item => pluginsListView.Items.Remove(item));
     220
     221      // populate plugins list
     222      if (productsListView.SelectedItems.Count > 0) {
     223        pluginsListView.SuppressItemCheckedEvents = true;
     224
     225        var selectedItem = productsListView.SelectedItems[0];
     226        if (selectedItem.Text == "All Plugins") {
     227          foreach (var plugin in plugins) {
     228            var item = CreateListViewItem(plugin);
     229            pluginsListView.Items.Add(item);
     230          }
     231        } else {
     232          var selectedProduct = (DeploymentService.ProductDescription)productsListView.SelectedItems[0].Tag;
     233          foreach (var plugin in selectedProduct.Plugins) {
     234            var item = CreateListViewItem(plugin);
     235            pluginsListView.Items.Add(item);
     236          }
     237        }
     238
     239        foreach (ColumnHeader column in pluginsListView.Columns)
     240          if (pluginsListView.Items.Count > 0)
     241            column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
     242          else column.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
     243
     244        pluginsListView.SuppressItemCheckedEvents = false;
     245      }
    242246    }
    243247
    244248    private ListViewItem CreateListViewItem(DeploymentService.ProductDescription product) {
    245       ListViewItem item = new ListViewItem(new string[] { product.Name, product.Version.ToString(), string.Empty });
     249      ListViewItem item = new ListViewItem(new string[] { product.Name, product.Version.ToString() });
    246250      item.Tag = product;
     251      item.ImageIndex = 0;
    247252      return item;
    248253    }
     
    251256      ListViewItem item = new ListViewItem(new string[] { plugin.Name, plugin.Version.ToString(), plugin.Description });
    252257      item.Tag = plugin;
     258      item.ImageIndex = 0;
    253259      return item;
    254260    }
     261
     262    #region products list view events
     263    private void productsListView_SelectedIndexChanged(object sender, EventArgs e) {
     264      UpdatePluginsList();
     265      installProductsButton.Enabled = (productsListView.SelectedItems.Count > 0 &&
     266        productsListView.SelectedItems[0].Text != "All Plugins");
     267    }
     268    #endregion
    255269
    256270    #region item checked event handler
    257271    private void remotePluginsListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
    258       foreach (ListViewItem item in remotePluginsListView.SelectedItems) {
     272      foreach (ListViewItem item in pluginsListView.SelectedItems) {
    259273        // dispatch by check state and type of item (product/plugin)
    260274        IPluginDescription plugin = item.Tag as IPluginDescription;
     
    273287        }
    274288      }
    275       installButton.Enabled = remotePluginsListView.CheckedItems.Count > 0;
     289      installPluginsButton.Enabled = pluginsListView.CheckedItems.Count > 0;
    276290    }
    277291
     
    287301        }
    288302      }
    289       remotePluginsListView.UncheckItems(modifiedItems);
     303      pluginsListView.UncheckItems(modifiedItems);
    290304    }
    291305
     
    303317        }
    304318      }
    305       remotePluginsListView.CheckItems(modifiedItems);
     319      pluginsListView.CheckItems(modifiedItems);
    306320    }
    307321
     
    333347        }
    334348      }
    335       remotePluginsListView.UncheckItems(modifiedItems);
     349      pluginsListView.UncheckItems(modifiedItems);
    336350    }
    337351
     
    349363        }
    350364      }
    351       remotePluginsListView.CheckItems(modifiedItems);
     365      pluginsListView.CheckItems(modifiedItems);
    352366    }
    353367
     
    356370    #region helper methods
    357371    private IEnumerable<ListViewItem> FindItemsForPlugin(IPluginDescription plugin) {
    358       return (from item in remotePluginsListView.Items.OfType<ListViewItem>()
     372      return (from item in pluginsListView.Items.OfType<ListViewItem>()
    359373              let otherPlugin = item.Tag as IPluginDescription
    360374              where otherPlugin != null && otherPlugin.Name == plugin.Name && otherPlugin.Version == plugin.Version
     
    363377
    364378    private ListViewItem FindItemForProduct(DeploymentService.ProductDescription product) {
    365       return (from item in remotePluginsListView.Items.OfType<ListViewItem>()
     379      return (from item in pluginsListView.Items.OfType<ListViewItem>()
    366380              let otherProduct = item.Tag as DeploymentService.ProductDescription
    367381              where otherProduct != null && otherProduct.Name == product.Name && otherProduct.Version == product.Version
     
    369383    }
    370384
    371     private void UpdateRemotePluginList(
    372       IEnumerable<DeploymentService.ProductDescription> remoteProducts,
    373       IEnumerable<IPluginDescription> remotePlugins) {
    374 
    375       var mostRecentRemotePlugins = from remote in remotePlugins
    376                                     where !remotePlugins.Any(x => x.Name == remote.Name && x.Version > remote.Version) // same name and higher version
    377                                     select remote;
    378 
    379       var newPlugins = from remote in mostRecentRemotePlugins
    380                        let matchingLocal = (from local in pluginManager.Plugins
    381                                             where local.Name == remote.Name
    382                                             where local.Version < remote.Version
    383                                             select local).FirstOrDefault()
    384                        where matchingLocal != null
    385                        select remote;
    386 
    387       NewPlugins = newPlugins;
    388       Products = remoteProducts;
    389       AllPlugins = remotePlugins;
    390     }
    391385    private bool IsNewerThan(IPluginDescription plugin1, IPluginDescription plugin2) {
    392386      // newer: build version is higher, or if build version is the same revision is higher
     
    397391    #endregion
    398392
    399 
    400393  }
    401394}
Note: See TracChangeset for help on using the changeset viewer.