Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1215

  • fixed issue with multiple problems (by introducing valuesReadOnly to IOptimizable)
  • fixed error message when removing last problem instance
  • made quality measure name configurable
File size: 4.6 KB
RevLine 
[4981]1using System;
[5665]2using System.Linq;
[4981]3using HeuristicLab.Core.Views;
[5653]4using HeuristicLab.Data;
[4981]5using HeuristicLab.MainForm;
6
7namespace HeuristicLab.Problems.MetaOptimization.Views.ValueConfigurationViews {
8  [View("IOptimizable View")]
9  [Content(typeof(IOptimizable), IsDefaultView = false)]
10  [Content(typeof(ParameterConfiguration), IsDefaultView = true)]
11  [Content(typeof(ValueConfiguration), IsDefaultView = true)]
12  public sealed partial class OptimizableView : ItemView {
13    public new IOptimizable Content {
14      get { return (IOptimizable)base.Content; }
15      set { base.Content = value; }
16    }
17
18    public OptimizableView() {
19      InitializeComponent();
20    }
21
22    protected override void DeregisterContentEvents() {
23      Content.OptimizeChanged -= new EventHandler(Content_OptimizeChanged);
[4984]24      Content.IsOptimizableChanged -= new EventHandler(Content_IsOptimizabeChanged);
[4981]25      base.DeregisterContentEvents();
26    }
27
28    protected override void RegisterContentEvents() {
29      base.RegisterContentEvents();
[4984]30      Content.IsOptimizableChanged += new EventHandler(Content_IsOptimizabeChanged);
[4981]31      Content.OptimizeChanged += new EventHandler(Content_OptimizeChanged);
32    }
33
34    #region Event Handlers (Content)
35    void Content_OptimizeChanged(object sender, EventArgs e) {
36      if (InvokeRequired) {
37        Invoke(new EventHandler(Content_OptimizeChanged), sender, e);
38      } else {
39        this.optimizeCheckBox.Checked = Content.Optimize;
40        if (Content.Optimize) {
41          this.viewHost.ViewType = null;
[5653]42
43          var pc = Content as IParameterConfiguration;
44          var vc = Content as IValueConfiguration;
45
46          if (pc != null) {
[5665]47            if (pc is SingleValuedParameterConfiguration) {
48              this.viewHost.Content = ((ParameterizedValueConfiguration)pc.ValueConfigurations.Single()).ParameterConfigurations;
49            } else {
50              this.viewHost.Content = pc.ValueConfigurations;
51            }
52          } else if (vc != null) {
[5653]53            var rvc = Content as RangeValueConfiguration;
54            if (rvc != null) {
55              if (Content.ActualValue.ValueDataType == typeof(IntValue) ||
[4997]56                Content.ActualValue.ValueDataType == typeof(DoubleValue) ||
57                Content.ActualValue.ValueDataType == typeof(PercentValue)) {
[5653]58                this.viewHost.ViewsLabelVisible = true;
59                this.viewHost.Content = rvc.RangeConstraint;
60              } else if (Content.ActualValue.ValueDataType == typeof(BoolValue)) {
61                this.viewHost.Content = null; // no configuration required
62              }
63            }
64
65            var pvc = Content as ParameterizedValueConfiguration;
66            if (pvc != null) {
[5087]67              this.viewHost.ViewsLabelVisible = false;
[5653]68              this.viewHost.Content = pvc.ParameterConfigurations;
[4981]69            }
[5927]70
71            //var symbolicVc = Content as SymbolicExpressionGrammarValueConfiguration;
72            //if (symbolicVc != null) {
73            //  this.viewHost.ViewsLabelVisible = false;
74            //  this.viewHost.Content = symbolicVc.ParameterConfigurations;
75            //}
[4981]76          } else {
77            throw new NotSupportedException("Only IParameterConfiguration and IValueConfiguration types are allowed.");
78          }
79        } else {
[5087]80          this.viewHost.ViewsLabelVisible = false;
[6489]81          if (Content.ValuesReadOnly) {
82            this.viewHost.Content = new MessageItem("Cannot modify value directly. Please modify the value in the list of problems.");
83          } else {
84            this.viewHost.Content = Content.ActualValue;
85          }
[4981]86        }
87      }
[5087]88      SetEnabledStateOfControls();
[4981]89    }
[4984]90    void Content_IsOptimizabeChanged(object sender, EventArgs e) {
91      if (InvokeRequired) {
92        Invoke(new EventHandler(Content_IsOptimizabeChanged), sender, e);
93      } else {
94        SetEnabledStateOfControls();
95      }
96    }
[4981]97    #endregion
98
99    protected override void OnContentChanged() {
100      base.OnContentChanged();
101      if (Content != null) {
102        Content_OptimizeChanged(this, EventArgs.Empty);
103      } else {
104        this.viewHost.Content = null;
105      }
106    }
107
108    protected override void SetEnabledStateOfControls() {
109      base.SetEnabledStateOfControls();
[4984]110      if (Content != null) {
111        this.optimizeCheckBox.Enabled = !this.ReadOnly && Content.IsOptimizable;
112      }
[4981]113    }
114
115    #region Event Handlers (child controls)
116    private void optimizeCheckBox_CheckedChanged(object sender, EventArgs e) {
117      Content.Optimize = optimizeCheckBox.Checked;
118    }
119    #endregion
120  }
121}
Note: See TracBrowser for help on using the repository browser.