#region License Information
/* HeuristicLab
* Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using HeuristicLab.PluginInfrastructure.Manager;
namespace HeuristicLab.PluginInfrastructure.Advanced {
internal partial class InstalledPluginsView : InstallationManagerControl {
private const string CheckingPluginsMessage = "Checking for updated plugins...";
private const string NoUpdatesAvailableMessage = "No updates available.";
private ListViewGroup enabledPluginsGroup;
private ListViewGroup disabledPluginsGroup;
private PluginManager pluginManager;
public PluginManager PluginManager {
get { return pluginManager; }
set {
pluginManager = value;
UpdateControl();
}
}
// private InstallationManager installationManager;
// public InstallationManager InstallationManager {
// get { return installationManager; }
// set { installationManager = value; }
// }
public InstalledPluginsView()
: base() {
InitializeComponent();
enabledPluginsGroup = localPluginsListView.Groups["activePluginsGroup"];
disabledPluginsGroup = localPluginsListView.Groups["disabledPluginsGroup"];
pluginImageList.Images.Add(HeuristicLab.PluginInfrastructure.Resources.Plugin);
UpdateControl();
}
#region event handlers for update plugins backgroundworker
// compares for two plugins with same major and minor version if plugin1 is newer than plugin2
private static bool IsNewerThan(IPluginDescription plugin1, IPluginDescription plugin2) {
// newer: build version is higher, or if build version is the same revision is higher
return plugin1.Version.Build > plugin2.Version.Build ||
(plugin1.Version.Build == plugin2.Version.Build && plugin1.Version.Revision > plugin2.Version.Revision);
}
#endregion
private void UpdateControl() {
ClearPluginList();
if (pluginManager != null) {
localPluginsListView.SuppressItemCheckedEvents = true;
foreach (var plugin in pluginManager.Plugins) {
var item = CreateListViewItem(plugin);
if (plugin.PluginState == PluginState.Enabled) {
item.Group = enabledPluginsGroup;
} else if (plugin.PluginState == PluginState.Disabled) {
item.Group = disabledPluginsGroup;
}
localPluginsListView.Items.Add(item);
}
localPluginsListView.SuppressItemCheckedEvents = false;
}
Util.ResizeColumns(localPluginsListView.Columns.OfType());
}
private void ClearPluginList() {
List itemsToRemove = new List(localPluginsListView.Items.OfType());
itemsToRemove.ForEach(item => localPluginsListView.Items.Remove(item));
}
private static ListViewItem CreateListViewItem(PluginDescription plugin) {
ListViewItem item = new ListViewItem(new string[] { plugin.Name, plugin.Version.ToString(), plugin.Description });
item.Tag = plugin;
item.ImageIndex = 0;
return item;
}
private void localPluginsListView_ItemActivate(object sender, EventArgs e) {
if (localPluginsListView.SelectedItems.Count > 0) {
var plugin = (PluginDescription)localPluginsListView.SelectedItems[0].Tag;
PluginView pluginView = new PluginView(plugin);
pluginView.Show(this);
}
}
}
}