1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Linq;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Core.Views;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using HeuristicLab.MainForm;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Optimization.Views {
|
---|
30 | [Content(typeof(IRunCollectionColumnConstraint))]
|
---|
31 | public partial class RunCollectionColumnConstraintView : ItemView {
|
---|
32 | public RunCollectionColumnConstraintView() {
|
---|
33 | InitializeComponent();
|
---|
34 | }
|
---|
35 |
|
---|
36 | public new IRunCollectionColumnConstraint Content {
|
---|
37 | get { return (IRunCollectionColumnConstraint)base.Content; }
|
---|
38 | set { base.Content = value; }
|
---|
39 | }
|
---|
40 |
|
---|
41 | protected override void OnContentChanged() {
|
---|
42 | base.OnContentChanged();
|
---|
43 | cmbConstraintColumn.Items.Clear();
|
---|
44 | cmbConstraintOperation.Items.Clear();
|
---|
45 |
|
---|
46 | if (Content != null) {
|
---|
47 | cmbConstraintOperation.Items.AddRange(Content.AllowedConstraintOperations.ToArray());
|
---|
48 | if (Content.ConstraintOperation != null)
|
---|
49 | cmbConstraintOperation.SelectedItem = Content.ConstraintOperation;
|
---|
50 | else if (cmbConstraintOperation.Items.Count != 0)
|
---|
51 | cmbConstraintOperation.SelectedIndex = 0;
|
---|
52 | UpdateColumnComboBox();
|
---|
53 | chbActive.Checked = Content.Active;
|
---|
54 | ReadOnly = Content.Active;
|
---|
55 | } else
|
---|
56 | chbActive.Checked = false;
|
---|
57 | }
|
---|
58 |
|
---|
59 | protected virtual void UpdateColumnComboBox() {
|
---|
60 | this.cmbConstraintColumn.Items.Clear();
|
---|
61 | if (Content.ConstrainedValue != null) {
|
---|
62 | this.cmbConstraintColumn.Items.AddRange(((IStringConvertibleMatrix)Content.ConstrainedValue).ColumnNames.ToArray());
|
---|
63 | if (!string.IsNullOrEmpty(Content.ConstraintColumn))
|
---|
64 | this.cmbConstraintColumn.SelectedItem = Content.ConstraintColumn;
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | protected override void RegisterContentEvents() {
|
---|
69 | base.RegisterContentEvents();
|
---|
70 | this.Content.ActiveChanged += new EventHandler(Content_ActiveChanged);
|
---|
71 | this.Content.ConstraintOperationChanged += new EventHandler(Content_ComparisonOperationChanged);
|
---|
72 | this.Content.ConstraintColumnChanged += new EventHandler(Content_ConstraintColumnChanged);
|
---|
73 | this.Content.ConstrainedValueChanged += new EventHandler(Content_ConstrainedValueChanged);
|
---|
74 | }
|
---|
75 |
|
---|
76 | protected override void DeregisterContentEvents() {
|
---|
77 | base.DeregisterContentEvents();
|
---|
78 | this.Content.ActiveChanged -= new EventHandler(Content_ActiveChanged);
|
---|
79 | this.Content.ConstraintOperationChanged -= new EventHandler(Content_ComparisonOperationChanged);
|
---|
80 | this.Content.ConstraintColumnChanged -= new EventHandler(Content_ConstraintColumnChanged);
|
---|
81 | this.Content.ConstrainedValueChanged += new EventHandler(Content_ConstrainedValueChanged);
|
---|
82 | }
|
---|
83 |
|
---|
84 | protected override void SetEnabledStateOfControls() {
|
---|
85 | base.SetEnabledStateOfControls();
|
---|
86 | cmbConstraintColumn.Enabled = !this.ReadOnly && Content != null;
|
---|
87 | cmbConstraintOperation.Enabled = !this.ReadOnly && Content != null;
|
---|
88 | chbActive.Enabled = !this.Locked && Content != null;
|
---|
89 | }
|
---|
90 |
|
---|
91 | protected virtual void Content_ConstrainedValueChanged(object sender, EventArgs e) {
|
---|
92 | this.UpdateColumnComboBox();
|
---|
93 | }
|
---|
94 |
|
---|
95 | protected virtual void Content_ConstraintColumnChanged(object sender, EventArgs e) {
|
---|
96 | if (Content.ConstrainedValue != null) {
|
---|
97 | if (cmbConstraintColumn.SelectedItem.ToString() != Content.ConstraintColumn)
|
---|
98 | cmbConstraintColumn.SelectedItem = Content.ConstraintColumn;
|
---|
99 | }
|
---|
100 | }
|
---|
101 | private void cmbConstraintColumn_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
102 | if (Content.ConstrainedValue != null) {
|
---|
103 | Content.ConstraintColumn = (string)cmbConstraintColumn.SelectedItem;
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | protected virtual void Content_ComparisonOperationChanged(object sender, EventArgs e) {
|
---|
108 | if (Content.ConstraintOperation != (ConstraintOperation)this.cmbConstraintOperation.SelectedItem)
|
---|
109 | this.cmbConstraintOperation.SelectedItem = Content.ConstraintOperation;
|
---|
110 | }
|
---|
111 | protected virtual void cmbComparisonOperation_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
112 | Content.ConstraintOperation = (ConstraintOperation)this.cmbConstraintOperation.SelectedItem;
|
---|
113 | }
|
---|
114 |
|
---|
115 | protected virtual void Content_ActiveChanged(object sender, EventArgs e) {
|
---|
116 | if (this.chbActive.Checked != Content.Active)
|
---|
117 | this.chbActive.Checked = Content.Active;
|
---|
118 | this.ReadOnly = Content.Active;
|
---|
119 | }
|
---|
120 | protected virtual void chbActive_CheckedChanged(object sender, EventArgs e) {
|
---|
121 | if (Content != null)
|
---|
122 | Content.Active = chbActive.Checked;
|
---|
123 | }
|
---|
124 | }
|
---|
125 | }
|
---|