1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.ComponentModel;
|
---|
25 | using System.Linq;
|
---|
26 | using System.Windows.Forms;
|
---|
27 | using HeuristicLab.PluginInfrastructure.Manager;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.PluginInfrastructure.Advanced {
|
---|
30 | internal partial class InstalledPluginsView : InstallationManagerControl {
|
---|
31 | private const string CheckingPluginsMessage = "Checking for updated plugins...";
|
---|
32 | private const string NoUpdatesAvailableMessage = "No updates available.";
|
---|
33 |
|
---|
34 | private ListViewGroup enabledPluginsGroup;
|
---|
35 | private ListViewGroup disabledPluginsGroup;
|
---|
36 |
|
---|
37 | private PluginManager pluginManager;
|
---|
38 | public PluginManager PluginManager {
|
---|
39 | get { return pluginManager; }
|
---|
40 | set {
|
---|
41 | pluginManager = value;
|
---|
42 | UpdateControl();
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | // private InstallationManager installationManager;
|
---|
47 | // public InstallationManager InstallationManager {
|
---|
48 | // get { return installationManager; }
|
---|
49 | // set { installationManager = value; }
|
---|
50 | // }
|
---|
51 |
|
---|
52 | public InstalledPluginsView()
|
---|
53 | : base() {
|
---|
54 | InitializeComponent();
|
---|
55 | enabledPluginsGroup = localPluginsListView.Groups["activePluginsGroup"];
|
---|
56 | disabledPluginsGroup = localPluginsListView.Groups["disabledPluginsGroup"];
|
---|
57 | pluginImageList.Images.Add(HeuristicLab.PluginInfrastructure.Resources.Plugin);
|
---|
58 | UpdateControl();
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | #region event handlers for update plugins backgroundworker
|
---|
63 | // compares for two plugins with same major and minor version if plugin1 is newer than plugin2
|
---|
64 | private static bool IsNewerThan(IPluginDescription plugin1, IPluginDescription plugin2) {
|
---|
65 | // newer: build version is higher, or if build version is the same revision is higher
|
---|
66 | return plugin1.Version.Build > plugin2.Version.Build ||
|
---|
67 | (plugin1.Version.Build == plugin2.Version.Build && plugin1.Version.Revision > plugin2.Version.Revision);
|
---|
68 | }
|
---|
69 | #endregion
|
---|
70 |
|
---|
71 | private void UpdateControl() {
|
---|
72 | ClearPluginList();
|
---|
73 | if (pluginManager != null) {
|
---|
74 | localPluginsListView.SuppressItemCheckedEvents = true;
|
---|
75 | foreach (var plugin in pluginManager.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 | Util.ResizeColumns(localPluginsListView.Columns.OfType<ColumnHeader>());
|
---|
87 | }
|
---|
88 |
|
---|
89 | private void ClearPluginList() {
|
---|
90 | List<ListViewItem> itemsToRemove = new List<ListViewItem>(localPluginsListView.Items.OfType<ListViewItem>());
|
---|
91 | itemsToRemove.ForEach(item => localPluginsListView.Items.Remove(item));
|
---|
92 | }
|
---|
93 |
|
---|
94 | private static ListViewItem CreateListViewItem(PluginDescription plugin) {
|
---|
95 | ListViewItem item = new ListViewItem(new string[] { plugin.Name, plugin.Version.ToString(), plugin.Description });
|
---|
96 | item.Tag = plugin;
|
---|
97 | item.ImageIndex = 0;
|
---|
98 | return item;
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 | private void localPluginsListView_ItemActivate(object sender, EventArgs e) {
|
---|
103 | if (localPluginsListView.SelectedItems.Count > 0) {
|
---|
104 | var plugin = (PluginDescription)localPluginsListView.SelectedItems[0].Tag;
|
---|
105 | PluginView pluginView = new PluginView(plugin);
|
---|
106 | pluginView.Show(this);
|
---|
107 | }
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|