Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/OptimizableView.cs @ 4997

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

#1215 worked on metaoptimization

File size: 3.7 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.Parameters;
11using HeuristicLab.Core;
12using HeuristicLab.Data;
13
14namespace HeuristicLab.Problems.MetaOptimization.Views.ValueConfigurationViews {
15  [View("IOptimizable View")]
16  [Content(typeof(IOptimizable), IsDefaultView = false)]
17  [Content(typeof(ParameterConfiguration), IsDefaultView = true)]
18  [Content(typeof(ValueConfiguration), IsDefaultView = true)]
19  public sealed partial class OptimizableView : ItemView {
20    public new IOptimizable Content {
21      get { return (IOptimizable)base.Content; }
22      set { base.Content = value; }
23    }
24
25    public OptimizableView() {
26      InitializeComponent();
27    }
28
29    protected override void DeregisterContentEvents() {
30      Content.OptimizeChanged -= new EventHandler(Content_OptimizeChanged);
31      Content.IsOptimizableChanged -= new EventHandler(Content_IsOptimizabeChanged);
32      base.DeregisterContentEvents();
33    }
34
35    protected override void RegisterContentEvents() {
36      base.RegisterContentEvents();
37      Content.IsOptimizableChanged += new EventHandler(Content_IsOptimizabeChanged);
38      Content.OptimizeChanged += new EventHandler(Content_OptimizeChanged);
39    }
40
41    #region Event Handlers (Content)
42    void Content_OptimizeChanged(object sender, EventArgs e) {
43      if (InvokeRequired) {
44        Invoke(new EventHandler(Content_OptimizeChanged), sender, e);
45      } else {
46        this.optimizeCheckBox.Checked = Content.Optimize;
47        if (Content.Optimize) {
48          this.viewHost.ViewType = null;
49          if (Content is IParameterConfiguration) {
50            this.viewHost.Content = ((IParameterConfiguration)Content).ValueConfigurations;
51          } else if (Content is IValueConfiguration) {
52            if (Content.ActualValue.ValueDataType == typeof(IntValue) ||
53                Content.ActualValue.ValueDataType == typeof(DoubleValue) ||
54                Content.ActualValue.ValueDataType == typeof(PercentValue)) {
55              this.viewHost.Content = ((IValueConfiguration)Content).RangeConstraint;
56            } else if(Content.ActualValue.ValueDataType == typeof(BoolValue)) {
57              this.viewHost.Content = null; // no configuration required
58            } else {
59              this.viewHost.Content = ((IValueConfiguration)Content).ParameterConfigurations;
60            }
61          } else {
62            throw new NotSupportedException("Only IParameterConfiguration and IValueConfiguration types are allowed.");
63          }
64        } else {
65          this.viewHost.Content = Content.ActualValue;
66        }
67      }
68    }
69    void Content_IsOptimizabeChanged(object sender, EventArgs e) {
70      if (InvokeRequired) {
71        Invoke(new EventHandler(Content_IsOptimizabeChanged), sender, e);
72      } else {
73        SetEnabledStateOfControls();
74      }
75    }
76    #endregion
77
78    protected override void OnContentChanged() {
79      base.OnContentChanged();
80      if (Content != null) {
81        Content_OptimizeChanged(this, EventArgs.Empty);
82      } else {
83        this.viewHost.Content = null;
84      }
85    }
86
87    protected override void SetEnabledStateOfControls() {
88      base.SetEnabledStateOfControls();
89      if (Content != null) {
90        this.optimizeCheckBox.Enabled = !this.ReadOnly && Content.IsOptimizable;
91      }
92    }
93
94    #region Event Handlers (child controls)
95    private void optimizeCheckBox_CheckedChanged(object sender, EventArgs e) {
96      Content.Optimize = optimizeCheckBox.Checked;
97    }
98    #endregion
99  }
100}
Note: See TracBrowser for help on using the repository browser.