1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 | using System;
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using System.ComponentModel;
|
---|
24 | using System.Drawing;
|
---|
25 | using System.Data;
|
---|
26 | using System.Linq;
|
---|
27 | using System.Text;
|
---|
28 | using System.Windows.Forms;
|
---|
29 | using HeuristicLab.PluginInfrastructure.Manager;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.PluginInfrastructure.Advanced {
|
---|
32 | internal partial class LocalPluginManager : UserControl {
|
---|
33 |
|
---|
34 | public event ItemCheckedEventHandler ItemChecked;
|
---|
35 |
|
---|
36 | private BackgroundWorker refreshPluginListBackgroundWorker = new BackgroundWorker();
|
---|
37 |
|
---|
38 | private ListViewGroup enabledPluginsGroup;
|
---|
39 | private ListViewGroup disabledPluginsGroup;
|
---|
40 |
|
---|
41 | public LocalPluginManager() {
|
---|
42 | InitializeComponent();
|
---|
43 |
|
---|
44 | imageListForLocalItems.Images.Add(HeuristicLab.PluginInfrastructure.Resources.Resources.Assembly);
|
---|
45 | imageListForLocalItems.Images.Add(HeuristicLab.PluginInfrastructure.Resources.Resources.Remove);
|
---|
46 |
|
---|
47 | enabledPluginsGroup = localPluginsListView.Groups["activePluginsGroup"];
|
---|
48 | disabledPluginsGroup = localPluginsListView.Groups["disabledPluginsGroup"];
|
---|
49 | }
|
---|
50 |
|
---|
51 | private IEnumerable<PluginDescription> plugins;
|
---|
52 | public IEnumerable<PluginDescription> Plugins {
|
---|
53 | get { return plugins; }
|
---|
54 | set {
|
---|
55 | if (value != plugins) {
|
---|
56 | this.plugins = value;
|
---|
57 | UpdateControl();
|
---|
58 | }
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | public IEnumerable<IPluginDescription> CheckedPlugins {
|
---|
63 | get {
|
---|
64 | return (from item in localPluginsListView.Items.OfType<ListViewItem>()
|
---|
65 | where item.Checked
|
---|
66 | let plugin = item.Tag as IPluginDescription
|
---|
67 | where plugin != null
|
---|
68 | select plugin).ToList();
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | private void UpdateControl() {
|
---|
73 | ClearPluginList();
|
---|
74 | localPluginsListView.SuppressItemCheckedEvents = true;
|
---|
75 | foreach (var plugin in plugins) {
|
---|
76 | var item = CreateListViewItem(plugin);
|
---|
77 | if (plugin.PluginState == PluginState.Enabled) {
|
---|
78 | item.Group = enabledPluginsGroup;
|
---|
79 | } else if (plugin.PluginState == PluginState.Disabled) {
|
---|
80 | item.Group = disabledPluginsGroup;
|
---|
81 | }
|
---|
82 | localPluginsListView.Items.Add(item);
|
---|
83 | }
|
---|
84 | localPluginsListView.SuppressItemCheckedEvents = false;
|
---|
85 | }
|
---|
86 |
|
---|
87 | private void ClearPluginList() {
|
---|
88 | List<ListViewItem> itemsToRemove = new List<ListViewItem>(from item in localPluginsListView.Items.OfType<ListViewItem>()
|
---|
89 | select item);
|
---|
90 | itemsToRemove.ForEach(item => localPluginsListView.Items.Remove(item));
|
---|
91 | }
|
---|
92 |
|
---|
93 | private ListViewItem CreateListViewItem(PluginDescription plugin) {
|
---|
94 | ListViewItem item = new ListViewItem(new string[] { plugin.Name, plugin.Version.ToString(), plugin.Description });
|
---|
95 | item.Tag = plugin;
|
---|
96 | return item;
|
---|
97 | }
|
---|
98 |
|
---|
99 | private void pluginsListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
|
---|
100 | // checked items are marked for removal
|
---|
101 | if (e.Item.Checked) {
|
---|
102 | List<ListViewItem> modifiedItems = new List<ListViewItem>();
|
---|
103 | foreach (ListViewItem item in localPluginsListView.SelectedItems) {
|
---|
104 | var plugin = (IPluginDescription)item.Tag;
|
---|
105 | modifiedItems.Add(item);
|
---|
106 | // also uncheck all dependent plugins
|
---|
107 | foreach (ListViewItem dependentItem in localPluginsListView.Items) {
|
---|
108 | var dependent = (IPluginDescription)dependentItem.Tag;
|
---|
109 | if (!dependentItem.Checked && (from dep in dependent.Dependencies
|
---|
110 | where dep.Name == plugin.Name
|
---|
111 | where dep.Version == plugin.Version
|
---|
112 | select dep).Any()) {
|
---|
113 | modifiedItems.Add(dependentItem);
|
---|
114 | }
|
---|
115 | }
|
---|
116 | }
|
---|
117 | localPluginsListView.CheckItems(modifiedItems);
|
---|
118 | } else {
|
---|
119 | List<ListViewItem> modifiedItems = new List<ListViewItem>();
|
---|
120 | foreach (ListViewItem item in localPluginsListView.SelectedItems) {
|
---|
121 | var plugin = (IPluginDescription)item.Tag;
|
---|
122 | modifiedItems.Add(item);
|
---|
123 | }
|
---|
124 | localPluginsListView.UncheckItems(modifiedItems);
|
---|
125 | }
|
---|
126 | OnItemChecked(e);
|
---|
127 | }
|
---|
128 |
|
---|
129 | private void OnItemChecked(ItemCheckedEventArgs e) {
|
---|
130 | if (ItemChecked != null) ItemChecked(this, e);
|
---|
131 | }
|
---|
132 |
|
---|
133 | private void localPluginsListView_ItemActivate(object sender, EventArgs e) {
|
---|
134 | if (localPluginsListView.SelectedItems.Count > 0) {
|
---|
135 | var plugin = (PluginDescription)localPluginsListView.SelectedItems[0].Tag;
|
---|
136 | PluginView pluginView = new PluginView(plugin);
|
---|
137 | pluginView.ShowInForm();
|
---|
138 | }
|
---|
139 | }
|
---|
140 | }
|
---|
141 | }
|
---|