Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3045


Ignore:
Timestamp:
03/15/10 19:34:35 (15 years ago)
Author:
gkronber
Message:

Worked on look and feel of product editor. #891 (Refactor GUI for plugin management)

Location:
branches/DeploymentServer Prototype/HeuristicLab.Services/HeuristicLab.DeploymentService.AdminClient
Files:
7 edited
3 copied

Legend:

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

    r3015 r3045  
    9494      <DependentUpon>PluginComparisonView.cs</DependentUpon>
    9595    </Compile>
     96    <Compile Include="PluginEditor.cs">
     97      <SubType>UserControl</SubType>
     98    </Compile>
     99    <Compile Include="PluginEditor.Designer.cs">
     100      <DependentUpon>PluginEditor.cs</DependentUpon>
     101    </Compile>
     102    <Compile Include="PluginListView.cs">
     103      <SubType>UserControl</SubType>
     104    </Compile>
     105    <Compile Include="PluginListView.Designer.cs">
     106      <DependentUpon>PluginListView.cs</DependentUpon>
     107    </Compile>
    96108    <Compile Include="PluginView.cs">
    97109      <SubType>UserControl</SubType>
     
    113125    <Compile Include="MainForm.cs">
    114126      <SubType>Form</SubType>
    115     </Compile>
    116     <Compile Include="PluginListView.cs">
    117       <SubType>UserControl</SubType>
    118     </Compile>
    119     <Compile Include="PluginListView.Designer.cs">
    120       <DependentUpon>PluginListView.cs</DependentUpon>
    121127    </Compile>
    122128    <Compile Include="Properties\AssemblyInfo.cs" />
     
    157163      <DependentUpon>PluginComparisonView.cs</DependentUpon>
    158164    </EmbeddedResource>
     165    <EmbeddedResource Include="PluginEditor.resx">
     166      <DependentUpon>PluginEditor.cs</DependentUpon>
     167    </EmbeddedResource>
     168    <EmbeddedResource Include="PluginListView.resx">
     169      <DependentUpon>PluginListView.cs</DependentUpon>
     170    </EmbeddedResource>
    159171    <EmbeddedResource Include="PluginView.resx">
    160172      <DependentUpon>PluginView.cs</DependentUpon>
     
    162174    <EmbeddedResource Include="ProductEditor.resx">
    163175      <DependentUpon>ProductEditor.cs</DependentUpon>
    164     </EmbeddedResource>
    165     <EmbeddedResource Include="PluginListView.resx">
    166       <DependentUpon>PluginListView.cs</DependentUpon>
    167176    </EmbeddedResource>
    168177  </ItemGroup>
  • branches/DeploymentServer Prototype/HeuristicLab.Services/HeuristicLab.DeploymentService.AdminClient/MainForm.cs

    r2922 r3045  
    1616    protected override void OnInitialized(EventArgs e) {
    1717      base.OnInitialized(e);
    18       (new PluginListView()).Show();
     18      (new PluginEditor()).Show();
    1919    }
    2020
  • branches/DeploymentServer Prototype/HeuristicLab.Services/HeuristicLab.DeploymentService.AdminClient/OpenServerProductsEditMenuItem.cs

    r2802 r3045  
    88  class OpenServerProductsEditorMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, IUserInterfaceItemProvider {
    99    public override string Name {
    10       get { return "Edit products"; }
     10      get { return "Edit Products"; }
    1111    }
    1212
    1313    public override IEnumerable<string> Structure {
    14       get { return new string[] { "Plugin server" }; }
     14      get { return new string[] { "Plugin Server" }; }
    1515    }
    1616
  • branches/DeploymentServer Prototype/HeuristicLab.Services/HeuristicLab.DeploymentService.AdminClient/PluginEditor.Designer.cs

    r3038 r3045  
    11namespace HeuristicLab.DeploymentService.AdminClient {
    2   partial class PluginListView {
     2  partial class PluginEditor {
    33    /// <summary>
    44    /// Required designer variable.
  • branches/DeploymentServer Prototype/HeuristicLab.Services/HeuristicLab.DeploymentService.AdminClient/PluginEditor.cs

    r3038 r3045  
    1616
    1717namespace HeuristicLab.DeploymentService.AdminClient {
    18   public partial class PluginListView : HeuristicLab.MainForm.WindowsForms.View {
     18  public partial class PluginEditor : HeuristicLab.MainForm.WindowsForms.View {
    1919    private Dictionary<IPluginDescription, PluginDeploymentService.PluginDescription> localAndServerPlugins;
    2020    private BackgroundWorker pluginUploadWorker;
    2121    private BackgroundWorker updateServerPluginsWorker;
    2222
    23     public PluginListView() {
     23    public PluginEditor() {
    2424      InitializeComponent();
    2525      imageList.Images.Add(HeuristicLab.Common.Resources.VS2008ImageLibrary.Assembly);
     
    156156    }
    157157
    158     private void listView_ItemChecked(object sender, ItemCheckedEventArgs e) {
     158    private void listView_ItemChecked(object sender, ItemCheckedEventArgs e) {     
    159159      // also check all dependencies
    160160      if (e.Item.Checked) {
  • branches/DeploymentServer Prototype/HeuristicLab.Services/HeuristicLab.DeploymentService.AdminClient/PluginListView.Designer.cs

    r3015 r3045  
    1 namespace HeuristicLab.DeploymentService.AdminClient {
    2   partial class PluginListView {
    3     /// <summary>
    4     /// Required designer variable.
    5     /// </summary>
    6     private System.ComponentModel.IContainer components = null;
     1namespace HeuristicLab.DeploymentService.AdminClient
     2{
     3  partial class PluginListView
     4  {
     5    /// <summary>
     6    /// Required designer variable.
     7    /// </summary>
     8    private System.ComponentModel.IContainer components = null;
    79
    8     /// <summary>
    9     /// Clean up any resources being used.
    10     /// </summary>
    11     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    12     protected override void Dispose(bool disposing) {
    13       if (disposing && (components != null)) {
    14         components.Dispose();
    15       }
    16       base.Dispose(disposing);
    17     }
     10    /// <summary>
     11    /// Clean up any resources being used.
     12    /// </summary>
     13    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
     14    protected override void Dispose(bool disposing)
     15    {
     16      if (disposing && (components != null))
     17      {
     18        components.Dispose();
     19      }
     20      base.Dispose(disposing);
     21    }
    1822
    19     #region Component Designer generated code
     23    #region Component Designer generated code
    2024
    21     /// <summary>
    22     /// Required method for Designer support - do not modify
    23     /// the contents of this method with the code editor.
    24     /// </summary>
    25     private void InitializeComponent() {
    26       this.components = new System.ComponentModel.Container();
     25    /// <summary>
     26    /// Required method for Designer support - do not modify
     27    /// the contents of this method with the code editor.
     28    /// </summary>
     29    private void InitializeComponent()
     30    {
    2731      this.listView = new System.Windows.Forms.ListView();
    2832      this.nameHeader = new System.Windows.Forms.ColumnHeader();
    29       this.localVersion = new System.Windows.Forms.ColumnHeader();
    30       this.serverVersion = new System.Windows.Forms.ColumnHeader();
    31       this.imageList = new System.Windows.Forms.ImageList(this.components);
    32       this.refreshButton = new System.Windows.Forms.Button();
    33       this.uploadButton = new System.Windows.Forms.Button();
     33      this.versionHeader = new System.Windows.Forms.ColumnHeader();
    3434      this.SuspendLayout();
    3535      //
    3636      // listView
    3737      //
    38       this.listView.Activation = System.Windows.Forms.ItemActivation.TwoClick;
    39       this.listView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    40                   | System.Windows.Forms.AnchorStyles.Left)
    41                   | System.Windows.Forms.AnchorStyles.Right)));
    4238      this.listView.CheckBoxes = true;
    4339      this.listView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
    4440            this.nameHeader,
    45             this.localVersion,
    46             this.serverVersion});
    47       this.listView.Enabled = false;
     41            this.versionHeader});
     42      this.listView.Dock = System.Windows.Forms.DockStyle.Fill;
    4843      this.listView.FullRowSelect = true;
    49       this.listView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
    50       this.listView.Location = new System.Drawing.Point(0, 30);
     44      this.listView.Location = new System.Drawing.Point(0, 0);
    5145      this.listView.Name = "listView";
    52       this.listView.ShowGroups = false;
    53       this.listView.Size = new System.Drawing.Size(536, 446);
    54       this.listView.StateImageList = this.imageList;
     46      this.listView.Size = new System.Drawing.Size(341, 320);
    5547      this.listView.TabIndex = 0;
    5648      this.listView.UseCompatibleStateImageBehavior = false;
    5749      this.listView.View = System.Windows.Forms.View.Details;
    58       this.listView.ItemActivate += new System.EventHandler(this.listView_ItemActivate);
    5950      this.listView.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.listView_ItemChecked);
    6051      //
     
    6253      //
    6354      this.nameHeader.Text = "Name";
    64       this.nameHeader.Width = 188;
    6555      //
    66       // localVersion
     56      // versionHeader
    6757      //
    68       this.localVersion.Text = "Local version";
    69       this.localVersion.Width = 100;
    70       //
    71       // serverVersion
    72       //
    73       this.serverVersion.Text = "Server version";
    74       this.serverVersion.Width = 100;
    75       //
    76       // imageList
    77       //
    78       this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
    79       this.imageList.ImageSize = new System.Drawing.Size(16, 16);
    80       this.imageList.TransparentColor = System.Drawing.Color.Transparent;
    81       //
    82       // refreshButton
    83       //
    84       this.refreshButton.Location = new System.Drawing.Point(3, 3);
    85       this.refreshButton.Name = "refreshButton";
    86       this.refreshButton.Size = new System.Drawing.Size(75, 23);
    87       this.refreshButton.TabIndex = 6;
    88       this.refreshButton.Text = "Refresh";
    89       this.refreshButton.UseVisualStyleBackColor = true;
    90       this.refreshButton.Click += new System.EventHandler(this.refreshButton_Click);
    91       //
    92       // uploadButton
    93       //
    94       this.uploadButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    95       this.uploadButton.Location = new System.Drawing.Point(3, 482);
    96       this.uploadButton.Name = "uploadButton";
    97       this.uploadButton.Size = new System.Drawing.Size(75, 23);
    98       this.uploadButton.TabIndex = 7;
    99       this.uploadButton.Text = "Upload";
    100       this.uploadButton.UseVisualStyleBackColor = true;
    101       this.uploadButton.Click += new System.EventHandler(this.uploadButton_Click);
     58      this.versionHeader.Text = "Version";
    10259      //
    10360      // PluginListView
     
    10562      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    10663      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    107       this.Controls.Add(this.uploadButton);
    108       this.Controls.Add(this.refreshButton);
    10964      this.Controls.Add(this.listView);
    11065      this.Name = "PluginListView";
    111       this.Size = new System.Drawing.Size(539, 508);
     66      this.Size = new System.Drawing.Size(341, 320);
    11267      this.ResumeLayout(false);
    11368
    114     }
     69    }
    11570
    116     #endregion
     71    #endregion
    11772
    11873    private System.Windows.Forms.ListView listView;
    11974    private System.Windows.Forms.ColumnHeader nameHeader;
    120     private System.Windows.Forms.ColumnHeader localVersion;
    121     private System.Windows.Forms.ColumnHeader serverVersion;
    122     private System.Windows.Forms.Button refreshButton;
    123     private System.Windows.Forms.Button uploadButton;
    124     private System.Windows.Forms.ImageList imageList;
    125   }
     75    private System.Windows.Forms.ColumnHeader versionHeader;
     76  }
    12677}
  • branches/DeploymentServer Prototype/HeuristicLab.Services/HeuristicLab.DeploymentService.AdminClient/PluginListView.cs

    r3015 r3045  
    77using System.Text;
    88using System.Windows.Forms;
    9 using HeuristicLab.MainForm;
    109using HeuristicLab.PluginInfrastructure;
    11 using PluginDeploymentService = HeuristicLab.PluginInfrastructure.Advanced.DeploymentService;
    12 using HeuristicLab.PluginInfrastructure.Manager;
    13 using System.ServiceModel;
    14 using ICSharpCode.SharpZipLib.Zip;
    15 using System.IO;
    1610
    1711namespace HeuristicLab.DeploymentService.AdminClient {
    18   public partial class PluginListView : HeuristicLab.MainForm.WindowsForms.View {
    19     private Dictionary<IPluginDescription, PluginDeploymentService.PluginDescription> localAndServerPlugins;
    20     private BackgroundWorker pluginUploadWorker;
    21     private BackgroundWorker updateServerPluginsWorker;
     12  public partial class PluginListView : UserControl {
     13    public event ItemCheckedEventHandler ItemChecked;
     14
     15    private IEnumerable<IPluginDescription> plugins;
     16    public IEnumerable<IPluginDescription> Plugins {
     17      get { return plugins; }
     18      set {
     19        plugins = value;
     20        UpdateControls();
     21      }
     22    }
     23
     24    public IEnumerable<IPluginDescription> CheckedPlugins {
     25      get {
     26        return from item in listView.Items.OfType<ListViewItem>()
     27               where item.Checked
     28               select item.Tag as IPluginDescription;
     29      }
     30    }
     31
     32    private bool suppressItemCheckedEvents = false;
    2233
    2334    public PluginListView() {
    2435      InitializeComponent();
    25       imageList.Images.Add(HeuristicLab.Common.Resources.VS2008ImageLibrary.Assembly);
    26       imageList.Images.Add(HeuristicLab.Common.Resources.VS2008ImageLibrary.ArrowUp);
    27       Caption = "Plugins";
    28 
    29       localAndServerPlugins = new Dictionary<IPluginDescription, PluginDeploymentService.PluginDescription>();
    30 
    31       #region initialize backgroundworkers
    32       pluginUploadWorker = new BackgroundWorker();
    33       pluginUploadWorker.DoWork += new DoWorkEventHandler(pluginUploadWorker_DoWork);
    34       pluginUploadWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(pluginUploadWorker_RunWorkerCompleted);
    35 
    36       updateServerPluginsWorker = new BackgroundWorker();
    37       updateServerPluginsWorker.DoWork += new DoWorkEventHandler(updateServerPluginsWorker_DoWork);
    38       updateServerPluginsWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(updateServerPluginsWorker_RunWorkerCompleted);
    39       #endregion
    4036    }
    4137
    42     #region refresh plugins from server backgroundworker
    43     void updateServerPluginsWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
    44       if (!e.Cancelled && e.Result != null) {
    45         // refresh local plugins
    46         localAndServerPlugins.Clear();
    47         foreach (var plugin in ApplicationManager.Manager.Plugins) {
    48           localAndServerPlugins.Add(plugin, null);
    49         }
    50         // refresh server plugins (find matching local plugins)
    51         var plugins = (PluginDeploymentService.PluginDescription[])e.Result;
    52         foreach (var plugin in plugins) {
    53           var matchingLocalPlugin = (from localPlugin in localAndServerPlugins.Keys
    54                                      where localPlugin.Name == plugin.Name
    55                                      where localPlugin.Version == localPlugin.Version
    56                                      select localPlugin).SingleOrDefault();
    57           if (matchingLocalPlugin != null) {
    58             localAndServerPlugins[matchingLocalPlugin] = plugin;
    59           }
    60         }
    61         // refresh the list view with plugins
    62         listView.Items.Clear();
    63         foreach (var pair in localAndServerPlugins) {
    64           var item = MakeListViewItem(pair.Key);
    65           listView.Items.Add(item);
    66         }
    67         UpdateControlsConnectedState();
    68       } else {
    69         UpdateControlsDisconnectedState();
    70       }
    71       // make sure cursor is set correctly
    72       Cursor = Cursors.Default;
    73     }
    74 
    75     void updateServerPluginsWorker_DoWork(object sender, DoWorkEventArgs e) {
    76       try {
    77         var client = PluginDeploymentService.UpdateClientFactory.CreateClient();
    78         e.Result = client.GetPlugins();
    79         e.Cancel = false;
    80       }
    81       catch (EndpointNotFoundException) {
    82         e.Result = null;
    83         e.Cancel = true;
    84       }
    85       catch (FaultException) {
    86         e.Result = null;
    87         e.Cancel = true;
    88       }
    89     }
    90     #endregion
    91 
    92     #region upload plugins to server backgroundworker
    93     void pluginUploadWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
    94       Cursor = Cursors.Default;
    95       if (e.Cancelled) {
    96         UpdateControlsDisconnectedState();
    97       } else {
    98         UpdateControlsConnectedState();
    99         // start another async call to refresh plugin information from server
    100         RefreshPluginsAsync();
     38    public void CheckPlugin(IPluginDescription plugin) {
     39      var items = FindItemsForPlugin(plugin);
     40      if (items.Count() == 0) throw new ArgumentException();
     41      var item = items.Single();
     42      if (!item.Checked) {
     43        suppressItemCheckedEvents = true;
     44        item.Checked = true;
     45        suppressItemCheckedEvents = false;
    10146      }
    10247    }
    10348
    104     void pluginUploadWorker_DoWork(object sender, DoWorkEventArgs e) {
    105       try {
    106         var selectedPlugins = (IEnumerable<IPluginDescription>)e.Argument;
    107         PluginDeploymentService.AdminClient adminClient = PluginDeploymentService.AdminClientFactory.CreateClient();
    108 
    109         foreach (var plugin in IteratePlugins(selectedPlugins)) {
    110          adminClient.DeployPlugin(MakePluginDescription(plugin), CreateZipPackage(plugin));
     49    private void UpdateControls() {
     50      if (plugins != null) {
     51        listView.Items.Clear();
     52        suppressItemCheckedEvents = true;
     53        foreach (var plugin in plugins) {
     54          listView.Items.Add(CreateListViewItem(plugin));
    11155        }
    112         e.Cancel = false;
    113       }
    114       catch (EndpointNotFoundException) {
    115         e.Cancel = true;
    116       }
    117       catch (FaultException) {
    118         e.Cancel = true;
    119       }
    120     }
    121     #endregion
    122 
    123 
    124     #region button events
    125     private void uploadButton_Click(object sender, EventArgs e) {
    126       var selectedPlugins = from item in listView.Items.Cast<ListViewItem>()
    127                             where item.Checked
    128                             where item.Tag is IPluginDescription
    129                             select item.Tag as IPluginDescription;
    130       if (selectedPlugins.Count() > 0) {
    131         Cursor = Cursors.AppStarting;
    132         DisableControl();
    133         pluginUploadWorker.RunWorkerAsync(selectedPlugins.ToList());
     56        suppressItemCheckedEvents = false;
    13457      }
    13558    }
    13659
    137     private void connectButton_Click(object sender, EventArgs e) {
    138       var connectionSetupView = new ConnectionSetupView();
    139       connectionSetupView.Show();
     60    private ListViewItem CreateListViewItem(IPluginDescription plugin) {
     61      var item = new ListViewItem(new string[] { plugin.Name, plugin.Version.ToString() });
     62      item.Tag = plugin;
     63      return item;
    14064    }
    14165
    142     private void refreshButton_Click(object sender, EventArgs e) {
    143       DisableControl();
    144       RefreshPluginsAsync();
     66    private void listView_ItemChecked(object sender, ItemCheckedEventArgs e) {
     67      if (suppressItemCheckedEvents) return;
     68      if (e.Item.Checked) {
     69        // also check all dependencies
     70        suppressItemCheckedEvents = true;
     71        var dependencies = GetAllDependencies(e.Item.Tag as IPluginDescription);
     72        foreach (var dep in dependencies) {
     73          var item = FindItemsForPlugin(dep).Single();
     74          if (!item.Checked) item.Checked = true;
     75        }
     76        suppressItemCheckedEvents = false;
     77      } else {
     78        // also uncheck all dependencies
     79        suppressItemCheckedEvents = true;
     80        var dependents = GetAllDependents(e.Item.Tag as IPluginDescription);
     81        foreach (var dep in dependents) {
     82          var item = FindItemsForPlugin(dep).Single();
     83          if (item.Checked) item.Checked = false;
     84        }
     85        suppressItemCheckedEvents = false;
     86      }
     87      OnItemChecked(e);
    14588    }
    14689
    147     #endregion
     90    private IEnumerable<ListViewItem> FindItemsForPlugin(IPluginDescription plugin) {
     91      return from item in listView.Items.OfType<ListViewItem>()
     92             let p = item.Tag as IPluginDescription
     93             where p.Name == plugin.Name
     94             where p.Version == plugin.Version
     95             select item;
     96    }
    14897
    149     #region item list events
    150     private void listView_ItemActivate(object sender, EventArgs e) {
    151       foreach (var item in listView.SelectedItems) {
    152         var plugin = (IPluginDescription)((ListViewItem)item).Tag;
    153         var compView = new PluginComparisonView(plugin, localAndServerPlugins[plugin]);
    154         compView.Show();
     98    private IEnumerable<IPluginDescription> GetAllDependents(IPluginDescription plugin) {
     99      return from p in plugins
     100             let matchingEntries = from dep in GetAllDependencies(p)
     101                                   where dep.Name == plugin.Name
     102                                   where dep.Version == plugin.Version
     103                                   select dep
     104             where matchingEntries.Any()
     105             select p;
     106    }
     107
     108    private IEnumerable<IPluginDescription> GetAllDependencies(IPluginDescription plugin) {
     109      foreach (var dep in plugin.Dependencies) {
     110        foreach (var recDep in GetAllDependencies(dep)) {
     111          yield return recDep;
     112        }
     113        yield return dep;
    155114      }
    156115    }
    157116
    158     private void listView_ItemChecked(object sender, ItemCheckedEventArgs e) {
    159       // also check all dependencies
    160       if (e.Item.Checked) {
    161         uploadButton.Enabled = true;
    162         var plugin = (IPluginDescription)e.Item.Tag;
    163         foreach (var dep in plugin.Dependencies) {
    164           var depItem = FindItemForPlugin(dep);
    165           if (!depItem.Checked) depItem.Checked = true;
    166         }
    167       } else {
    168         uploadButton.Enabled = (from i in listView.Items.Cast<ListViewItem>()
    169                                 where i.Checked
    170                                 select i).Any();
    171         // also uncheck all dependent plugins
    172         var plugin = (IPluginDescription)e.Item.Tag;
    173         foreach (ListViewItem item in listView.Items) {
    174           var dep = (IPluginDescription)item.Tag;
    175           if (dep.Dependencies.Contains(plugin) && item.Checked) {
    176             item.Checked = false;
    177           }
    178         }
    179       }
     117    private void OnItemChecked(ItemCheckedEventArgs e) {
     118      if (ItemChecked != null && !suppressItemCheckedEvents) ItemChecked(this, e);
    180119    }
    181     #endregion
    182 
    183     #region helper methods
    184     private byte[] CreateZipPackage(IPluginDescription plugin) {
    185       using (MemoryStream stream = new MemoryStream()) {
    186         ZipFile zipFile = new ZipFile(stream);
    187         zipFile.BeginUpdate();
    188         foreach (var file in plugin.Files) {
    189           zipFile.Add(file.Name);
    190         }
    191         zipFile.CommitUpdate();
    192         stream.Seek(0, SeekOrigin.Begin);
    193         return stream.GetBuffer();
    194       }
    195     }
    196 
    197     private ListViewItem MakeListViewItem(IPluginDescription plugin) {
    198       ListViewItem item;
    199       if (localAndServerPlugins[plugin] != null) {
    200         item = new ListViewItem(new string[] { plugin.Name, plugin.Version.ToString(), localAndServerPlugins[plugin].Version.ToString() });
    201       } else {
    202         item = new ListViewItem(new string[] { plugin.Name, plugin.Version.ToString(), string.Empty });
    203       }
    204       item.Tag = plugin;
    205       item.Checked = false;
    206       return item;
    207     }
    208 
    209     private ListViewItem FindItemForPlugin(IPluginDescription dep) {
    210       return (from i in listView.Items.Cast<ListViewItem>()
    211               where i.Tag == dep
    212               select i).Single();
    213     }
    214 
    215     private PluginDeploymentService.PluginDescription MakePluginDescription(IPluginDescription plugin) {
    216       var dependencies = from dep in plugin.Dependencies
    217                          select MakePluginDescription(dep);
    218       return new PluginDeploymentService.PluginDescription(plugin.Name, plugin.Version, dependencies, plugin.ContactName, plugin.ContactEmail, plugin.LicenseText);
    219     }
    220 
    221     private IEnumerable<IPluginDescription> IteratePlugins(IEnumerable<IPluginDescription> plugins) {
    222       foreach (var plugin in plugins) {
    223         foreach (var dependency in IteratePlugins(plugin.Dependencies)) {
    224           yield return dependency;
    225         }
    226         yield return plugin;
    227       }
    228     }
    229 
    230     // start background process to refresh the plugin list (local and server)
    231     private void RefreshPluginsAsync() {
    232       Cursor = Cursors.AppStarting;
    233       DisableControl();
    234       updateServerPluginsWorker.RunWorkerAsync();
    235     }
    236 
    237     // is called by all methods that start a background process
    238     // controls must be enabled manuall again when the backgroundworker finishes
    239     private void DisableControl() {
    240       MainFormManager.GetMainForm<MainForm>().ShowProgressBar();
    241       foreach (Control ctrl in Controls)
    242         ctrl.Enabled = false;
    243     }
    244 
    245     private void UpdateControlsDisconnectedState() {
    246       refreshButton.Enabled = false;
    247 
    248       localAndServerPlugins.Clear();
    249       listView.Items.Clear();
    250       listView.Enabled = false;
    251       uploadButton.Enabled = false;
    252       MainFormManager.GetMainForm<MainForm>().HideProgressBar();
    253     }
    254 
    255     private void UpdateControlsConnectedState() {
    256       refreshButton.Enabled = true;
    257       listView.Enabled = true;
    258       uploadButton.Enabled = false;
    259       MainFormManager.GetMainForm<MainForm>().HideProgressBar();
    260     }
    261     #endregion
    262120  }
    263121}
  • branches/DeploymentServer Prototype/HeuristicLab.Services/HeuristicLab.DeploymentService.AdminClient/ProductEditor.Designer.cs

    r3015 r3045  
    2929      this.newProductButton = new System.Windows.Forms.Button();
    3030      this.splitContainer = new System.Windows.Forms.SplitContainer();
     31      this.productsListView = new System.Windows.Forms.ListView();
     32      this.productNameHeader = new System.Windows.Forms.ColumnHeader();
     33      this.productVersionHeader = new System.Windows.Forms.ColumnHeader();
     34      this.productImageList = new System.Windows.Forms.ImageList(this.components);
     35      this.pluginImageList = new System.Windows.Forms.ImageList(this.components);
    3136      this.pluginsLabel = new System.Windows.Forms.Label();
    3237      this.versionTextBox = new System.Windows.Forms.TextBox();
     
    3540      this.nameLabel = new System.Windows.Forms.Label();
    3641      this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components);
    37       this.productsListView = new System.Windows.Forms.ListView();
    38       this.productNameHeader = new System.Windows.Forms.ColumnHeader();
    39       this.productVersionHeader = new System.Windows.Forms.ColumnHeader();
    40       this.productImageList = new System.Windows.Forms.ImageList(this.components);
    41       this.pluginImageList = new System.Windows.Forms.ImageList(this.components);
    42       this.pluginsListView = new System.Windows.Forms.ListView();
    43       this.pluginNameHeader = new System.Windows.Forms.ColumnHeader();
    44       this.pluginVersionHeader = new System.Windows.Forms.ColumnHeader();
     42      this.pluginListView = new HeuristicLab.DeploymentService.AdminClient.PluginListView();
    4543      this.splitContainer.Panel1.SuspendLayout();
    4644      this.splitContainer.Panel2.SuspendLayout();
     
    6159      // saveButton
    6260      //
    63       this.saveButton.Location = new System.Drawing.Point(84, 3);
     61      this.saveButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     62      this.saveButton.Location = new System.Drawing.Point(3, 365);
    6463      this.saveButton.Name = "saveButton";
    6564      this.saveButton.Size = new System.Drawing.Size(96, 23);
     
    7170      // newProductButton
    7271      //
    73       this.newProductButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    74       this.newProductButton.Location = new System.Drawing.Point(3, 365);
     72      this.newProductButton.Location = new System.Drawing.Point(84, 3);
    7573      this.newProductButton.Name = "newProductButton";
    7674      this.newProductButton.Size = new System.Drawing.Size(91, 23);
     
    9189      //
    9290      this.splitContainer.Panel1.Controls.Add(this.productsListView);
    93       this.splitContainer.Panel1.Controls.Add(this.newProductButton);
     91      this.splitContainer.Panel1.Controls.Add(this.saveButton);
    9492      //
    9593      // splitContainer.Panel2
    9694      //
    97       this.splitContainer.Panel2.Controls.Add(this.pluginsListView);
     95      this.splitContainer.Panel2.Controls.Add(this.pluginListView);
    9896      this.splitContainer.Panel2.Controls.Add(this.pluginsLabel);
    9997      this.splitContainer.Panel2.Controls.Add(this.versionTextBox);
     
    104102      this.splitContainer.SplitterDistance = 319;
    105103      this.splitContainer.TabIndex = 4;
    106       //
    107       // pluginsLabel
    108       //
    109       this.pluginsLabel.AutoSize = true;
    110       this.pluginsLabel.Location = new System.Drawing.Point(11, 69);
    111       this.pluginsLabel.Name = "pluginsLabel";
    112       this.pluginsLabel.Size = new System.Drawing.Size(44, 13);
    113       this.pluginsLabel.TabIndex = 6;
    114       this.pluginsLabel.Text = "Plugins:";
    115       //
    116       // versionTextBox
    117       //
    118       this.versionTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    119                   | System.Windows.Forms.AnchorStyles.Right)));
    120       this.versionTextBox.Location = new System.Drawing.Point(68, 29);
    121       this.versionTextBox.Name = "versionTextBox";
    122       this.versionTextBox.Size = new System.Drawing.Size(233, 20);
    123       this.versionTextBox.TabIndex = 5;
    124       this.versionTextBox.TextChanged += new System.EventHandler(this.versionTextBox_TextChanged);
    125       //
    126       // versionLabel
    127       //
    128       this.versionLabel.AutoSize = true;
    129       this.versionLabel.Location = new System.Drawing.Point(10, 32);
    130       this.versionLabel.Name = "versionLabel";
    131       this.versionLabel.Size = new System.Drawing.Size(45, 13);
    132       this.versionLabel.TabIndex = 4;
    133       this.versionLabel.Text = "Version:";
    134       //
    135       // nameTextBox
    136       //
    137       this.nameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    138                   | System.Windows.Forms.AnchorStyles.Right)));
    139       this.nameTextBox.Location = new System.Drawing.Point(68, 3);
    140       this.nameTextBox.Name = "nameTextBox";
    141       this.nameTextBox.Size = new System.Drawing.Size(233, 20);
    142       this.nameTextBox.TabIndex = 3;
    143       this.nameTextBox.TextChanged += new System.EventHandler(this.nameTextBox_TextChanged);
    144       //
    145       // nameLabel
    146       //
    147       this.nameLabel.AutoSize = true;
    148       this.nameLabel.Location = new System.Drawing.Point(17, 6);
    149       this.nameLabel.Name = "nameLabel";
    150       this.nameLabel.Size = new System.Drawing.Size(38, 13);
    151       this.nameLabel.TabIndex = 2;
    152       this.nameLabel.Text = "Name:";
    153       //
    154       // errorProvider
    155       //
    156       this.errorProvider.ContainerControl = this;
    157104      //
    158105      // productsListView
     
    197144      this.pluginImageList.TransparentColor = System.Drawing.Color.Transparent;
    198145      //
    199       // pluginsListView
    200       //
    201       this.pluginsListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     146      // pluginsLabel
     147      //
     148      this.pluginsLabel.AutoSize = true;
     149      this.pluginsLabel.Location = new System.Drawing.Point(11, 69);
     150      this.pluginsLabel.Name = "pluginsLabel";
     151      this.pluginsLabel.Size = new System.Drawing.Size(44, 13);
     152      this.pluginsLabel.TabIndex = 6;
     153      this.pluginsLabel.Text = "Plugins:";
     154      //
     155      // versionTextBox
     156      //
     157      this.versionTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     158                  | System.Windows.Forms.AnchorStyles.Right)));
     159      this.versionTextBox.Location = new System.Drawing.Point(68, 29);
     160      this.versionTextBox.Name = "versionTextBox";
     161      this.versionTextBox.Size = new System.Drawing.Size(233, 20);
     162      this.versionTextBox.TabIndex = 5;
     163      this.versionTextBox.TextChanged += new System.EventHandler(this.versionTextBox_TextChanged);
     164      //
     165      // versionLabel
     166      //
     167      this.versionLabel.AutoSize = true;
     168      this.versionLabel.Location = new System.Drawing.Point(10, 32);
     169      this.versionLabel.Name = "versionLabel";
     170      this.versionLabel.Size = new System.Drawing.Size(45, 13);
     171      this.versionLabel.TabIndex = 4;
     172      this.versionLabel.Text = "Version:";
     173      //
     174      // nameTextBox
     175      //
     176      this.nameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     177                  | System.Windows.Forms.AnchorStyles.Right)));
     178      this.nameTextBox.Location = new System.Drawing.Point(68, 3);
     179      this.nameTextBox.Name = "nameTextBox";
     180      this.nameTextBox.Size = new System.Drawing.Size(233, 20);
     181      this.nameTextBox.TabIndex = 3;
     182      this.nameTextBox.TextChanged += new System.EventHandler(this.nameTextBox_TextChanged);
     183      //
     184      // nameLabel
     185      //
     186      this.nameLabel.AutoSize = true;
     187      this.nameLabel.Location = new System.Drawing.Point(17, 6);
     188      this.nameLabel.Name = "nameLabel";
     189      this.nameLabel.Size = new System.Drawing.Size(38, 13);
     190      this.nameLabel.TabIndex = 2;
     191      this.nameLabel.Text = "Name:";
     192      //
     193      // errorProvider
     194      //
     195      this.errorProvider.ContainerControl = this;
     196      //
     197      // pluginListView
     198      //
     199      this.pluginListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    202200                  | System.Windows.Forms.AnchorStyles.Left)
    203201                  | System.Windows.Forms.AnchorStyles.Right)));
    204       this.pluginsListView.CheckBoxes = true;
    205       this.pluginsListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
    206             this.pluginNameHeader,
    207             this.pluginVersionHeader});
    208       this.pluginsListView.Location = new System.Drawing.Point(3, 85);
    209       this.pluginsListView.Name = "pluginsListView";
    210       this.pluginsListView.Size = new System.Drawing.Size(333, 303);
    211       this.pluginsListView.SmallImageList = this.pluginImageList;
    212       this.pluginsListView.TabIndex = 7;
    213       this.pluginsListView.UseCompatibleStateImageBehavior = false;
    214       this.pluginsListView.View = System.Windows.Forms.View.Details;
    215       this.pluginsListView.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.pluginsListView_ItemChecked);
    216       //
    217       // pluginNameHeader
    218       //
    219       this.pluginNameHeader.Text = "Name";
    220       this.pluginNameHeader.Width = 220;
    221       //
    222       // pluginVersionHeader
    223       //
    224       this.pluginVersionHeader.Text = "Version";
    225       this.pluginVersionHeader.Width = 120;
     202      this.pluginListView.Location = new System.Drawing.Point(3, 85);
     203      this.pluginListView.Name = "pluginListView";
     204      this.pluginListView.Plugins = null;
     205      this.pluginListView.Size = new System.Drawing.Size(330, 303);
     206      this.pluginListView.TabIndex = 7;
     207      this.pluginListView.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.pluginListView_ItemChecked);
    226208      //
    227209      // ProductEditor
     
    230212      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    231213      this.Controls.Add(this.splitContainer);
    232       this.Controls.Add(this.saveButton);
     214      this.Controls.Add(this.newProductButton);
    233215      this.Controls.Add(this.refreshButton);
    234216      this.Name = "ProductEditor";
     
    260242    private System.Windows.Forms.ImageList productImageList;
    261243    private System.Windows.Forms.ImageList pluginImageList;
    262     private System.Windows.Forms.ListView pluginsListView;
    263     private System.Windows.Forms.ColumnHeader pluginNameHeader;
    264     private System.Windows.Forms.ColumnHeader pluginVersionHeader;
     244    private PluginListView pluginListView;
    265245
    266246  }
  • branches/DeploymentServer Prototype/HeuristicLab.Services/HeuristicLab.DeploymentService.AdminClient/ProductEditor.cs

    r3015 r3045  
    100100      versionTextBox.Text = activeProduct.Version.ToString();
    101101
    102       pluginsListView.Items.Clear();
    103       foreach (PluginDeploymentService.PluginDescription pluginDesc in plugins) {
    104         var matching = from p in activeProduct.Plugins
    105                        where p.Name == pluginDesc.Name
    106                        where p.Version == pluginDesc.Version
    107                        select p;
    108 
    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;
     102      UpdatePluginsListView();
    128103    }
    129104
     
    135110    }
    136111
    137     private void refreshButton_Click(object sender, EventArgs e) {
    138       SetControlsEnabled(false);
    139       Cursor = Cursors.AppStarting;
    140       refreshProductsWorker.RunWorkerAsync();
    141     }
    142 
    143112    private void SetControlsEnabled(bool enabled) {
    144113      saveButton.Enabled = enabled;
    145114      refreshButton.Enabled = enabled;
     115      newProductButton.Enabled = enabled;
    146116      splitContainer.Enabled = enabled;
    147117    }
    148118
     119    #region button event handlers
    149120    private void newProductButton_Click(object sender, EventArgs e) {
    150121      var newProduct = new PluginDeploymentService.ProductDescription("New product", new Version("0.0.0.0"));
     
    158129      uploadChangedProductsWorker.RunWorkerAsync(dirtyProducts);
    159130    }
    160 
     131    private void refreshButton_Click(object sender, EventArgs e) {
     132      SetControlsEnabled(false);
     133      Cursor = Cursors.AppStarting;
     134      refreshProductsWorker.RunWorkerAsync();
     135    }
     136
     137    #endregion
     138
     139    #region textbox changed event handlers
    161140    private void nameTextBox_TextChanged(object sender, EventArgs e) {
    162141      ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0];
     
    198177      }
    199178    }
    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     }
     179    #endregion
     180
     181
     182    #region plugin list view
     183    private void UpdatePluginsListView() {
     184      ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0];
     185      PluginDeploymentService.ProductDescription activeProduct = (PluginDeploymentService.ProductDescription)activeItem.Tag;
     186      pluginListView.Plugins = plugins.OfType<IPluginDescription>();
     187      foreach (var plugin in activeProduct.Plugins) pluginListView.CheckPlugin(plugin);
     188    }
     189
     190    private void pluginListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
     191      ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0];
     192      PluginDeploymentService.ProductDescription activeProduct = (PluginDeploymentService.ProductDescription)activeItem.Tag;
     193      activeProduct.Plugins = pluginListView.CheckedPlugins.Cast<PluginDeploymentService.PluginDescription>().ToArray();
     194      MarkProductDirty(activeProduct);
     195    }
     196    #endregion
    214197
    215198    private void MarkProductDirty(HeuristicLab.PluginInfrastructure.Advanced.DeploymentService.ProductDescription activeProduct) {
     
    220203      }
    221204    }
    222 
    223205    private ListViewItem FindItemForProduct(HeuristicLab.PluginInfrastructure.Advanced.DeploymentService.ProductDescription activeProduct) {
    224206      return (from item in productsListView.Items.OfType<ListViewItem>()
Note: See TracChangeset for help on using the changeset viewer.