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.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 | }
|
---|