Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceSpeedUp/HeuristicLab.Optimization.Views/3.3/RunCollectionComparisonConstraintView.cs @ 11544

Last change on this file since 11544 was 6760, checked in by epitzer, 13 years ago

#1530 integrate changes from trunk

File size: 4.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Linq;
26using HeuristicLab.Data;
27using HeuristicLab.MainForm;
28
29namespace HeuristicLab.Optimization.Views {
30  [Content(typeof(RunCollectionComparisonConstraint), true)]
31  public partial class RunCollectionComparisonConstraintView : RunCollectionColumnConstraintView {
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() {
55      base.DeregisterContentEvents();
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        }
71        if (!string.IsNullOrEmpty(Content.ConstraintColumn)) {
72          this.cmbConstraintColumn.SelectedItem = Content.ConstraintColumn;
73          if (Content.ConstraintData != null)
74            txtConstraintData.Text = Content.ConstraintData.GetValue();
75          else
76            this.Content_ConstraintColumnChanged(cmbConstraintColumn, EventArgs.Empty);
77        }
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();
88      txtConstraintData.Enabled = Content != null;
89      txtConstraintData.ReadOnly = ReadOnly;
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
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;
103    }
104
105    private void txtConstraintData_Validating(object sender, CancelEventArgs e) {
106      string errorMessage = string.Empty;
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}
Note: See TracBrowser for help on using the repository browser.