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