Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.PluginInfrastructure/Advanced/PluginView.cs @ 3627

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

Refactored class names and fixed a dependency-selection bug. #994 (Clean up plugin infrastructure project)

File size: 5.2 KB
RevLine 
[3090]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
21using System;
[3006]22using System.Collections.Generic;
23using System.ComponentModel;
24using System.Drawing;
25using System.Data;
26using System.Linq;
27using System.Text;
28using System.Windows.Forms;
29using HeuristicLab.PluginInfrastructure;
30using System.IO;
31using HeuristicLab.PluginInfrastructure.Manager;
32
33namespace HeuristicLab.PluginInfrastructure.Advanced {
[3547]34  internal partial class PluginView : Form {
[3573]35    private const string IMAGE_KEY_PLUGIN = "Plugin";
[3006]36    private const string IMAGE_KEY_ASSEMBLY = "Assembly";
37    private const string IMAGE_KEY_FILE = "File";
38    private const string IMAGE_KEY_DOCUMENT = "Document";
39
[3509]40    private IPluginDescription plugin;
[3006]41
42    public PluginView() {
43      InitializeComponent();
44      PopulateImageList();
45    }
46
[3509]47    public PluginView(IPluginDescription plugin) {
[3006]48      InitializeComponent();
49      PopulateImageList();
50
51      this.plugin = plugin;
[3547]52      this.Text = "Plugin Details: " + plugin.ToString();
[3006]53      UpdateControls();
54    }
55
56    private void PopulateImageList() {
[3608]57      pluginsImageList.Images.Add(IMAGE_KEY_PLUGIN, HeuristicLab.PluginInfrastructure.Resources.Resources.plugin_16);
[3573]58      filesImageList.Images.Add(IMAGE_KEY_ASSEMBLY, HeuristicLab.PluginInfrastructure.Resources.Resources.Assembly);
59      filesImageList.Images.Add(IMAGE_KEY_FILE, HeuristicLab.PluginInfrastructure.Resources.Resources.File);
60      filesImageList.Images.Add(IMAGE_KEY_DOCUMENT, HeuristicLab.PluginInfrastructure.Resources.Resources.Document);
[3006]61    }
62
63    public void UpdateControls() {
64      string appDir = Path.GetDirectoryName(Application.ExecutablePath);
65      nameTextBox.Text = plugin.Name;
66      versionTextBox.Text = plugin.Version.ToString();
67      contactTextBox.Text = CombineStrings(plugin.ContactName, plugin.ContactEmail);
[3627]68      toolTip.SetToolTip(contactTextBox, contactTextBox.Text);
[3006]69      descriptionTextBox.Text = plugin.Description;
[3627]70      toolTip.SetToolTip(descriptionTextBox, plugin.Description);
[3509]71      var localPlugin = plugin as PluginDescription;
72      if (localPlugin != null) {
73        stateTextBox.Text = localPlugin.PluginState.ToString();
74        errorTextBox.Text = localPlugin.LoadingErrorInformation;
[3627]75        toolTip.SetToolTip(stateTextBox, stateTextBox.Text + Environment.NewLine + errorTextBox.Text);
76        toolTip.SetToolTip(errorTextBox, errorTextBox.Text);
[3509]77      }
[3006]78      foreach (PluginDescription dependency in plugin.Dependencies) {
[3573]79        var depItem = new ListViewItem(new string[] { dependency.Name, dependency.Version.ToString(), dependency.Description });
[3006]80        depItem.Tag = dependency;
[3573]81        depItem.ImageKey = IMAGE_KEY_PLUGIN;
[3006]82        dependenciesListView.Items.Add(depItem);
83      }
84      foreach (var file in plugin.Files) {
85        string displayedFileName = file.Name.Replace(appDir, string.Empty);
86        displayedFileName = displayedFileName.TrimStart(Path.DirectorySeparatorChar);
87        var fileItem = new ListViewItem(new string[] { displayedFileName, file.Type.ToString() });
88        if (file.Type == PluginFileType.Assembly) {
89          fileItem.ImageKey = IMAGE_KEY_ASSEMBLY;
90        } else if (file.Type == PluginFileType.License) {
91          fileItem.ImageKey = IMAGE_KEY_DOCUMENT;
92        } else fileItem.ImageKey = IMAGE_KEY_FILE;
93        filesListView.Items.Add(fileItem);
94      }
[3624]95      Util.ResizeColumns(dependenciesListView.Columns.OfType<ColumnHeader>());
96      Util.ResizeColumns(filesListView.Columns.OfType<ColumnHeader>());
97
[3627]98      showLicenseButton.Enabled = !string.IsNullOrEmpty(plugin.LicenseText);
[3006]99    }
100
101    private string CombineStrings(string a, string b) {
102      if (string.IsNullOrEmpty(a))
103        // a is empty
104        if (!string.IsNullOrEmpty(b)) return CombineStrings(b, string.Empty);
105        else return string.Empty;
106      // a is not empty
107      else if (string.IsNullOrEmpty(b)) return a;
108      // and b are not empty
109      else return a + ", " + b;
110    }
111
112    private void dependenciesListView_ItemActivate(object sender, EventArgs e) {
113      if (dependenciesListView.SelectedItems.Count > 0) {
114        var dep = (PluginDescription)dependenciesListView.SelectedItems[0].Tag;
115        PluginView view = new PluginView(dep);
[3474]116        view.Show();
[3006]117      }
118    }
[3627]119
120    private void showLicenseButton_Click(object sender, EventArgs e) {
121      LicenseView view = new LicenseView(plugin);
122      view.Show();
123    }
[3006]124  }
125}
Note: See TracBrowser for help on using the repository browser.