Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionTypeCompatibilityConstraintView.cs @ 3623

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

implemented first version of RunConstraints (ticket #970)

File size: 2.1 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.Common;
11
12namespace HeuristicLab.Optimization.Views {
13  [Content(typeof(RunCollectionTypeCompatibilityConstraint), true)]
14  public partial class RunCollectionTypeCompatibilityConstraintView : RunCollectionConstraintView {
15    public RunCollectionTypeCompatibilityConstraintView() {
16      InitializeComponent();
17      cmbType.DisplayMember = "Name";
18    }
19
20    public new RunCollectionTypeCompatibilityConstraint Content {
21      get { return (RunCollectionTypeCompatibilityConstraint)base.Content; }
22      set { base.Content = value; }
23    }
24
25    protected override void Content_ConstraintColumnChanged(object sender, EventArgs e) {
26      base.Content_ConstraintColumnChanged(sender, e);
27      UpdateTypeColumn();
28    }
29
30    protected override void OnContentChanged() {
31      base.OnContentChanged();
32      UpdateTypeColumn();
33    }
34
35    protected virtual void UpdateTypeColumn() {
36      cmbType.Items.Clear();
37      if (Content != null && Content.ConstrainedValue != null) {
38        foreach (Type t in Content.ConstrainedValue.GetDataType(cmbConstraintColumn.SelectedItem.ToString()))
39          cmbType.Items.Add(t);
40        if (Content.ConstraintData != null)
41          cmbType.SelectedItem = Content.ConstraintData;
42        else if (cmbType.Items.Count > 0)
43          cmbType.SelectedIndex = 0;
44      }
45    }
46
47    protected override void SetEnabledStateOfControls() {
48      base.SetEnabledStateOfControls();
49      cmbType.Enabled = Content != null && !this.ReadOnly;
50    }
51
52    private void cmbType_SelectedIndexChanged(object sender, EventArgs e) {
53      if (Content != null)
54        Content.ConstraintData = (Type)cmbType.SelectedItem;
55    }
56
57    private struct ComboBoxItem {
58      public ComboBoxItem(string name, Type type) {
59        this.Name = name;
60        this.Type = type;
61      }
62      public string Name;
63      public Type Type;
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.