#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.Linq;
using System.Windows.Forms;
using HeuristicLab.PluginInfrastructure.Manager;
namespace HeuristicLab.PluginInfrastructure.UI {
internal partial class InstalledPluginsView : InstallationManagerControl {
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(Resources.Plugin);
UpdateControl();
}
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);
}
}
}
}