Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ParameterBinding/HeuristicLab.Optimization.Views/3.3/RunCollectionConstraintView.cs @ 10245

Last change on this file since 10245 was 4435, checked in by mkommend, 14 years ago

Adjusted the SetEnabledStateOfControls method in all views, added the Enabled property into the IView interface and adapted the ViewHost, View and ContentView class (ticket #1155).

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