[4981] | 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 | base.DeregisterContentEvents();
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | protected override void RegisterContentEvents() {
|
---|
| 35 | base.RegisterContentEvents();
|
---|
| 36 | Content.OptimizeChanged += new EventHandler(Content_OptimizeChanged);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | #region Event Handlers (Content)
|
---|
| 40 | void Content_OptimizeChanged(object sender, EventArgs e) {
|
---|
| 41 | if (InvokeRequired) {
|
---|
| 42 | Invoke(new EventHandler(Content_OptimizeChanged), sender, e);
|
---|
| 43 | } else {
|
---|
| 44 | this.optimizeCheckBox.Checked = Content.Optimize;
|
---|
| 45 | if (Content.Optimize) {
|
---|
| 46 | this.viewHost.ViewType = null;
|
---|
| 47 | if (Content is IParameterConfiguration) {
|
---|
| 48 | // this is a shortcut if only one possible ValueConfiguration is available
|
---|
| 49 | //if (((IParameterConfiguration)Content).ValueConfigurations.Count == 1) {
|
---|
| 50 | // IValueConfiguration vc = ((IParameterConfiguration)Content).ValueConfigurations.First();
|
---|
| 51 | // vc.Optimize = true;
|
---|
| 52 | // this.viewHost.Content = vc;
|
---|
| 53 | //} else {
|
---|
| 54 | // this.viewHost.Content = ((IParameterConfiguration)Content).ValueConfigurations;
|
---|
| 55 | //}
|
---|
| 56 | this.viewHost.Content = ((IParameterConfiguration)Content).ValueConfigurations;
|
---|
| 57 | } else if (Content is IValueConfiguration) {
|
---|
| 58 | if (Content.ConstrainedValue.ValueDataType == typeof(IntValue) ||
|
---|
| 59 | Content.ConstrainedValue.ValueDataType == typeof(DoubleValue)) {
|
---|
| 60 | this.viewHost.Content = ((IValueConfiguration)Content).RangeConstraint;
|
---|
| 61 | } else {
|
---|
| 62 | this.viewHost.Content = ((IValueConfiguration)Content).ParameterConfigurations;
|
---|
| 63 | }
|
---|
| 64 | } else {
|
---|
| 65 | throw new NotSupportedException("Only IParameterConfiguration and IValueConfiguration types are allowed.");
|
---|
| 66 | }
|
---|
| 67 | } else {
|
---|
| 68 | this.viewHost.Content = Content.ConstrainedValue;
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 | #endregion
|
---|
| 73 |
|
---|
| 74 | protected override void OnContentChanged() {
|
---|
| 75 | base.OnContentChanged();
|
---|
| 76 | if (Content != null) {
|
---|
| 77 | Content_OptimizeChanged(this, EventArgs.Empty);
|
---|
| 78 | } else {
|
---|
| 79 | this.viewHost.Content = null;
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | protected override void SetEnabledStateOfControls() {
|
---|
| 84 | base.SetEnabledStateOfControls();
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | #region Event Handlers (child controls)
|
---|
| 88 | private void optimizeCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 89 | Content.Optimize = optimizeCheckBox.Checked;
|
---|
| 90 | }
|
---|
| 91 | #endregion
|
---|
| 92 | }
|
---|
| 93 | }
|
---|