Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding.Views/3.3/ValueConfigurationViews/ValueConfigurationCheckedItemListView.cs @ 9356

Last change on this file since 9356 was 9356, checked in by jkarder, 11 years ago

#1853:

  • moved ValueConfigurationCheckedItemCollectionView to ParameterConfigurationEncoding
  • renamed ValueConfigurationCheckedItemCollectionView to ValueConfigurationCheckedItemListView
File size: 2.6 KB
Line 
1using System;
2using System.Linq;
3using System.Windows.Forms;
4using HeuristicLab.Core;
5using HeuristicLab.Core.Views;
6using HeuristicLab.MainForm;
7using HeuristicLab.PluginInfrastructure;
8
9namespace HeuristicLab.Encodings.ParameterConfigurationEncoding.Views {
10  [View("ValueConfigurationList View")]
11  [Content(typeof(ICheckedValueConfigurationList), IsDefaultView = true)]
12  public sealed partial class ValueConfigurationCheckedItemListView : CheckedItemListView<IValueConfiguration> {
13    public new ICheckedValueConfigurationList Content {
14      get { return (ICheckedValueConfigurationList)base.Content; }
15      set { base.Content = value; }
16    }
17
18    public ValueConfigurationCheckedItemListView() {
19      InitializeComponent();
20      this.viewHost.ViewsLabelVisible = false;
21      this.typeSelectorDialog = new TypeSelectorDialog();
22    }
23
24    #region Event Handlers (Content)
25    #endregion
26
27    protected override void OnContentChanged() {
28      base.OnContentChanged();
29      if (Content != null) {
30        SetEnabledStateOfControls();
31      } else {
32      }
33    }
34
35    protected override void SetEnabledStateOfControls() {
36      base.SetEnabledStateOfControls();
37      if (Content != null) this.removeButton.Enabled = Content.Count > Content.MinItemCount;
38    }
39
40    #region Event Handlers (child controls)
41    protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
42      base.itemsListView_SelectedIndexChanged(sender, e);
43      this.removeButton.Enabled = removeButton.Enabled && (Content.Count > Content.MinItemCount);
44    }
45    #endregion
46
47    protected override IValueConfiguration CreateItem() {
48      typeSelectorDialog.Caption = "Select Item";
49      typeSelectorDialog.TypeSelector.Caption = "Available Items";
50      typeSelectorDialog.TypeSelector.Configure(Content.ValidValues.Select(x => x.GetType()), false, false, false);
51      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
52        try {
53          IItem value = (IItem)Content.ValidValues.Single(x => x.GetType() == typeSelectorDialog.TypeSelector.SelectedType).Clone();
54          if (value is NullValue) {
55            return new NullValueConfiguration();
56          } else if (value is IParameterizedItem) {
57            return new ParameterizedValueConfiguration(value, value.GetType(), true);
58          } else {
59            return new RangeValueConfiguration(value, value.GetType());
60          }
61        }
62        catch (Exception ex) {
63          ErrorHandling.ShowErrorDialog(this, ex);
64        }
65      }
66      return null;
67    }
68  }
69}
Note: See TracBrowser for help on using the repository browser.