Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 14579 was 14185, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

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