Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1215

  • worked on configurability of SymbolicExpressionGrammar
File size: 4.4 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;
[4997]81          this.viewHost.Content = Content.ActualValue;
[4981]82        }
83      }
[5087]84      SetEnabledStateOfControls();
[4981]85    }
[4984]86    void Content_IsOptimizabeChanged(object sender, EventArgs e) {
87      if (InvokeRequired) {
88        Invoke(new EventHandler(Content_IsOptimizabeChanged), sender, e);
89      } else {
90        SetEnabledStateOfControls();
91      }
92    }
[4981]93    #endregion
94
95    protected override void OnContentChanged() {
96      base.OnContentChanged();
97      if (Content != null) {
98        Content_OptimizeChanged(this, EventArgs.Empty);
99      } else {
100        this.viewHost.Content = null;
101      }
102    }
103
104    protected override void SetEnabledStateOfControls() {
105      base.SetEnabledStateOfControls();
[4984]106      if (Content != null) {
107        this.optimizeCheckBox.Enabled = !this.ReadOnly && Content.IsOptimizable;
108      }
[4981]109    }
110
111    #region Event Handlers (child controls)
112    private void optimizeCheckBox_CheckedChanged(object sender, EventArgs e) {
113      Content.Optimize = optimizeCheckBox.Checked;
114    }
115    #endregion
116  }
117}
Note: See TracBrowser for help on using the repository browser.