Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ObjectSelectorDialog.cs @ 4682

Last change on this file since 4682 was 4516, checked in by cneumuel, 14 years ago

initial prototype for Meta Optimization Problem (#1215)

File size: 2.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9using HeuristicLab.Core;
10
11namespace HeuristicLab.Problems.MetaOptimization.Views {
12  public partial class ObjectSelectorDialog<T> : Form where T : INamedItem {
13    private bool initialized;
14    private List<IItem> items;
15    private IEnumerable<IGrouping<string, T>> selectableItems;
16
17    private T item;
18    public T Item {
19      get { return item; }
20    }
21
22    public ObjectSelectorDialog(IEnumerable<IGrouping<string, T>> selectableItems) {
23      this.initialized = false;
24      this.items = new List<IItem>();
25      this.item = default(T);
26      this.selectableItems = selectableItems;
27      InitializeComponent();
28    }
29
30    private void ObjectSelectorDialog_Load(object sender, EventArgs e) {
31      if (!initialized) {
32        itemsListView.SmallImageList = new ImageList();
33
34        foreach (IGrouping<string, T> category in selectableItems) {
35          ListViewGroup group = new ListViewGroup(category.Key);
36          itemsListView.Groups.Add(group);
37          foreach (T i in category) {
38            items.Add(i);
39            ListViewItem item = new ListViewItem(new string[] { i.Name, i.Description, i.ItemName }, group);
40            itemsListView.SmallImageList.Images.Add(i.ItemImage);
41            item.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
42            item.Tag = i;
43            itemsListView.Items.Add(item);
44          }
45        }
46        for (int i = 0; i < itemsListView.Columns.Count; i++)
47          itemsListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
48        initialized = true;
49      }
50    }
51
52    private void ObjectSelectorDialog_Shown(object sender, EventArgs e) {
53      item = default(T);
54    }
55
56    private void okButton_Click(object sender, EventArgs e) {
57      if (itemsListView.SelectedItems.Count == 1) {
58        item = (T)itemsListView.SelectedItems[0].Tag;
59        DialogResult = DialogResult.OK;
60        Close();
61      }
62    }
63
64    private void itemsListView_DoubleClick(object sender, EventArgs e) {
65      if (itemsListView.SelectedItems.Count == 1) {
66        item = (T)itemsListView.SelectedItems[0].Tag;
67        DialogResult = DialogResult.OK;
68        Close();
69      }
70    }
71
72    private void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
73      okButton.Enabled = itemsListView.SelectedItems.Count == 1;
74    }
75
76
77  }
78}
Note: See TracBrowser for help on using the repository browser.