[3742] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12118] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3742] | 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;
|
---|
[3614] | 23 | using System.Linq;
|
---|
[4068] | 24 | using HeuristicLab.Core;
|
---|
[3614] | 25 | using HeuristicLab.Core.Views;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
| 27 | using HeuristicLab.MainForm;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.Optimization.Views {
|
---|
[6673] | 30 | [Content(typeof(IRunCollectionColumnConstraint))]
|
---|
| 31 | public partial class RunCollectionColumnConstraintView : ItemView {
|
---|
| 32 | public RunCollectionColumnConstraintView() {
|
---|
[3614] | 33 | InitializeComponent();
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[6673] | 36 | public new IRunCollectionColumnConstraint Content {
|
---|
| 37 | get { return (IRunCollectionColumnConstraint)base.Content; }
|
---|
[3614] | 38 | set { base.Content = value; }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | protected override void OnContentChanged() {
|
---|
| 42 | base.OnContentChanged();
|
---|
| 43 | cmbConstraintColumn.Items.Clear();
|
---|
| 44 | cmbConstraintOperation.Items.Clear();
|
---|
[5007] | 45 |
|
---|
[3614] | 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;
|
---|
[5007] | 52 | UpdateColumnComboBox();
|
---|
[3614] | 53 | chbActive.Checked = Content.Active;
|
---|
[5007] | 54 | ReadOnly = Content.Active;
|
---|
| 55 | } else
|
---|
| 56 | chbActive.Checked = false;
|
---|
[3614] | 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());
|
---|
[3718] | 63 | if (!string.IsNullOrEmpty(Content.ConstraintColumn))
|
---|
| 64 | this.cmbConstraintColumn.SelectedItem = Content.ConstraintColumn;
|
---|
[3614] | 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 |
|
---|
[3904] | 84 | protected override void SetEnabledStateOfControls() {
|
---|
| 85 | base.SetEnabledStateOfControls();
|
---|
[4435] | 86 | cmbConstraintColumn.Enabled = !this.ReadOnly && Content != null;
|
---|
| 87 | cmbConstraintOperation.Enabled = !this.ReadOnly && Content != null;
|
---|
[3614] | 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) {
|
---|
[3718] | 97 | if (cmbConstraintColumn.SelectedItem.ToString() != Content.ConstraintColumn)
|
---|
| 98 | cmbConstraintColumn.SelectedItem = Content.ConstraintColumn;
|
---|
[3614] | 99 | }
|
---|
| 100 | }
|
---|
| 101 | private void cmbConstraintColumn_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 102 | if (Content.ConstrainedValue != null) {
|
---|
[4068] | 103 | Content.ConstraintColumn = (string)cmbConstraintColumn.SelectedItem;
|
---|
[3614] | 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) {
|
---|
[4152] | 121 | if (Content != null)
|
---|
| 122 | Content.Active = chbActive.Checked;
|
---|
[3614] | 123 | }
|
---|
| 124 | }
|
---|
| 125 | }
|
---|