Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/05/10 10:38:19 (14 years ago)
Author:
gkronber
Message:

Implemented changes in plugin infrastructure requested by reviewers. #989 (Implement review comments in plugin infrastructure)

File:
1 edited

Legend:

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

    r3612 r3624  
    114114        "There was an error while connecting to the server." + Environment.NewLine +
    115115           "Please check your connection settings and user credentials.");
    116         DisableControls();
     116        this.products.Clear();
     117        this.plugins.Clear();
    117118      } else {
    118119        this.products = new List<DeploymentService.ProductDescription>(
     
    121122          (DeploymentService.PluginDescription[])((object[])e.Result)[1]);
    122123
    123         UpdateProductsList();
    124         dirtyProducts.Clear();
    125124        EnableControls();
    126125      }
     126      UpdateProductsList();
     127      dirtyProducts.Clear();
    127128      StatusView.HideProgressIndicator();
    128129      StatusView.RemoveMessage(DeleteProductMessage);
     
    179180        "There was an error while connecting to the server." + Environment.NewLine +
    180181           "Please check your connection settings and user credentials.");
    181         DisableControls();
     182        this.products.Clear();
     183        this.plugins.Clear();
    182184      } else {
    183185        this.products = new List<DeploymentService.ProductDescription>(
     
    186188          (DeploymentService.PluginDescription[])((object[])e.Result)[1]);
    187189
    188         UpdateProductsList();
    189         dirtyProducts.Clear();
    190         EnableControls();
    191       }
     190      }
     191      UpdateProductsList();
     192      dirtyProducts.Clear();
     193      EnableControls();
    192194      StatusView.HideProgressIndicator();
    193195      StatusView.RemoveMessage(UploadMessage);
     
    222224          "There was an error while connecting to the server." + Environment.NewLine +
    223225                   "Please check your connection settings and user credentials.");
    224         DisableControls();
     226        this.products.Clear();
     227        this.plugins.Clear();
     228
    225229      } else {
    226230        this.products = new List<DeploymentService.ProductDescription>(
     
    228232        this.plugins = new List<DeploymentService.PluginDescription>(
    229233          (DeploymentService.PluginDescription[])((object[])e.Result)[1]);
    230 
    231 
    232         UpdateProductsList();
    233         dirtyProducts.Clear();
    234         EnableControls();
    235       }
     234      }
     235      UpdateProductsList();
     236      dirtyProducts.Clear();
     237      EnableControls();
    236238      StatusView.HideProgressIndicator();
    237239      StatusView.RemoveMessage(RefreshMessage);
     
    241243
    242244    private void UpdateProductsList() {
     245      productsListView.SelectedItems.Clear();
    243246      productsListView.Items.Clear();
    244247      foreach (var prodDesc in products) {
    245248        productsListView.Items.Add(CreateListViewItem(prodDesc));
    246249      }
    247       foreach (ColumnHeader column in productsListView.Columns)
    248         if (productsListView.Items.Count > 0)
    249           column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
    250         else column.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
     250      Util.ResizeColumns(productsListView.Columns.OfType<ColumnHeader>());
    251251    }
    252252
     
    254254      bool productSelected = productsListView.SelectedItems.Count > 0;
    255255      detailsGroupBox.Enabled = productSelected;
    256       deleteProductButton.Enabled = productSelected;
    257       uploadButton.Enabled = dirtyProducts.Count > 0;
     256      UpdateProductButtons();
    258257      if (productSelected) {
    259258        DeploymentService.ProductDescription activeProduct = (DeploymentService.ProductDescription)((ListViewItem)productsListView.SelectedItems[0]).Tag;
     
    263262        // populate plugins list view
    264263        ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0];
     264        pluginListView.SuppressItemCheckedEvents = true;
    265265        foreach (var plugin in plugins.OfType<IPluginDescription>()) {
    266266          pluginListView.Items.Add(CreateListViewItem(plugin));
    267267        }
    268 
    269         pluginListView.CheckItems(from plugin in activeProduct.Plugins
    270                                   let item = FindItemForPlugin(plugin)
    271                                   where item != null
    272                                   select item);
    273 
     268        pluginListView.SuppressItemCheckedEvents = false;
     269        foreach (var plugin in activeProduct.Plugins) {
     270          pluginListView.CheckItems(FindItemsForPlugin(plugin));
     271        }
    274272      } else {
    275273        nameTextBox.Text = string.Empty;
     
    277275        pluginListView.Items.Clear();
    278276      }
     277      Util.ResizeColumns(pluginListView.Columns.OfType<ColumnHeader>());
     278    }
     279
     280    private void UpdateProductButtons() {
     281      uploadButton.Enabled = dirtyProducts.Count > 0;
     282      if (productsListView.SelectedItems.Count > 0) {
     283        var selectedProduct = (DeploymentService.ProductDescription)productsListView.SelectedItems[0].Tag;
     284        deleteProductButton.Enabled = !dirtyProducts.Contains(selectedProduct);
     285      } else {
     286        deleteProductButton.Enabled = false;
     287      }
    279288    }
    280289
     
    283292    private void newProductButton_Click(object sender, EventArgs e) {
    284293      var newProduct = new DeploymentService.ProductDescription("New product", new Version("0.0.0.0"));
    285       ListViewItem item = CreateListViewItem(newProduct);
    286       productsListView.Items.Add(item);
     294      products.Add(newProduct);
     295      UpdateProductsList();
    287296      MarkProductDirty(newProduct);
    288297    }
     
    359368
    360369    #region plugin list view
    361     private void pluginListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
     370    private void OnItemChecked(ItemCheckedEventArgs e) {
    362371      ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0];
    363372      DeploymentService.ProductDescription activeProduct = (DeploymentService.ProductDescription)activeItem.Tag;
     
    366375      MarkProductDirty(activeProduct);
    367376    }
     377
     378    private void listView_ItemChecked(object sender, ItemCheckedEventArgs e) {
     379      List<IPluginDescription> modifiedPlugins = new List<IPluginDescription>();
     380      if (e.Item.Checked) {
     381        foreach (ListViewItem item in pluginListView.SelectedItems) {
     382          var plugin = (IPluginDescription)item.Tag;
     383          // also check all dependencies
     384          if (!modifiedPlugins.Contains(plugin))
     385            modifiedPlugins.Add(plugin);
     386          foreach (var dep in GetAllDependencies(plugin)) {
     387            if (!modifiedPlugins.Contains(dep))
     388              modifiedPlugins.Add(dep);
     389          }
     390        }
     391        pluginListView.CheckItems(modifiedPlugins.Select(x => FindItemsForPlugin(x).Single()));
     392        OnItemChecked(e);
     393      } else {
     394        foreach (ListViewItem item in pluginListView.SelectedItems) {
     395          var plugin = (IPluginDescription)item.Tag;
     396          // also uncheck all dependent plugins
     397          if (!modifiedPlugins.Contains(plugin))
     398            modifiedPlugins.Add(plugin);
     399          foreach (var dep in GetAllDependents(plugin)) {
     400            if (!modifiedPlugins.Contains(dep))
     401              modifiedPlugins.Add(dep);
     402          }
     403
     404        }
     405        pluginListView.UncheckItems(modifiedPlugins.Select(x => FindItemsForPlugin(x).Single()));
     406        OnItemChecked(e);
     407      }
     408    }
     409
     410
    368411    #endregion
    369412
    370413    #region helper
     414    private IEnumerable<IPluginDescription> GetAllDependents(IPluginDescription plugin) {
     415      return from p in plugins
     416             let matchingEntries = from dep in GetAllDependencies(p)
     417                                   where dep.Name == plugin.Name
     418                                   where dep.Version == plugin.Version
     419                                   select dep
     420             where matchingEntries.Any()
     421             select p as IPluginDescription;
     422    }
     423
     424    private IEnumerable<IPluginDescription> GetAllDependencies(IPluginDescription plugin) {
     425      HashSet<IPluginDescription> yieldedPlugins = new HashSet<IPluginDescription>();
     426      foreach (var dep in plugin.Dependencies) {
     427        foreach (var recDep in GetAllDependencies(dep)) {
     428          if (!yieldedPlugins.Contains(recDep)) {
     429            yieldedPlugins.Add(recDep);
     430            yield return recDep;
     431          }
     432        }
     433        if (!yieldedPlugins.Contains(dep)) {
     434          yieldedPlugins.Add(dep);
     435          yield return dep;
     436        }
     437      }
     438    }
    371439    private void MarkProductDirty(HeuristicLab.PluginInfrastructure.Advanced.DeploymentService.ProductDescription activeProduct) {
    372440      if (!dirtyProducts.Contains(activeProduct)) {
     
    374442        var item = FindItemForProduct(activeProduct);
    375443        item.ImageIndex = 1;
     444        UpdateProductButtons();
    376445      }
    377446    }
     
    399468              select item).Single();
    400469    }
    401 
    402     private ListViewItem FindItemForPlugin(IPluginDescription plugin) {
    403       return (from i in pluginListView.Items.Cast<ListViewItem>()
    404               let p = i.Tag as IPluginDescription
    405               where p != null
    406               where p.Name == plugin.Name
    407               where p.Version == plugin.Version
    408               select i).SingleOrDefault();
    409     }
    410 
    411     private void DisableControls() {
    412       newProductButton.Enabled = false;
    413       productsListView.Enabled = false;
    414       detailsGroupBox.Enabled = false;
    415       deleteProductButton.Enabled = false;
    416       nameTextBox.Text = string.Empty;
    417       versionTextBox.Text = string.Empty;
    418       pluginListView.Items.Clear();
    419     }
     470    private IEnumerable<ListViewItem> FindItemsForPlugin(IPluginDescription plugin) {
     471      return from item in pluginListView.Items.OfType<ListViewItem>()
     472             let p = item.Tag as IPluginDescription
     473             where p.Name == plugin.Name
     474             where p.Version == plugin.Version
     475             select item;
     476    }
     477
    420478    private void EnableControls() {
    421479      newProductButton.Enabled = true;
Note: See TracChangeset for help on using the changeset viewer.