Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionConstraintView.cs @ 3634

Last change on this file since 3634 was 3614, checked in by mkommend, 15 years ago

implemented first version of RunConstraints (ticket #970)

File size: 5.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Linq;
6using System.Text;
7using System.Windows.Forms;
8using HeuristicLab.Core.Views;
9using HeuristicLab.Core;
10using HeuristicLab.Data;
11using HeuristicLab.MainForm;
12using HeuristicLab.Optimization;
13
14namespace HeuristicLab.Optimization.Views {
15  [Content(typeof(IRunCollectionConstraint))]
16  public partial class RunCollectionConstraintView : ItemView {
17    public RunCollectionConstraintView() {
18      InitializeComponent();
19    }
20
21    public new IRunCollectionConstraint Content {
22      get { return (IRunCollectionConstraint)base.Content; }
23      set { base.Content = value; }
24    }
25
26    protected override void OnContentChanged() {
27      base.OnContentChanged();
28      cmbConstraintColumn.Items.Clear();
29      cmbConstraintOperation.Items.Clear();
30      chbActive.Checked = false;
31      if (Content != null) {
32        cmbConstraintOperation.Items.AddRange(Content.AllowedConstraintOperations.ToArray());
33        if (Content.ConstraintOperation != null)
34          cmbConstraintOperation.SelectedItem = Content.ConstraintOperation;
35        else if (cmbConstraintOperation.Items.Count != 0)
36          cmbConstraintOperation.SelectedIndex = 0;
37        this.UpdateColumnComboBox();
38        chbActive.Checked = Content.Active;
39        this.ReadOnly = Content.Active;
40      }
41      SetEnabledStateOfControls();
42    }
43
44    protected virtual void UpdateColumnComboBox() {
45      this.cmbConstraintColumn.Items.Clear();
46      if (Content.ConstrainedValue != null) {
47        this.cmbConstraintColumn.Items.AddRange(((IStringConvertibleMatrix)Content.ConstrainedValue).ColumnNames.ToArray());
48        if (Content.ConstraintColumn >= 0)
49          this.cmbConstraintColumn.SelectedItem = ((IStringConvertibleMatrix)Content.ConstrainedValue).ColumnNames.ElementAt(Content.ConstraintColumn);
50      }
51    }
52
53    protected override void RegisterContentEvents() {
54      base.RegisterContentEvents();
55      this.Content.ActiveChanged += new EventHandler(Content_ActiveChanged);
56      this.Content.ConstraintOperationChanged += new EventHandler(Content_ComparisonOperationChanged);
57      this.Content.ConstraintColumnChanged += new EventHandler(Content_ConstraintColumnChanged);
58      this.Content.ConstrainedValueChanged += new EventHandler(Content_ConstrainedValueChanged);
59    }
60
61    protected override void DeregisterContentEvents() {
62      base.DeregisterContentEvents();
63      this.Content.ActiveChanged -= new EventHandler(Content_ActiveChanged);
64      this.Content.ConstraintOperationChanged -= new EventHandler(Content_ComparisonOperationChanged);
65      this.Content.ConstraintColumnChanged -= new EventHandler(Content_ConstraintColumnChanged);
66      this.Content.ConstrainedValueChanged += new EventHandler(Content_ConstrainedValueChanged);
67    }
68
69    protected override void OnReadOnlyChanged() {
70      base.OnReadOnlyChanged();
71      SetEnabledStateOfControls();
72    }
73    protected override void OnLockedChanged() {
74      base.OnLockedChanged();
75      SetEnabledStateOfControls();
76    }
77    protected virtual void SetEnabledStateOfControls() {
78      cmbConstraintColumn.Enabled = !this.ReadOnly && !this.Locked && Content != null;
79      cmbConstraintOperation.Enabled = !this.ReadOnly && !this.Locked && Content != null;
80      chbActive.Enabled = !this.Locked && Content != null;
81    }
82
83    protected virtual void Content_ConstrainedValueChanged(object sender, EventArgs e) {
84      this.UpdateColumnComboBox();
85    }
86
87    protected virtual void Content_ConstraintColumnChanged(object sender, EventArgs e) {
88      if (Content.ConstrainedValue != null) {
89        string columnName = ((IStringConvertibleMatrix)Content.ConstrainedValue).ColumnNames.ElementAt(Content.ConstraintColumn);
90        if (cmbConstraintColumn.SelectedItem.ToString() != columnName)
91          cmbConstraintColumn.SelectedItem = columnName;
92      }
93    }
94    private void cmbConstraintColumn_SelectedIndexChanged(object sender, EventArgs e) {
95      if (Content.ConstrainedValue != null) {
96        Content.ConstraintColumn = ((IStringConvertibleMatrix)Content.ConstrainedValue).ColumnNames.ToList().IndexOf(cmbConstraintColumn.SelectedItem.ToString());
97      }
98    }
99
100    protected virtual void Content_ComparisonOperationChanged(object sender, EventArgs e) {
101      if (Content.ConstraintOperation != (ConstraintOperation)this.cmbConstraintOperation.SelectedItem)
102        this.cmbConstraintOperation.SelectedItem = Content.ConstraintOperation;
103    }
104    protected virtual void cmbComparisonOperation_SelectedIndexChanged(object sender, EventArgs e) {
105      Content.ConstraintOperation = (ConstraintOperation)this.cmbConstraintOperation.SelectedItem;
106    }
107
108    protected virtual void Content_ActiveChanged(object sender, EventArgs e) {
109      if (this.chbActive.Checked != Content.Active)
110        this.chbActive.Checked = Content.Active;
111      this.ReadOnly = Content.Active;
112    }
113    protected virtual void chbActive_CheckedChanged(object sender, EventArgs e) {
114      Content.Active = chbActive.Checked;
115    }
116  }
117}
Note: See TracBrowser for help on using the repository browser.