Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3975 was 3904, checked in by mkommend, 14 years ago

Added SetEnabledStateOfControls as protected virtual method in !View. Therefore the overloading of OnReadOnlyChanged and OnLockedChanged got obsolete in most views, because the method got called in the !View respectively ContentView. (ticket #1021)

File size: 5.4 KB
RevLine 
[3742]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;
[3614]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    }
63
64    protected virtual void UpdateColumnComboBox() {
65      this.cmbConstraintColumn.Items.Clear();
66      if (Content.ConstrainedValue != null) {
67        this.cmbConstraintColumn.Items.AddRange(((IStringConvertibleMatrix)Content.ConstrainedValue).ColumnNames.ToArray());
[3718]68        if (!string.IsNullOrEmpty(Content.ConstraintColumn))
69          this.cmbConstraintColumn.SelectedItem = Content.ConstraintColumn;
[3614]70      }
71    }
72
73    protected override void RegisterContentEvents() {
74      base.RegisterContentEvents();
75      this.Content.ActiveChanged += new EventHandler(Content_ActiveChanged);
76      this.Content.ConstraintOperationChanged += new EventHandler(Content_ComparisonOperationChanged);
77      this.Content.ConstraintColumnChanged += new EventHandler(Content_ConstraintColumnChanged);
78      this.Content.ConstrainedValueChanged += new EventHandler(Content_ConstrainedValueChanged);
79    }
80
81    protected override void DeregisterContentEvents() {
82      base.DeregisterContentEvents();
83      this.Content.ActiveChanged -= new EventHandler(Content_ActiveChanged);
84      this.Content.ConstraintOperationChanged -= new EventHandler(Content_ComparisonOperationChanged);
85      this.Content.ConstraintColumnChanged -= new EventHandler(Content_ConstraintColumnChanged);
86      this.Content.ConstrainedValueChanged += new EventHandler(Content_ConstrainedValueChanged);
87    }
88
[3904]89    protected override void SetEnabledStateOfControls() {
90      base.SetEnabledStateOfControls();
[3614]91      cmbConstraintColumn.Enabled = !this.ReadOnly && !this.Locked && Content != null;
92      cmbConstraintOperation.Enabled = !this.ReadOnly && !this.Locked && Content != null;
93      chbActive.Enabled = !this.Locked && Content != null;
94    }
95
96    protected virtual void Content_ConstrainedValueChanged(object sender, EventArgs e) {
97      this.UpdateColumnComboBox();
98    }
99
100    protected virtual void Content_ConstraintColumnChanged(object sender, EventArgs e) {
101      if (Content.ConstrainedValue != null) {
[3718]102        if (cmbConstraintColumn.SelectedItem.ToString() != Content.ConstraintColumn)
103          cmbConstraintColumn.SelectedItem = Content.ConstraintColumn;
[3614]104      }
105    }
106    private void cmbConstraintColumn_SelectedIndexChanged(object sender, EventArgs e) {
107      if (Content.ConstrainedValue != null) {
[3718]108        Content.ConstraintColumn = (string) cmbConstraintColumn.SelectedItem;
[3614]109      }
110    }
111
112    protected virtual void Content_ComparisonOperationChanged(object sender, EventArgs e) {
113      if (Content.ConstraintOperation != (ConstraintOperation)this.cmbConstraintOperation.SelectedItem)
114        this.cmbConstraintOperation.SelectedItem = Content.ConstraintOperation;
115    }
116    protected virtual void cmbComparisonOperation_SelectedIndexChanged(object sender, EventArgs e) {
117      Content.ConstraintOperation = (ConstraintOperation)this.cmbConstraintOperation.SelectedItem;
118    }
119
120    protected virtual void Content_ActiveChanged(object sender, EventArgs e) {
121      if (this.chbActive.Checked != Content.Active)
122        this.chbActive.Checked = Content.Active;
123      this.ReadOnly = Content.Active;
124    }
125    protected virtual void chbActive_CheckedChanged(object sender, EventArgs e) {
126      Content.Active = chbActive.Checked;
127    }
128  }
129}
Note: See TracBrowser for help on using the repository browser.