Free cookie consent management tool by TermsFeed Policy Generator

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

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

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

File size: 3.9 KB
RevLine 
[2790]1#region License Information
2/* HeuristicLab
[9456]3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2790]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;
[7201]23using System.Drawing;
[2520]24using System.Linq;
25using System.Windows.Forms;
[2790]26using HeuristicLab.Core;
[2546]27using HeuristicLab.PluginInfrastructure;
[2520]28
29namespace HeuristicLab.Optimizer {
[2546]30  internal partial class NewItemDialog : Form {
31    private bool initialized;
32
33    private IItem item;
34    public IItem Item {
35      get { return item; }
[2520]36    }
37
[2546]38    public NewItemDialog() {
39      initialized = false;
40      item = null;
[2520]41      InitializeComponent();
42    }
[2546]43
44    private void NewItemDialog_Load(object sender, EventArgs e) {
45      if (!initialized) {
[2656]46        var categories = from t in ApplicationManager.Manager.GetTypes(typeof(IItem))
[2546]47                         where CreatableAttribute.IsCreatable(t)
[3728]48                         orderby CreatableAttribute.GetCategory(t), ItemAttribute.GetName(t), ItemAttribute.GetVersion(t) ascending
[2546]49                         group t by CreatableAttribute.GetCategory(t) into c
50                         select c;
51
52        itemsListView.SmallImageList = new ImageList();
[7201]53        itemsListView.SmallImageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Class);  // default icon
[2546]54        foreach (var category in categories) {
55          ListViewGroup group = new ListViewGroup(category.Key);
56          itemsListView.Groups.Add(group);
57          foreach (var creatable in category) {
[7201]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;
[2546]69            itemsListView.Items.Add(item);
70          }
71        }
[2790]72        for (int i = 0; i < itemsListView.Columns.Count; i++)
73          itemsListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
[2546]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) {
[7201]88        item = (IItem)Activator.CreateInstance((Type)itemsListView.SelectedItems[0].Tag);
[2546]89        DialogResult = DialogResult.OK;
90        Close();
91      }
92    }
93    private void itemTypesListView_DoubleClick(object sender, EventArgs e) {
94      if (itemsListView.SelectedItems.Count == 1) {
[7201]95        item = (IItem)Activator.CreateInstance((Type)itemsListView.SelectedItems[0].Tag);
[2546]96        DialogResult = DialogResult.OK;
97        Close();
98      }
99    }
[2520]100  }
101}
Note: See TracBrowser for help on using the repository browser.