[3614] | 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.Data;
|
---|
| 11 |
|
---|
| 12 | namespace HeuristicLab.Optimization.Views {
|
---|
| 13 | [Content(typeof(RunCollectionComparisonConstraint), true)]
|
---|
| 14 | public partial class RunCollectionComparisonConstraintView : RunCollectionConstraintView {
|
---|
| 15 | public RunCollectionComparisonConstraintView() {
|
---|
| 16 | InitializeComponent();
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | public new RunCollectionComparisonConstraint Content {
|
---|
| 20 | get { return (RunCollectionComparisonConstraint)base.Content; }
|
---|
| 21 | set { base.Content = value; }
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | protected override void OnContentChanged() {
|
---|
| 25 | base.OnContentChanged();
|
---|
| 26 | if (Content == null || Content.ConstraintData == null)
|
---|
| 27 | this.txtConstraintData.Text = string.Empty;
|
---|
| 28 | else
|
---|
| 29 | this.txtConstraintData.Text = Content.ConstraintData.GetValue();
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | protected override void RegisterContentEvents() {
|
---|
| 33 | base.RegisterContentEvents();
|
---|
| 34 | Content.ConstraintDataChanged += new EventHandler(Content_ConstraintDataChanged);
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | protected override void DeregisterContentEvents() {
|
---|
| 38 | base.RegisterContentEvents();
|
---|
| 39 | Content.ConstraintDataChanged -= new EventHandler(Content_ConstraintDataChanged);
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | protected override void UpdateColumnComboBox() {
|
---|
| 43 | this.cmbConstraintColumn.Items.Clear();
|
---|
| 44 | if (Content.ConstrainedValue != null) {
|
---|
| 45 | IStringConvertibleMatrix matrix = (IStringConvertibleMatrix)Content.ConstrainedValue;
|
---|
| 46 | foreach (string columnName in matrix.ColumnNames) {
|
---|
| 47 | IEnumerable<Type> dataTypes = Content.ConstrainedValue.GetDataType(columnName);
|
---|
| 48 | if (dataTypes.Count() == 1) {
|
---|
| 49 | Type dataType = dataTypes.First();
|
---|
| 50 | if (typeof(IStringConvertibleValue).IsAssignableFrom(dataType) && typeof(IComparable).IsAssignableFrom(dataType))
|
---|
| 51 | this.cmbConstraintColumn.Items.Add(columnName);
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | if (Content.ConstraintColumn >= 0)
|
---|
| 55 | this.cmbConstraintColumn.SelectedItem = (matrix.ColumnNames.ElementAt(Content.ConstraintColumn));
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | protected override void Content_ConstraintColumnChanged(object sender, EventArgs e) {
|
---|
| 60 | base.Content_ConstraintColumnChanged(sender, e);
|
---|
| 61 | this.Content.ConstraintData = (IStringConvertibleValue)Activator.CreateInstance(Content.ConstrainedValue.GetDataType(cmbConstraintColumn.SelectedItem.ToString()).First());
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | protected override void SetEnabledStateOfControls() {
|
---|
| 65 | base.SetEnabledStateOfControls();
|
---|
| 66 | txtConstraintData.ReadOnly = Content == null || this.ReadOnly;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | protected virtual void Content_ConstraintDataChanged(object sender, EventArgs e) {
|
---|
| 70 | if (Content.ConstraintData != null)
|
---|
| 71 | txtConstraintData.Text = Content.ConstraintData.GetValue();
|
---|
| 72 | else
|
---|
| 73 | txtConstraintData.Text = string.Empty;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | private void txtConstraintData_TextChanged(object sender, EventArgs e) {
|
---|
| 77 | Content.ConstraintData.SetValue(txtConstraintData.Text);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | private void txtConstraintData_Validating(object sender, CancelEventArgs e) {
|
---|
| 81 | string errorMessage;
|
---|
| 82 | if (!Content.ConstraintData.Validate(txtConstraintData.Text, out errorMessage)) {
|
---|
| 83 | errorProvider.SetError(txtConstraintData, errorMessage);
|
---|
| 84 | e.Cancel = true;
|
---|
| 85 | } else
|
---|
| 86 | errorProvider.Clear();
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 | }
|
---|