Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/10 14:58:26 (14 years ago)
Author:
gkronber
Message:

Improved GUI for plugin and product management. #891 (Refactor GUI for plugin management)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DeploymentServer Prototype/HeuristicLab.Services/HeuristicLab.DeploymentService.AdminClient/ProductEditor.cs

    r2816 r3015  
    99using HeuristicLab.MainForm;
    1010using PluginDeploymentService = HeuristicLab.PluginInfrastructure.Advanced.DeploymentService;
     11using System.ServiceModel;
     12using HeuristicLab.PluginInfrastructure;
    1113
    1214namespace HeuristicLab.DeploymentService.AdminClient {
     
    2224      Caption = "Products";
    2325
     26      productImageList.Images.Add(HeuristicLab.Common.Resources.VS2008ImageLibrary.Assembly);
     27      productImageList.Images.Add(HeuristicLab.Common.Resources.VS2008ImageLibrary.ArrowUp);
     28      pluginImageList.Images.Add(HeuristicLab.Common.Resources.VS2008ImageLibrary.Assembly);
     29
    2430      dirtyProducts = new HashSet<PluginDeploymentService.ProductDescription>();
    2531      refreshProductsWorker = new BackgroundWorker();
     
    3238    }
    3339
    34     void uploadChangedProductsWorker_DoWork(object sender, DoWorkEventArgs e) {
     40    #region event handlers for upload products background worker
     41    private void uploadChangedProductsWorker_DoWork(object sender, DoWorkEventArgs e) {
    3542      var products = (IEnumerable<PluginDeploymentService.ProductDescription>)e.Argument;
    36       using (var adminClient = new PluginDeploymentService.AdminClient()) {
     43      var adminClient = PluginDeploymentService.AdminClientFactory.CreateClient();
     44      try {
    3745        foreach (var product in products) {
    3846          adminClient.DeployProduct(product);
    3947        }
    40       }
    41       e.Cancel = false;
    42     }
    43 
    44     void uploadChangedProductsWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
     48        e.Cancel = false;
     49      }
     50      catch (FaultException) {
     51      }
     52    }
     53
     54    private void uploadChangedProductsWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
    4555      this.Enabled = true;
    46     }
    47 
    48     void refreshProductsWorker_DoWork(object sender, DoWorkEventArgs e) {
    49       var updateClient = new PluginDeploymentService.UpdateClient();
    50       e.Result = new object[] { updateClient.GetProducts(), updateClient.GetPlugins() };
    51     }
    52 
    53     void refreshProductsWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
     56      refreshProductsWorker.RunWorkerAsync();
     57    }
     58    #endregion
     59
     60    #region event handlers for refresh products background worker
     61    private void refreshProductsWorker_DoWork(object sender, DoWorkEventArgs e) {
     62      var updateClient = PluginDeploymentService.UpdateClientFactory.CreateClient();
     63      try {
     64        e.Result = new object[] { updateClient.GetProducts(), updateClient.GetPlugins() };
     65      }
     66      catch (FaultException) {
     67        e.Cancel = true;
     68      }
     69    }
     70
     71    private void refreshProductsWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
    5472      this.products = new List<PluginDeploymentService.ProductDescription>(
    5573        (PluginDeploymentService.ProductDescription[])((object[])e.Result)[0]);
     
    6381      SetControlsEnabled(true);
    6482    }
     83    #endregion
    6584
    6685    private void UpdateProductsList() {
     86      productsListView.Items.Clear();
    6787      foreach (var prodDesc in products) {
    68         productsListBox.Items.Add(CreateListViewItem(prodDesc));
     88        productsListView.Items.Add(CreateListViewItem(prodDesc));
    6989      }
    7090    }
    7191
    7292    private void productsListBox_SelectedIndexChanged(object sender, EventArgs e) {
    73       if (productsListBox.SelectedItems.Count == 0) return;
    74       PluginDeploymentService.ProductDescription activeProduct = (PluginDeploymentService.ProductDescription)((ListViewItem)productsListBox.SelectedItem).Tag;
     93      if (productsListView.SelectedItems.Count == 0) return;
     94      PluginDeploymentService.ProductDescription activeProduct = (PluginDeploymentService.ProductDescription)((ListViewItem)productsListView.SelectedItems[0]).Tag;
    7595      UpdateProductDetails(activeProduct);
    7696    }
     
    80100      versionTextBox.Text = activeProduct.Version.ToString();
    81101
    82       pluginsList.Items.Clear();
     102      pluginsListView.Items.Clear();
    83103      foreach (PluginDeploymentService.PluginDescription pluginDesc in plugins) {
    84104        var matching = from p in activeProduct.Plugins
     
    87107                       select p;
    88108
    89         if (matching.Any()) pluginsList.Items.Add(pluginDesc, true);
    90         else pluginsList.Items.Add(pluginDesc, false);
    91       }
     109        if (matching.Any()) pluginsListView.Items.Add(CreateCheckedListViewItem(pluginDesc));
     110        else pluginsListView.Items.Add(CreateUncheckedListViewItem(pluginDesc));
     111      }
     112    }
     113
     114    private ListViewItem CreateUncheckedListViewItem(HeuristicLab.PluginInfrastructure.Advanced.DeploymentService.PluginDescription pluginDesc) {
     115      ListViewItem item = new ListViewItem(new string[] { pluginDesc.Name, pluginDesc.Version.ToString() });
     116      item.Checked = false;
     117      item.Tag = pluginDesc;
     118      item.ImageIndex = 0;
     119      return item;
     120    }
     121
     122    private ListViewItem CreateCheckedListViewItem(HeuristicLab.PluginInfrastructure.Advanced.DeploymentService.PluginDescription pluginDesc) {
     123      ListViewItem item = new ListViewItem(new string[] { pluginDesc.Name, pluginDesc.Version.ToString() });
     124      item.Checked = true;
     125      item.Tag = pluginDesc;
     126      item.ImageIndex = 0;
     127      return item;
     128    }
     129
     130    private ListViewItem CreateListViewItem(PluginDeploymentService.ProductDescription productDescription) {
     131      ListViewItem item = new ListViewItem(new string[] { productDescription.Name, productDescription.Version.ToString() });
     132      item.Tag = productDescription;
     133      item.ImageIndex = 0;
     134      return item;
    92135    }
    93136
     
    107150      var newProduct = new PluginDeploymentService.ProductDescription("New product", new Version("0.0.0.0"));
    108151      ListViewItem item = CreateListViewItem(newProduct);
    109       productsListBox.Items.Add(item);
    110       dirtyProducts.Add(newProduct);
    111     }
    112 
    113     private ListViewItem CreateListViewItem(PluginDeploymentService.ProductDescription productDescription) {
    114       ListViewItem item = new ListViewItem();
    115       item.Text = productDescription.Name + " " + productDescription.Version;
    116       item.Name = productDescription.Name + " " + productDescription.Version;
    117       item.Tag = productDescription;
    118       return item;
     152      productsListView.Items.Add(item);
     153      MarkProductDirty(newProduct);
    119154    }
    120155
     
    125160
    126161    private void nameTextBox_TextChanged(object sender, EventArgs e) {
    127       ListViewItem activeItem = (ListViewItem)productsListBox.SelectedItem;
     162      ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0];
    128163      PluginDeploymentService.ProductDescription activeProduct = (PluginDeploymentService.ProductDescription)activeItem.Tag;
    129164      if (string.IsNullOrEmpty(nameTextBox.Name)) {
    130165        errorProvider.SetError(nameTextBox, "Invalid value");
    131166      } else {
    132         activeProduct.Name = nameTextBox.Text;
    133         activeItem.Text = activeProduct.Name + " " + activeProduct.Version;
    134         activeItem.Name = activeProduct.Name + " " + activeProduct.Version;
    135         errorProvider.SetError(nameTextBox, string.Empty);
    136       }
    137     }
     167        if (activeProduct.Name != nameTextBox.Text) {
     168          activeProduct.Name = nameTextBox.Text;
     169          activeItem.SubItems[0].Text = activeProduct.Name;
     170          errorProvider.SetError(nameTextBox, string.Empty);
     171          MarkProductDirty(activeProduct);
     172        }
     173      }
     174    }
     175
    138176
    139177    private void versionTextBox_TextChanged(object sender, EventArgs e) {
    140       ListViewItem activeItem = (ListViewItem)productsListBox.SelectedItem;
     178      ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0];
    141179      PluginDeploymentService.ProductDescription activeProduct = (PluginDeploymentService.ProductDescription)activeItem.Tag;
    142180      try {
    143         activeProduct.Version = new Version(versionTextBox.Text);
    144         activeItem.Text = activeProduct.Name + " " + activeProduct.Version;
    145         activeItem.Name = activeProduct.Name + " " + activeProduct.Version;
    146         errorProvider.SetError(versionTextBox, string.Empty);
     181        var newVersion = new Version(versionTextBox.Text);
     182        if (activeProduct.Version != newVersion) {
     183          activeProduct.Version = newVersion;
     184          activeItem.SubItems[1].Text = versionTextBox.Text;
     185          errorProvider.SetError(versionTextBox, string.Empty);
     186          MarkProductDirty(activeProduct);
     187        }
    147188      }
    148189      catch (OverflowException ex) {
     
    157198      }
    158199    }
     200
     201    private void pluginsListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
     202      var pluginItem = e.Item;
     203      var activePlugin = (IPluginDescription)pluginItem.Tag;
     204      ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0];
     205      PluginDeploymentService.ProductDescription activeProduct = (PluginDeploymentService.ProductDescription)activeItem.Tag;
     206      if (pluginItem.Checked && !activeProduct.Plugins.Contains(activePlugin)) {
     207        activeProduct.AddPlugin(activePlugin);
     208        MarkProductDirty(activeProduct);
     209      } else if (!pluginItem.Checked && activeProduct.Plugins.Contains(activePlugin)) {
     210        activeProduct.RemovePlugin(activePlugin);
     211        MarkProductDirty(activeProduct);
     212      }
     213    }
     214
     215    private void MarkProductDirty(HeuristicLab.PluginInfrastructure.Advanced.DeploymentService.ProductDescription activeProduct) {
     216      if (!dirtyProducts.Contains(activeProduct)) {
     217        dirtyProducts.Add(activeProduct);
     218        var item = FindItemForProduct(activeProduct);
     219        item.ImageIndex = 1;
     220      }
     221    }
     222
     223    private ListViewItem FindItemForProduct(HeuristicLab.PluginInfrastructure.Advanced.DeploymentService.ProductDescription activeProduct) {
     224      return (from item in productsListView.Items.OfType<ListViewItem>()
     225              let product = item.Tag as PluginDeploymentService.ProductDescription
     226              where product != null
     227              where product == activeProduct
     228              select item).Single();
     229    }
    159230  }
    160231}
Note: See TracChangeset for help on using the changeset viewer.