1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Data;
|
---|
6 | using System.Linq;
|
---|
7 | using System.Text;
|
---|
8 | using System.Windows.Forms;
|
---|
9 | using HeuristicLab.MainForm;
|
---|
10 | using HeuristicLab.Core.Views;
|
---|
11 | using HeuristicLab.Core;
|
---|
12 | using HeuristicLab.PluginInfrastructure;
|
---|
13 |
|
---|
14 | namespace HeuristicLab.Problems.MetaOptimization.Views {
|
---|
15 | /// <summary>
|
---|
16 | /// The visual representation of a <see cref="ParameterConfiguration"/>.
|
---|
17 | /// </summary>
|
---|
18 | [View("ParameterConfigurationList View")]
|
---|
19 | [Content(typeof(ParameterConfigurationList), true)]
|
---|
20 | public partial class ParameterConfigurationListView : ItemCollectionView<IParameterConfiguration> {
|
---|
21 | /// <summary>
|
---|
22 | /// Gets or sets the variable to represent visually.
|
---|
23 | /// </summary>
|
---|
24 | /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
|
---|
25 | /// No own data storage present.</remarks>
|
---|
26 | public new ParameterConfigurationList Content {
|
---|
27 | get { return (ParameterConfigurationList)base.Content; }
|
---|
28 | set { base.Content = value; }
|
---|
29 | }
|
---|
30 |
|
---|
31 | public ParameterConfigurationListView() {
|
---|
32 | InitializeComponent();
|
---|
33 | }
|
---|
34 |
|
---|
35 | protected override void RegisterContentEvents() {
|
---|
36 | base.RegisterContentEvents();
|
---|
37 | Content.CheckedItemsChanged += new Collections.CollectionItemsChangedEventHandler<IParameterConfiguration>(Content_CheckedItemsChanged);
|
---|
38 | }
|
---|
39 |
|
---|
40 | protected override void DeregisterContentEvents() {
|
---|
41 | Content.CheckedItemsChanged -= new Collections.CollectionItemsChangedEventHandler<IParameterConfiguration>(Content_CheckedItemsChanged);
|
---|
42 | base.DeregisterContentEvents();
|
---|
43 | }
|
---|
44 |
|
---|
45 | protected override void OnContentChanged() {
|
---|
46 | base.OnContentChanged();
|
---|
47 | while (itemsListView.Items.Count > 0) RemoveListViewItem(itemsListView.Items[0]);
|
---|
48 | viewHost.Content = null;
|
---|
49 | if (Content != null) {
|
---|
50 | Caption += " (" + Content.GetType().Name + ")";
|
---|
51 | foreach (IParameterConfiguration item in Content.CheckedItems)
|
---|
52 | AddListViewItem(CreateListViewItem(item));
|
---|
53 | AdjustListViewColumnSizes();
|
---|
54 | SortItemsListView(SortOrder.Ascending);
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | protected override void SetEnabledStateOfControls() {
|
---|
59 | base.SetEnabledStateOfControls();
|
---|
60 | }
|
---|
61 |
|
---|
62 | protected override void addButton_Click(object sender, EventArgs e) {
|
---|
63 | var selectorDialog = new ObjectSelectorDialog<IParameterConfiguration>(from c in Content
|
---|
64 | where !Content.ItemChecked(c)
|
---|
65 | group c by c.Category);
|
---|
66 | if (selectorDialog.ShowDialog() == DialogResult.OK) {
|
---|
67 | Content.SetItemCheckedState(selectorDialog.Item, true);
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | protected override void removeButton_Click(object sender, EventArgs e) {
|
---|
72 | if (itemsListView.SelectedItems.Count > 0) {
|
---|
73 | foreach (ListViewItem item in itemsListView.SelectedItems)
|
---|
74 | Content.SetItemCheckedState((IParameterConfiguration)item.Tag, false);
|
---|
75 | itemsListView.SelectedItems.Clear();
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | private void Content_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IParameterConfiguration> e) {
|
---|
80 | foreach (IParameterConfiguration item in e.Items) {
|
---|
81 | if (!Content.ItemChecked(item)) {
|
---|
82 | ListViewItem found = FindListViewItem(item);
|
---|
83 | if(found != null)
|
---|
84 | RemoveListViewItem(found);
|
---|
85 | } else {
|
---|
86 | ListViewItem found = FindListViewItem(item);
|
---|
87 | if (found == null)
|
---|
88 | AddListViewItem(CreateListViewItem(item));
|
---|
89 | }
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | #region Helpers
|
---|
94 | private ListViewItem FindListViewItem(IParameterConfiguration tag) {
|
---|
95 | foreach (ListViewItem item in itemsListView.Items) {
|
---|
96 | if (item.Tag == tag)
|
---|
97 | return item;
|
---|
98 | }
|
---|
99 | return null;
|
---|
100 | }
|
---|
101 | #endregion
|
---|
102 | }
|
---|
103 | }
|
---|