Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ValueConfigurationViews/ValueConfigurationCheckedItemCollectionView.cs @ 10204

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

#1215

  • implemented optimization of problem parameters
File size: 2.4 KB
RevLine 
[5654]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.Problems.MetaOptimization.Views {
10  [View("ValueConfigurationList View")]
11  [Content(typeof(ICheckedValueConfigurationList), IsDefaultView = true)]
12  public sealed partial class ValueConfigurationCheckedItemCollectionView : CheckedItemListView<IValueConfiguration> {
13    public new ICheckedValueConfigurationList Content {
14      get { return (ICheckedValueConfigurationList)base.Content; }
15      set { base.Content = value; }
16    }
17
18    public ValueConfigurationCheckedItemCollectionView() {
19      InitializeComponent();
20      this.viewHost.ViewsLabelVisible = false;
21    }
22
23    #region Event Handlers (Content)
24    #endregion
25
26    protected override void OnContentChanged() {
27      base.OnContentChanged();
28      if (Content != null) {
29        SetEnabledStateOfControls();
30      } else {
31      }
32    }
33
34    protected override void SetEnabledStateOfControls() {
35      base.SetEnabledStateOfControls();
36      if(Content != null) this.removeButton.Enabled = Content.Count > Content.MinItemCount;
37    }
38
39    #region Event Handlers (child controls)
40    protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
41      base.itemsListView_SelectedIndexChanged(sender, e);
42      this.removeButton.Enabled = removeButton.Enabled && (Content.Count > Content.MinItemCount);
43    }
44    #endregion
45
46    protected override IValueConfiguration CreateItem() {
47      var objectSelectorDialog = new ObjectSelectorDialog<IItem>(Content.ValidValues.GroupBy(x => ApplicationManager.Manager.GetDeclaringPlugin(x.GetType()).Name));
48      if (objectSelectorDialog.ShowDialog(this) == DialogResult.OK) {
49        try {
50          IItem value = (IItem)objectSelectorDialog.Item.Clone();
51          if (value is NullValue) {
52            return new NullValueConfiguration();
53          } else if(value is IParameterizedItem) {
[5665]54            return new ParameterizedValueConfiguration(value, value.GetType(), true);
[5654]55          } else {
56            return new RangeValueConfiguration(value, value.GetType());
57          }
58        }
59        catch (Exception ex) {
60          ErrorHandling.ShowErrorDialog(this, ex);
61        }
62      }
63      return null;
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.