Free cookie consent management tool by TermsFeed Policy Generator

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

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

Added license headers and set visibility to internal for the classes of the plugin manager. #891 (Refactor GUI for plugin management)

File size: 4.4 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 : InstallationManagerControl {
35    private const string IMAGE_KEY_ASSEMBLY = "Assembly";
36    private const string IMAGE_KEY_FILE = "File";
37    private const string IMAGE_KEY_DOCUMENT = "Document";
38
39    private PluginDescription plugin;
40
41    public PluginView() {
42      InitializeComponent();
43      PopulateImageList();
44    }
45
46    public PluginView(PluginDescription plugin) {
47      InitializeComponent();
48      PopulateImageList();
49
50      this.plugin = plugin;
51      this.Name = "Plugin Details: " + plugin.ToString();
52      UpdateControls();
53    }
54
55    private void PopulateImageList() {
56      imageList.Images.Add(IMAGE_KEY_ASSEMBLY, HeuristicLab.PluginInfrastructure.Resources.Resources.Assembly);
57      imageList.Images.Add(IMAGE_KEY_FILE, HeuristicLab.PluginInfrastructure.Resources.Resources.File);
58      imageList.Images.Add(IMAGE_KEY_DOCUMENT, HeuristicLab.PluginInfrastructure.Resources.Resources.Document);
59    }
60
61    public void UpdateControls() {
62      string appDir = Path.GetDirectoryName(Application.ExecutablePath);
63      nameTextBox.Text = plugin.Name;
64      versionTextBox.Text = plugin.Version.ToString();
65      contactTextBox.Text = CombineStrings(plugin.ContactName, plugin.ContactEmail);
66      descriptionTextBox.Text = plugin.Description;
67      stateTextBox.Text = plugin.PluginState.ToString();
68      errorTextBox.Text = plugin.LoadingErrorInformation;
69      foreach (PluginDescription dependency in plugin.Dependencies) {
70        var depItem = new ListViewItem(new string[] { dependency.Name, dependency.Version.ToString() });
71        depItem.Tag = dependency;
72        depItem.ImageKey = IMAGE_KEY_ASSEMBLY;
73        dependenciesListView.Items.Add(depItem);
74      }
75      foreach (var file in plugin.Files) {
76        string displayedFileName = file.Name.Replace(appDir, string.Empty);
77        displayedFileName = displayedFileName.TrimStart(Path.DirectorySeparatorChar);
78        var fileItem = new ListViewItem(new string[] { displayedFileName, file.Type.ToString() });
79        if (file.Type == PluginFileType.Assembly) {
80          fileItem.ImageKey = IMAGE_KEY_ASSEMBLY;
81        } else if (file.Type == PluginFileType.License) {
82          fileItem.ImageKey = IMAGE_KEY_DOCUMENT;
83        } else fileItem.ImageKey = IMAGE_KEY_FILE;
84        filesListView.Items.Add(fileItem);
85      }
86      licenseButton.Enabled = !string.IsNullOrEmpty(plugin.LicenseText);
87    }
88
89    private string CombineStrings(string a, string b) {
90      if (string.IsNullOrEmpty(a))
91        // a is empty
92        if (!string.IsNullOrEmpty(b)) return CombineStrings(b, string.Empty);
93        else return string.Empty;
94      // a is not empty
95      else if (string.IsNullOrEmpty(b)) return a;
96      // and b are not empty
97      else return a + ", " + b;
98    }
99
100    private void licenseButton_Click(object sender, EventArgs e) {
101      LicenseView view = new LicenseView(plugin);
102      view.ShowInForm();
103    }
104
105    private void dependenciesListView_ItemActivate(object sender, EventArgs e) {
106      if (dependenciesListView.SelectedItems.Count > 0) {
107        var dep = (PluginDescription)dependenciesListView.SelectedItems[0].Tag;
108        PluginView view = new PluginView(dep);
109        view.ShowInForm();
110      }
111    }
112  }
113}
Note: See TracBrowser for help on using the repository browser.