[3742] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16956] | 3 | * Copyright (C) 2002-2019 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.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Linq;
|
---|
[4068] | 26 | using HeuristicLab.Data;
|
---|
[3614] | 27 | using HeuristicLab.MainForm;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.Optimization.Views {
|
---|
| 30 | [Content(typeof(RunCollectionComparisonConstraint), true)]
|
---|
[6673] | 31 | public partial class RunCollectionComparisonConstraintView : RunCollectionColumnConstraintView {
|
---|
[3614] | 32 | public RunCollectionComparisonConstraintView() {
|
---|
| 33 | InitializeComponent();
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | public new RunCollectionComparisonConstraint Content {
|
---|
| 37 | get { return (RunCollectionComparisonConstraint)base.Content; }
|
---|
| 38 | set { base.Content = value; }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | protected override void OnContentChanged() {
|
---|
| 42 | base.OnContentChanged();
|
---|
| 43 | if (Content == null || Content.ConstraintData == null)
|
---|
| 44 | this.txtConstraintData.Text = string.Empty;
|
---|
| 45 | else
|
---|
| 46 | this.txtConstraintData.Text = Content.ConstraintData.GetValue();
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | protected override void RegisterContentEvents() {
|
---|
| 50 | base.RegisterContentEvents();
|
---|
| 51 | Content.ConstraintDataChanged += new EventHandler(Content_ConstraintDataChanged);
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | protected override void DeregisterContentEvents() {
|
---|
[3632] | 55 | base.DeregisterContentEvents();
|
---|
[3614] | 56 | Content.ConstraintDataChanged -= new EventHandler(Content_ConstraintDataChanged);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | protected override void UpdateColumnComboBox() {
|
---|
| 60 | this.cmbConstraintColumn.Items.Clear();
|
---|
| 61 | if (Content.ConstrainedValue != null) {
|
---|
| 62 | IStringConvertibleMatrix matrix = (IStringConvertibleMatrix)Content.ConstrainedValue;
|
---|
| 63 | foreach (string columnName in matrix.ColumnNames) {
|
---|
| 64 | IEnumerable<Type> dataTypes = Content.ConstrainedValue.GetDataType(columnName);
|
---|
| 65 | if (dataTypes.Count() == 1) {
|
---|
| 66 | Type dataType = dataTypes.First();
|
---|
| 67 | if (typeof(IStringConvertibleValue).IsAssignableFrom(dataType) && typeof(IComparable).IsAssignableFrom(dataType))
|
---|
| 68 | this.cmbConstraintColumn.Items.Add(columnName);
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
[4068] | 71 | if (!string.IsNullOrEmpty(Content.ConstraintColumn)) {
|
---|
[3718] | 72 | this.cmbConstraintColumn.SelectedItem = Content.ConstraintColumn;
|
---|
[3632] | 73 | if (Content.ConstraintData != null)
|
---|
| 74 | txtConstraintData.Text = Content.ConstraintData.GetValue();
|
---|
| 75 | else
|
---|
| 76 | this.Content_ConstraintColumnChanged(cmbConstraintColumn, EventArgs.Empty);
|
---|
| 77 | }
|
---|
[3614] | 78 | }
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | protected override void Content_ConstraintColumnChanged(object sender, EventArgs e) {
|
---|
| 82 | base.Content_ConstraintColumnChanged(sender, e);
|
---|
| 83 | this.Content.ConstraintData = (IStringConvertibleValue)Activator.CreateInstance(Content.ConstrainedValue.GetDataType(cmbConstraintColumn.SelectedItem.ToString()).First());
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | protected override void SetEnabledStateOfControls() {
|
---|
| 87 | base.SetEnabledStateOfControls();
|
---|
[4435] | 88 | txtConstraintData.Enabled = Content != null;
|
---|
| 89 | txtConstraintData.ReadOnly = ReadOnly;
|
---|
[3614] | 90 | }
|
---|
| 91 |
|
---|
| 92 | protected virtual void Content_ConstraintDataChanged(object sender, EventArgs e) {
|
---|
| 93 | if (Content.ConstraintData != null)
|
---|
| 94 | txtConstraintData.Text = Content.ConstraintData.GetValue();
|
---|
| 95 | else
|
---|
| 96 | txtConstraintData.Text = string.Empty;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[3632] | 99 | private void txtConstraintData_Validated(object sender, EventArgs e) {
|
---|
| 100 | IStringConvertibleValue value = (IStringConvertibleValue)Activator.CreateInstance(Content.ConstrainedValue.GetDataType(cmbConstraintColumn.SelectedItem.ToString()).First());
|
---|
| 101 | value.SetValue(txtConstraintData.Text);
|
---|
| 102 | Content.ConstraintData = value;
|
---|
[3614] | 103 | }
|
---|
| 104 |
|
---|
| 105 | private void txtConstraintData_Validating(object sender, CancelEventArgs e) {
|
---|
[3632] | 106 | string errorMessage = string.Empty;
|
---|
[3614] | 107 | if (!Content.ConstraintData.Validate(txtConstraintData.Text, out errorMessage)) {
|
---|
| 108 | errorProvider.SetError(txtConstraintData, errorMessage);
|
---|
| 109 | e.Cancel = true;
|
---|
| 110 | } else
|
---|
| 111 | errorProvider.Clear();
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 | }
|
---|