Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1215 worked on metaoptimization

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(ICheckedValueConfigurationCollection), IsDefaultView = true)]
18  public sealed partial class ValueConfigurationCheckedItemCollectionView : CheckedItemCollectionView<IValueConfiguration> {
19    public new ICheckedValueConfigurationCollection Content {
20      get { return (ICheckedValueConfigurationCollection)base.Content; }
21      set { base.Content = value; }
22    }
23
24    public ValueConfigurationCheckedItemCollectionView() {
25      InitializeComponent();
26    }
27
28    protected override void DeregisterContentEvents() {
29      Content.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(Content_ItemsRemoved);
30      base.DeregisterContentEvents();
31    }
32
33    protected override void RegisterContentEvents() {
34      base.RegisterContentEvents();
35      Content.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(Content_ItemsRemoved);
36    }
37
38    #region Event Handlers (Content)
39    private new void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IValueConfiguration> e) {
40      if (InvokeRequired) {
41        Invoke(new EventHandler<CollectionItemsChangedEventArgs<IValueConfiguration>>(Content_ItemsRemoved), sender, e);
42      } else {
43        base.Content_ItemsRemoved(sender, e);
44        SetEnabledStateOfControls();
45      }
46    }
47    #endregion
48
49    protected override void OnContentChanged() {
50      base.OnContentChanged();
51      if (Content != null) {
52        SetEnabledStateOfControls();
53      } else {
54      }
55    }
56
57    protected override void SetEnabledStateOfControls() {
58      base.SetEnabledStateOfControls();
59      if(Content != null) this.removeButton.Enabled = Content.Count > Content.MinItemCount;
60    }
61
62    protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
63      base.itemsListView_SelectedIndexChanged(sender, e);
64      this.removeButton.Enabled = removeButton.Enabled && (Content.Count > Content.MinItemCount);
65    }
66
67    #region Event Handlers (child controls)
68    #endregion
69
70    protected override IValueConfiguration CreateItem() {
71      if (typeSelectorDialog == null) {
72        typeSelectorDialog = new TypeSelectorDialog();
73        typeSelectorDialog.Caption = "Select Item";
74        typeSelectorDialog.TypeSelector.Caption = "Available Items";
75        typeSelectorDialog.TypeSelector.Configure(Content.ValueDataType, false, true);
76      }
77
78      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
79        try {
80          IItem value = (IItem)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
81          return new ValueConfiguration(value, value.GetType());
82        }
83        catch (Exception ex) {
84          ErrorHandling.ShowErrorDialog(this, ex);
85        }
86      }
87      return null;
88    }
89  }
90}
Note: See TracBrowser for help on using the repository browser.