Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3532 was 3376, checked in by swagner, 15 years ago

Moved interfaces and classes for deep cloning from HeuristicLab.Core to HeuristicLab.Common (#975).

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