Free cookie consent management tool by TermsFeed Policy Generator

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

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

Fixed exception in plugin view. #989

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