Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3707 was 3632, checked in by mkommend, 15 years ago

corrected RunCollectionConstraints and the according views (ticket#970)

File size: 3.9 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.DeregisterContentEvents();
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          if (Content.ConstraintData != null)
57            txtConstraintData.Text = Content.ConstraintData.GetValue();
58          else
59            this.Content_ConstraintColumnChanged(cmbConstraintColumn, EventArgs.Empty);
60        }
61      }
62    }
63
64    protected override void Content_ConstraintColumnChanged(object sender, EventArgs e) {
65      base.Content_ConstraintColumnChanged(sender, e);
66      this.Content.ConstraintData = (IStringConvertibleValue)Activator.CreateInstance(Content.ConstrainedValue.GetDataType(cmbConstraintColumn.SelectedItem.ToString()).First());
67    }
68
69    protected override void SetEnabledStateOfControls() {
70      base.SetEnabledStateOfControls();
71      txtConstraintData.ReadOnly = Content == null || this.ReadOnly;
72    }
73
74    protected virtual void Content_ConstraintDataChanged(object sender, EventArgs e) {
75      if (Content.ConstraintData != null)
76        txtConstraintData.Text = Content.ConstraintData.GetValue();
77      else
78        txtConstraintData.Text = string.Empty;
79    }
80
81    private void txtConstraintData_Validated(object sender, EventArgs e) {
82      IStringConvertibleValue value = (IStringConvertibleValue)Activator.CreateInstance(Content.ConstrainedValue.GetDataType(cmbConstraintColumn.SelectedItem.ToString()).First());
83      value.SetValue(txtConstraintData.Text);
84      Content.ConstraintData = value;
85    }
86
87    private void txtConstraintData_Validating(object sender, CancelEventArgs e) {
88      string errorMessage = string.Empty;
89      if (!Content.ConstraintData.Validate(txtConstraintData.Text, out errorMessage)) {
90        errorProvider.SetError(txtConstraintData, errorMessage);
91        e.Cancel = true;
92      } else
93        errorProvider.Clear();
94    }
95  }
96}
Note: See TracBrowser for help on using the repository browser.