Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.PluginInfrastructure/Advanced/LocalPluginManager.cs @ 3031

Last change on this file since 3031 was 3006, checked in by gkronber, 15 years ago

Implemented deployment service on servdev.heuristiclab.com and changed all service references and configurations to point to the service address. Improved GUI of installation manager. Implemented user name authentication and authorization for the deployment service. #860 (Deployment server for plugin installation from web locations)

File size: 3.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9using HeuristicLab.PluginInfrastructure.Manager;
10
11namespace HeuristicLab.PluginInfrastructure.Advanced {
12  public partial class LocalPluginManager : UserControl {
13
14    public event ItemCheckedEventHandler ItemChecked;
15
16    private BackgroundWorker refreshPluginListBackgroundWorker = new BackgroundWorker();
17
18    private ListViewGroup enabledPluginsGroup;
19    private ListViewGroup disabledPluginsGroup;
20
21    public LocalPluginManager() {
22      InitializeComponent();
23
24      imageListForLocalItems.Images.Add(HeuristicLab.PluginInfrastructure.Resources.Resources.Assembly);
25      imageListForLocalItems.Images.Add(HeuristicLab.PluginInfrastructure.Resources.Resources.Remove);
26
27      enabledPluginsGroup = localPluginsListView.Groups["activePluginsGroup"];
28      disabledPluginsGroup = localPluginsListView.Groups["disabledPluginsGroup"];
29    }
30
31    private IEnumerable<PluginDescription> plugins;
32    public IEnumerable<PluginDescription> Plugins {
33      get { return plugins; }
34      set {
35        if (value != plugins) {
36          this.plugins = value;
37          UpdateControl();
38        }
39      }
40    }
41
42    public IEnumerable<IPluginDescription> CheckedPlugins {
43      get {
44        return (from item in localPluginsListView.Items.OfType<ListViewItem>()
45                where item.Checked
46                let plugin = item.Tag as IPluginDescription
47                where plugin != null
48                select plugin).ToList();
49      }
50    }
51
52    private void UpdateControl() {
53      ClearPluginList();
54      foreach (var plugin in plugins) {
55        var item = CreateListViewItem(plugin);
56        if (plugin.PluginState == PluginState.Enabled) {
57          item.Group = enabledPluginsGroup;
58        } else if (plugin.PluginState == PluginState.Disabled) {
59          item.Group = disabledPluginsGroup;
60        }
61        localPluginsListView.Items.Add(item);
62      }
63    }
64
65    private void ClearPluginList() {
66      List<ListViewItem> itemsToRemove = new List<ListViewItem>(from item in localPluginsListView.Items.OfType<ListViewItem>()
67                                                                select item);
68      itemsToRemove.ForEach(item => localPluginsListView.Items.Remove(item));
69    }
70
71    private ListViewItem CreateListViewItem(PluginDescription plugin) {
72      ListViewItem item = new ListViewItem(new string[] { plugin.Name, plugin.Version.ToString(), plugin.Description });
73      item.Tag = plugin;
74      return item;
75    }
76
77    private void pluginsListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
78      // checked items are marked for removal
79      if (e.Item.Checked) {
80        var plugin = (IPluginDescription)e.Item.Tag;
81        foreach (ListViewItem item in localPluginsListView.Items) {
82          var dep = (IPluginDescription)item.Tag;
83          if (!item.Checked && dep.Dependencies.Contains(plugin)) {
84            item.Checked = true;
85          }
86        }
87      }
88      OnItemChecked(e);
89    }
90
91    private void OnItemChecked(ItemCheckedEventArgs e) {
92      if (ItemChecked != null) ItemChecked(this, e);
93    }
94
95    private void localPluginsListView_ItemActivate(object sender, EventArgs e) {
96      if (localPluginsListView.SelectedItems.Count > 0) {
97        var plugin = (PluginDescription)localPluginsListView.SelectedItems[0].Tag;
98        PluginView pluginView = new PluginView(plugin);
99        pluginView.ShowInForm();
100      }
101    }
102  }
103}
Note: See TracBrowser for help on using the repository browser.