1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Data;
|
---|
6 | using System.Linq;
|
---|
7 | using System.Text;
|
---|
8 | using HeuristicLab.Core.Views;
|
---|
9 | using HeuristicLab.MainForm;
|
---|
10 | using HeuristicLab.Parameters;
|
---|
11 | using HeuristicLab.Core;
|
---|
12 | using HeuristicLab.Data;
|
---|
13 |
|
---|
14 | namespace 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.ViewsLabelVisible = true;
|
---|
56 | this.viewHost.Content = ((IValueConfiguration)Content).RangeConstraint;
|
---|
57 | } else if(Content.ActualValue.ValueDataType == typeof(BoolValue)) {
|
---|
58 | this.viewHost.Content = null; // no configuration required
|
---|
59 | } else {
|
---|
60 | this.viewHost.ViewsLabelVisible = false;
|
---|
61 | this.viewHost.Content = ((IValueConfiguration)Content).ParameterConfigurations;
|
---|
62 | }
|
---|
63 | } else {
|
---|
64 | throw new NotSupportedException("Only IParameterConfiguration and IValueConfiguration types are allowed.");
|
---|
65 | }
|
---|
66 | } else {
|
---|
67 | this.viewHost.ViewsLabelVisible = false;
|
---|
68 | this.viewHost.Content = Content.ActualValue;
|
---|
69 | }
|
---|
70 | }
|
---|
71 | SetEnabledStateOfControls();
|
---|
72 | }
|
---|
73 | void Content_IsOptimizabeChanged(object sender, EventArgs e) {
|
---|
74 | if (InvokeRequired) {
|
---|
75 | Invoke(new EventHandler(Content_IsOptimizabeChanged), sender, e);
|
---|
76 | } else {
|
---|
77 | SetEnabledStateOfControls();
|
---|
78 | }
|
---|
79 | }
|
---|
80 | #endregion
|
---|
81 |
|
---|
82 | protected override void OnContentChanged() {
|
---|
83 | base.OnContentChanged();
|
---|
84 | if (Content != null) {
|
---|
85 | Content_OptimizeChanged(this, EventArgs.Empty);
|
---|
86 | } else {
|
---|
87 | this.viewHost.Content = null;
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | protected override void SetEnabledStateOfControls() {
|
---|
92 | base.SetEnabledStateOfControls();
|
---|
93 | if (Content != null) {
|
---|
94 | this.optimizeCheckBox.Enabled = !this.ReadOnly && Content.IsOptimizable;
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | #region Event Handlers (child controls)
|
---|
99 | private void optimizeCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
100 | Content.Optimize = optimizeCheckBox.Checked;
|
---|
101 | }
|
---|
102 | #endregion
|
---|
103 | }
|
---|
104 | }
|
---|