Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 9168 was 7259, checked in by swagner, 13 years ago

Updated year of copyrights to 2012 (#1716)

File size: 5.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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;
22using System.IO;
23using System.Linq;
24using System.Windows.Forms;
25using HeuristicLab.PluginInfrastructure.Manager;
26
27namespace HeuristicLab.PluginInfrastructure.Advanced {
28  internal partial class PluginView : Form {
29    private const string IMAGE_KEY_PLUGIN = "Plugin";
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
34    private IPluginDescription plugin;
35
36    public PluginView()
37      : base() {
38      InitializeComponent();
39      PopulateImageList();
40    }
41
42    public PluginView(IPluginDescription plugin)
43      : base() {
44      InitializeComponent();
45      PopulateImageList();
46
47      this.plugin = plugin;
48      this.Text = "Plugin Details: " + plugin.ToString();
49      UpdateControls();
50    }
51
52    private void PopulateImageList() {
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);
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);
64      toolTip.SetToolTip(contactTextBox, contactTextBox.Text);
65      descriptionTextBox.Text = plugin.Description;
66      toolTip.SetToolTip(descriptionTextBox, plugin.Description);
67      var localPlugin = plugin as PluginDescription;
68      if (localPlugin != null) {
69        stateTextBox.Text = localPlugin.PluginState.ToString();
70        if (!string.IsNullOrEmpty(localPlugin.LoadingErrorInformation))
71          errorTextBox.Text = localPlugin.LoadingErrorInformation.Replace(Environment.NewLine, " ");
72        toolTip.SetToolTip(stateTextBox, stateTextBox.Text + Environment.NewLine + errorTextBox.Text);
73        toolTip.SetToolTip(errorTextBox, errorTextBox.Text);
74      }
75      foreach (PluginDescription dependency in plugin.Dependencies) {
76        var depItem = new ListViewItem(new string[] { dependency.Name, dependency.Version.ToString(), dependency.Description });
77        depItem.Tag = dependency;
78        depItem.ImageKey = IMAGE_KEY_PLUGIN;
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      }
92      Util.ResizeColumns(dependenciesListView.Columns.OfType<ColumnHeader>());
93      Util.ResizeColumns(filesListView.Columns.OfType<ColumnHeader>());
94
95      showLicenseButton.Enabled = !string.IsNullOrEmpty(plugin.LicenseText);
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);
113        view.Show(this);
114      }
115    }
116
117    private void showLicenseButton_Click(object sender, EventArgs e) {
118      LicenseView view = new LicenseView(plugin);
119      view.Show(this);
120    }
121  }
122}
Note: See TracBrowser for help on using the repository browser.