Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Optimizer/3.3/NewItemDialog.cs @ 10188

Last change on this file since 10188 was 9456, checked in by swagner, 12 years ago

Updated copyright year and added some missing license headers (#1889)

File size: 3.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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
21
22using System;
23using System.Drawing;
24using System.Linq;
25using System.Windows.Forms;
26using HeuristicLab.Core;
27using HeuristicLab.PluginInfrastructure;
28
29namespace HeuristicLab.Optimizer {
30  internal partial class NewItemDialog : Form {
31    private bool initialized;
32
33    private IItem item;
34    public IItem Item {
35      get { return item; }
36    }
37
38    public NewItemDialog() {
39      initialized = false;
40      item = null;
41      InitializeComponent();
42    }
43
44    private void NewItemDialog_Load(object sender, EventArgs e) {
45      if (!initialized) {
46        var categories = from t in ApplicationManager.Manager.GetTypes(typeof(IItem))
47                         where CreatableAttribute.IsCreatable(t)
48                         orderby CreatableAttribute.GetCategory(t), ItemAttribute.GetName(t), ItemAttribute.GetVersion(t) ascending
49                         group t by CreatableAttribute.GetCategory(t) into c
50                         select c;
51
52        itemsListView.SmallImageList = new ImageList();
53        itemsListView.SmallImageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Class);  // default icon
54        foreach (var category in categories) {
55          ListViewGroup group = new ListViewGroup(category.Key);
56          itemsListView.Groups.Add(group);
57          foreach (var creatable in category) {
58            string name = ItemAttribute.GetName(creatable);
59            string version = ItemAttribute.GetVersion(creatable).ToString();
60            string description = ItemAttribute.GetDescription(creatable);
61            ListViewItem item = new ListViewItem(new string[] { name, version, description }, group);
62            item.ImageIndex = 0;
63            Image image = ItemAttribute.GetImage(creatable);
64            if (image != null) {
65              itemsListView.SmallImageList.Images.Add(image);
66              item.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
67            }
68            item.Tag = creatable;
69            itemsListView.Items.Add(item);
70          }
71        }
72        for (int i = 0; i < itemsListView.Columns.Count; i++)
73          itemsListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
74        initialized = true;
75      }
76    }
77
78    private void NewItemDialog_Shown(object sender, EventArgs e) {
79      item = null;
80    }
81
82    private void itemTypesListView_SelectedIndexChanged(object sender, EventArgs e) {
83      okButton.Enabled = itemsListView.SelectedItems.Count == 1;
84    }
85
86    private void okButton_Click(object sender, EventArgs e) {
87      if (itemsListView.SelectedItems.Count == 1) {
88        item = (IItem)Activator.CreateInstance((Type)itemsListView.SelectedItems[0].Tag);
89        DialogResult = DialogResult.OK;
90        Close();
91      }
92    }
93    private void itemTypesListView_DoubleClick(object sender, EventArgs e) {
94      if (itemsListView.SelectedItems.Count == 1) {
95        item = (IItem)Activator.CreateInstance((Type)itemsListView.SelectedItems[0].Tag);
96        DialogResult = DialogResult.OK;
97        Close();
98      }
99    }
100  }
101}
Note: See TracBrowser for help on using the repository browser.