Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ValueConfigurationViews/ValueConfigurationCheckedItemList.cs @ 5277

Last change on this file since 5277 was 5277, checked in by cneumuel, 13 years ago

#1215

  • implemented crossover and manipulator operators for int and double values
File size: 3.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using HeuristicLab.Core.Views;
9using HeuristicLab.MainForm;
10using HeuristicLab.Core;
11using System.Windows.Forms;
12using HeuristicLab.PluginInfrastructure;
13using HeuristicLab.Collections;
14
15namespace HeuristicLab.Problems.MetaOptimization.Views {
16  [View("ValueConfigurationList View")]
17  [Content(typeof(ICheckedValueConfigurationList), IsDefaultView = true)]
18  public sealed partial class ValueConfigurationCheckedItemCollectionView : CheckedItemListView<IValueConfiguration> {
19    public new ICheckedValueConfigurationList Content {
20      get { return (ICheckedValueConfigurationList)base.Content; }
21      set { base.Content = value; }
22    }
23
24    public ValueConfigurationCheckedItemCollectionView() {
25      InitializeComponent();
26      this.viewHost.ViewsLabelVisible = false;
27    }
28
29    protected override void DeregisterContentEvents() {
30      Content.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(Content_ItemsRemoved);
31      base.DeregisterContentEvents();
32    }
33
34    protected override void RegisterContentEvents() {
35      base.RegisterContentEvents();
36      Content.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(Content_ItemsRemoved);
37    }
38
39    #region Event Handlers (Content)
40    private new void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {
41      if (InvokeRequired) {
42        Invoke(new EventHandler<CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>>>(Content_ItemsRemoved), sender, e);
43      } else {
44        base.Content_ItemsRemoved(sender, e);
45        SetEnabledStateOfControls();
46      }
47    }
48    #endregion
49
50    protected override void OnContentChanged() {
51      base.OnContentChanged();
52      if (Content != null) {
53        SetEnabledStateOfControls();
54      } else {
55      }
56    }
57
58    protected override void SetEnabledStateOfControls() {
59      base.SetEnabledStateOfControls();
60      if(Content != null) this.removeButton.Enabled = Content.Count > Content.MinItemCount;
61    }
62
63    protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
64      base.itemsListView_SelectedIndexChanged(sender, e);
65      this.removeButton.Enabled = removeButton.Enabled && (Content.Count > Content.MinItemCount);
66    }
67
68    #region Event Handlers (child controls)
69    #endregion
70
71    protected override IValueConfiguration CreateItem() {
72      var objectSelectorDialog = new ObjectSelectorDialog<IItem>(Content.ValidValues.GroupBy(x => ApplicationManager.Manager.GetDeclaringPlugin(x.GetType()).Name));
73      if (objectSelectorDialog.ShowDialog(this) == DialogResult.OK) {
74        try {
75          IItem value = (IItem)objectSelectorDialog.Item.Clone();
76          if (value is NullValue) {
77            return new NullValueConfiguration();
78          } else {
79            return new ValueConfiguration(value, value.GetType());
80          }
81        }
82        catch (Exception ex) {
83          ErrorHandling.ShowErrorDialog(this, ex);
84        }
85      }
86      return null;
87    }
88  }
89}
Note: See TracBrowser for help on using the repository browser.