Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectioComparisonConstraintView.cs @ 3627

Last change on this file since 3627 was 3614, checked in by mkommend, 14 years ago

implemented first version of RunConstraints (ticket #970)

File size: 3.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9using HeuristicLab.MainForm;
10using HeuristicLab.Data;
11
12namespace 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}
Note: See TracBrowser for help on using the repository browser.