Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1215

  • evaluation operator returns operatorgraph which creates a scope and an operation for each algorithm execution (each repetition and problem)
  • split ValueConfiguration into ParameterizedValueConfiguration and RangeValueConfiguration
File size: 3.3 KB
Line 
1using System;
2using System.Linq;
3using System.Windows.Forms;
4using HeuristicLab.Collections;
5using HeuristicLab.Core;
6using HeuristicLab.Core.Views;
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    }
23
24    protected override void DeregisterContentEvents() {
25      Content.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(Content_ItemsRemoved);
26      base.DeregisterContentEvents();
27    }
28
29    protected override void RegisterContentEvents() {
30      base.RegisterContentEvents();
31      Content.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(Content_ItemsRemoved);
32    }
33
34    #region Event Handlers (Content)
35    private new void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {
36      if (InvokeRequired) {
37        Invoke(new EventHandler<CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>>>(Content_ItemsRemoved), sender, e);
38      } else {
39        base.Content_ItemsRemoved(sender, e);
40        SetEnabledStateOfControls();
41      }
42    }
43    #endregion
44
45    protected override void OnContentChanged() {
46      base.OnContentChanged();
47      if (Content != null) {
48        SetEnabledStateOfControls();
49      } else {
50      }
51    }
52
53    protected override void SetEnabledStateOfControls() {
54      base.SetEnabledStateOfControls();
55      if(Content != null) this.removeButton.Enabled = Content.Count > Content.MinItemCount;
56    }
57
58    protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
59      base.itemsListView_SelectedIndexChanged(sender, e);
60      this.removeButton.Enabled = removeButton.Enabled && (Content.Count > Content.MinItemCount);
61    }
62
63    #region Event Handlers (child controls)
64    #endregion
65
66    protected override IValueConfiguration CreateItem() {
67      var objectSelectorDialog = new ObjectSelectorDialog<IItem>(Content.ValidValues.GroupBy(x => ApplicationManager.Manager.GetDeclaringPlugin(x.GetType()).Name));
68      if (objectSelectorDialog.ShowDialog(this) == DialogResult.OK) {
69        try {
70          IItem value = (IItem)objectSelectorDialog.Item.Clone();
71          if (value is NullValue) {
72            return new NullValueConfiguration();
73          } else if(value is IParameterizedItem) {
74            return new ParameterizedValueConfiguration(value, value.GetType());
75          } else {
76            return new RangeValueConfiguration(value, value.GetType());
77          }
78        }
79        catch (Exception ex) {
80          ErrorHandling.ShowErrorDialog(this, ex);
81        }
82      }
83      return null;
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.