Free cookie consent management tool by TermsFeed Policy Generator

source: tags/3.3.0/HeuristicLab.Optimization.Views/3.3/RunCollectionConstraintView.cs @ 7259

Last change on this file since 7259 was 3742, checked in by gkronber, 14 years ago

Fixed GPL license headers and deleted files which are not referenced by projects. #893

File size: 5.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.Drawing;
26using System.Linq;
27using System.Text;
28using System.Windows.Forms;
29using HeuristicLab.Core.Views;
30using HeuristicLab.Core;
31using HeuristicLab.Data;
32using HeuristicLab.MainForm;
33using HeuristicLab.Optimization;
34
35namespace HeuristicLab.Optimization.Views {
36  [Content(typeof(IRunCollectionConstraint))]
37  public partial class RunCollectionConstraintView : ItemView {
38    public RunCollectionConstraintView() {
39      InitializeComponent();
40    }
41
42    public new IRunCollectionConstraint Content {
43      get { return (IRunCollectionConstraint)base.Content; }
44      set { base.Content = value; }
45    }
46
47    protected override void OnContentChanged() {
48      base.OnContentChanged();
49      cmbConstraintColumn.Items.Clear();
50      cmbConstraintOperation.Items.Clear();
51      chbActive.Checked = false;
52      if (Content != null) {
53        cmbConstraintOperation.Items.AddRange(Content.AllowedConstraintOperations.ToArray());
54        if (Content.ConstraintOperation != null)
55          cmbConstraintOperation.SelectedItem = Content.ConstraintOperation;
56        else if (cmbConstraintOperation.Items.Count != 0)
57          cmbConstraintOperation.SelectedIndex = 0;
58        this.UpdateColumnComboBox();
59        chbActive.Checked = Content.Active;
60        this.ReadOnly = Content.Active;
61      }
62      SetEnabledStateOfControls();
63    }
64
65    protected virtual void UpdateColumnComboBox() {
66      this.cmbConstraintColumn.Items.Clear();
67      if (Content.ConstrainedValue != null) {
68        this.cmbConstraintColumn.Items.AddRange(((IStringConvertibleMatrix)Content.ConstrainedValue).ColumnNames.ToArray());
69        if (!string.IsNullOrEmpty(Content.ConstraintColumn))
70          this.cmbConstraintColumn.SelectedItem = Content.ConstraintColumn;
71      }
72    }
73
74    protected override void RegisterContentEvents() {
75      base.RegisterContentEvents();
76      this.Content.ActiveChanged += new EventHandler(Content_ActiveChanged);
77      this.Content.ConstraintOperationChanged += new EventHandler(Content_ComparisonOperationChanged);
78      this.Content.ConstraintColumnChanged += new EventHandler(Content_ConstraintColumnChanged);
79      this.Content.ConstrainedValueChanged += new EventHandler(Content_ConstrainedValueChanged);
80    }
81
82    protected override void DeregisterContentEvents() {
83      base.DeregisterContentEvents();
84      this.Content.ActiveChanged -= new EventHandler(Content_ActiveChanged);
85      this.Content.ConstraintOperationChanged -= new EventHandler(Content_ComparisonOperationChanged);
86      this.Content.ConstraintColumnChanged -= new EventHandler(Content_ConstraintColumnChanged);
87      this.Content.ConstrainedValueChanged += new EventHandler(Content_ConstrainedValueChanged);
88    }
89
90    protected override void OnReadOnlyChanged() {
91      base.OnReadOnlyChanged();
92      SetEnabledStateOfControls();
93    }
94    protected override void OnLockedChanged() {
95      base.OnLockedChanged();
96      SetEnabledStateOfControls();
97    }
98    protected virtual void SetEnabledStateOfControls() {
99      cmbConstraintColumn.Enabled = !this.ReadOnly && !this.Locked && Content != null;
100      cmbConstraintOperation.Enabled = !this.ReadOnly && !this.Locked && Content != null;
101      chbActive.Enabled = !this.Locked && Content != null;
102    }
103
104    protected virtual void Content_ConstrainedValueChanged(object sender, EventArgs e) {
105      this.UpdateColumnComboBox();
106    }
107
108    protected virtual void Content_ConstraintColumnChanged(object sender, EventArgs e) {
109      if (Content.ConstrainedValue != null) {
110        if (cmbConstraintColumn.SelectedItem.ToString() != Content.ConstraintColumn)
111          cmbConstraintColumn.SelectedItem = Content.ConstraintColumn;
112      }
113    }
114    private void cmbConstraintColumn_SelectedIndexChanged(object sender, EventArgs e) {
115      if (Content.ConstrainedValue != null) {
116        Content.ConstraintColumn = (string) cmbConstraintColumn.SelectedItem;
117      }
118    }
119
120    protected virtual void Content_ComparisonOperationChanged(object sender, EventArgs e) {
121      if (Content.ConstraintOperation != (ConstraintOperation)this.cmbConstraintOperation.SelectedItem)
122        this.cmbConstraintOperation.SelectedItem = Content.ConstraintOperation;
123    }
124    protected virtual void cmbComparisonOperation_SelectedIndexChanged(object sender, EventArgs e) {
125      Content.ConstraintOperation = (ConstraintOperation)this.cmbConstraintOperation.SelectedItem;
126    }
127
128    protected virtual void Content_ActiveChanged(object sender, EventArgs e) {
129      if (this.chbActive.Checked != Content.Active)
130        this.chbActive.Checked = Content.Active;
131      this.ReadOnly = Content.Active;
132    }
133    protected virtual void chbActive_CheckedChanged(object sender, EventArgs e) {
134      Content.Active = chbActive.Checked;
135    }
136  }
137}
Note: See TracBrowser for help on using the repository browser.