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 System.Windows.Forms;
|
---|
9 | using HeuristicLab.MainForm;
|
---|
10 | using HeuristicLab.Core.Views;
|
---|
11 | using HeuristicLab.Core;
|
---|
12 | using HeuristicLab.Collections;
|
---|
13 |
|
---|
14 | namespace HeuristicLab.Problems.MetaOptimization.Views {
|
---|
15 | /// <summary>
|
---|
16 | /// The visual representation of a <see cref="ParameterConfiguration"/>.
|
---|
17 | /// </summary>
|
---|
18 | [View("ParameterConfiguration View")]
|
---|
19 | [Content(typeof(IParameterConfiguration), false)]
|
---|
20 | [Content(typeof(ParameterConfiguration), true)]
|
---|
21 | public partial class ParameterConfigurationView : ItemView {
|
---|
22 | /// <summary>
|
---|
23 | /// Gets or sets the variable to represent visually.
|
---|
24 | /// </summary>
|
---|
25 | /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
|
---|
26 | /// No own data storage present.</remarks>
|
---|
27 | public new IParameterConfiguration Content {
|
---|
28 | get { return (IParameterConfiguration)base.Content; }
|
---|
29 | set { base.Content = value; }
|
---|
30 | }
|
---|
31 |
|
---|
32 | public ParameterConfigurationView() {
|
---|
33 | InitializeComponent();
|
---|
34 | }
|
---|
35 |
|
---|
36 | protected override void OnContentChanged() {
|
---|
37 | base.OnContentChanged();
|
---|
38 | if (Content != null) {
|
---|
39 | optimizeCheckBox.Checked = Content.OptimizationEnabled;
|
---|
40 | valueViewHost.ViewType = typeof(ValueView);
|
---|
41 | valueViewHost.Content = Content;
|
---|
42 | if (Content is IntValueParameterConfiguration) {
|
---|
43 | configurationViewHost.Content = ((IntValueParameterConfiguration)Content).Ranges;
|
---|
44 | } else {
|
---|
45 | configurationViewHost.Content = null;
|
---|
46 | }
|
---|
47 |
|
---|
48 | childParameterConfigurationListView.Content = ((ParameterConfiguration)Content).ChildParameterConfigurations;
|
---|
49 | } else {
|
---|
50 | valueViewHost.Content = null;
|
---|
51 | configurationViewHost.Content = null;
|
---|
52 | childParameterConfigurationListView.Content = null;
|
---|
53 | }
|
---|
54 | SetEnabledStateOfControls();
|
---|
55 | }
|
---|
56 |
|
---|
57 | protected override void RegisterContentEvents() {
|
---|
58 | base.RegisterContentEvents();
|
---|
59 | Content.ChildParameterConfigurations.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IParameterConfiguration>>(ChildParameterConfigurations_ItemsAdded);
|
---|
60 | Content.ChildParameterConfigurations.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IParameterConfiguration>>(ChildParameterConfigurations_ItemsRemoved);
|
---|
61 | }
|
---|
62 | protected override void DeregisterContentEvents() {
|
---|
63 | Content.ChildParameterConfigurations.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<IParameterConfiguration>>(ChildParameterConfigurations_ItemsAdded);
|
---|
64 | Content.ChildParameterConfigurations.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<IParameterConfiguration>>(ChildParameterConfigurations_ItemsRemoved);
|
---|
65 | base.DeregisterContentEvents();
|
---|
66 | }
|
---|
67 |
|
---|
68 | void ChildParameterConfigurations_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<IParameterConfiguration>> e) {
|
---|
69 | SetEnabledStateOfControls();
|
---|
70 | }
|
---|
71 |
|
---|
72 | void ChildParameterConfigurations_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<IParameterConfiguration>> e) {
|
---|
73 | SetEnabledStateOfControls();
|
---|
74 | }
|
---|
75 |
|
---|
76 | protected override void SetEnabledStateOfControls() {
|
---|
77 | base.SetEnabledStateOfControls();
|
---|
78 | this.SuspendLayout();
|
---|
79 | if (optimizeCheckBox.Checked) {
|
---|
80 | DisableTabPage(valueTabPage);
|
---|
81 | EnableTabPage(configurationtabPage);
|
---|
82 | if (Content.ChildParameterConfigurations.Count > 0)
|
---|
83 | EnableTabPage(childParameterTabPage);
|
---|
84 | } else {
|
---|
85 | DisableTabPage(configurationtabPage);
|
---|
86 | DisableTabPage(childParameterTabPage);
|
---|
87 | EnableTabPage(valueTabPage);
|
---|
88 | }
|
---|
89 | this.ResumeLayout();
|
---|
90 | }
|
---|
91 |
|
---|
92 | private void optimizeCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
93 | Content.OptimizationEnabled = optimizeCheckBox.Checked;
|
---|
94 | SetEnabledStateOfControls();
|
---|
95 | }
|
---|
96 |
|
---|
97 | protected void EnableTabPage(TabPage tabPage) {
|
---|
98 | if (!tabControl.TabPages.Contains(tabPage)) {
|
---|
99 | tabControl.TabPages.Add(tabPage);
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | protected void DisableTabPage(TabPage tabPage) {
|
---|
104 | if (tabControl.TabPages.Contains(tabPage)) {
|
---|
105 | tabControl.TabPages.Remove(tabPage);
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|
109 | }
|
---|