Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization (trunk integration)/HeuristicLab.Problems.MetaOptimization.Views/3.3/ValueConfigurationViews/ValueConfigurationCheckedItemCollectionView.cs @ 8576

Last change on this file since 8576 was 8576, checked in by jkarder, 12 years ago

#1853: created branch for MetaOptimization (trunk integration)

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