Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimizer/3.3/NewItemDialog.cs @ 7071

Last change on this file since 7071 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

File size: 3.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Collections.Generic;
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    private List<IItem> items;
33
34    private IItem item;
35    public IItem Item {
36      get { return item; }
37    }
38
39    public NewItemDialog() {
40      initialized = false;
41      items = new List<IItem>();
42      item = null;
43      InitializeComponent();
44    }
45
46    private void NewItemDialog_Load(object sender, EventArgs e) {
47      if (!initialized) {
48        var categories = from t in ApplicationManager.Manager.GetTypes(typeof(IItem))
49                         where CreatableAttribute.IsCreatable(t)
50                         orderby CreatableAttribute.GetCategory(t), ItemAttribute.GetName(t), ItemAttribute.GetVersion(t) ascending
51                         group t by CreatableAttribute.GetCategory(t) into c
52                         select c;
53
54        itemsListView.SmallImageList = new ImageList();
55        foreach (var category in categories) {
56          ListViewGroup group = new ListViewGroup(category.Key);
57          itemsListView.Groups.Add(group);
58          foreach (var creatable in category) {
59            IItem i = (IItem)Activator.CreateInstance(creatable);
60            items.Add(i);
61            ListViewItem item = new ListViewItem(new string[] { i.ItemName, i.ItemVersion.ToString(), i.ItemDescription }, group);
62            itemsListView.SmallImageList.Images.Add(i.ItemImage);
63            item.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
64            item.Tag = i;
65            itemsListView.Items.Add(item);
66          }
67        }
68        for (int i = 0; i < itemsListView.Columns.Count; i++)
69          itemsListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
70        initialized = true;
71      }
72    }
73
74    private void NewItemDialog_Shown(object sender, EventArgs e) {
75      item = null;
76    }
77
78    private void itemTypesListView_SelectedIndexChanged(object sender, EventArgs e) {
79      okButton.Enabled = itemsListView.SelectedItems.Count == 1;
80    }
81
82    private void okButton_Click(object sender, EventArgs e) {
83      if (itemsListView.SelectedItems.Count == 1) {
84        item = (IItem)((IItem)itemsListView.SelectedItems[0].Tag).Clone();
85        DialogResult = DialogResult.OK;
86        Close();
87      }
88    }
89    private void itemTypesListView_DoubleClick(object sender, EventArgs e) {
90      if (itemsListView.SelectedItems.Count == 1) {
91        item = (IItem)((IItem)itemsListView.SelectedItems[0].Tag).Clone();
92        DialogResult = DialogResult.OK;
93        Close();
94      }
95    }
96  }
97}
Note: See TracBrowser for help on using the repository browser.