Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 12012 was 12012, checked in by ascheibe, 9 years ago

#2212 merged r12008, r12009, r12010 back into trunk

File size: 2.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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 HeuristicLab.MainForm;
24
25namespace HeuristicLab.Optimization.Views {
26  [Content(typeof(RunCollectionTypeCompatibilityConstraint), true)]
27  public partial class RunCollectionTypeCompatibilityConstraintView : RunCollectionColumnConstraintView {
28    public RunCollectionTypeCompatibilityConstraintView() {
29      InitializeComponent();
30      cmbType.DisplayMember = "Name";
31    }
32
33    public new RunCollectionTypeCompatibilityConstraint Content {
34      get { return (RunCollectionTypeCompatibilityConstraint)base.Content; }
35      set { base.Content = value; }
36    }
37
38    protected override void Content_ConstraintColumnChanged(object sender, EventArgs e) {
39      base.Content_ConstraintColumnChanged(sender, e);
40      UpdateTypeColumn();
41    }
42
43    protected override void OnContentChanged() {
44      base.OnContentChanged();
45      UpdateTypeColumn();
46    }
47
48    protected virtual void UpdateTypeColumn() {
49      cmbType.Items.Clear();
50      if (Content != null && Content.ConstrainedValue != null) {
51        foreach (Type t in Content.ConstrainedValue.GetDataType(cmbConstraintColumn.SelectedItem.ToString()))
52          cmbType.Items.Add(t);
53        if (Content.ConstraintData != null)
54          cmbType.SelectedItem = Content.ConstraintData;
55        else if (cmbType.Items.Count > 0)
56          cmbType.SelectedIndex = 0;
57      }
58    }
59
60    protected override void SetEnabledStateOfControls() {
61      base.SetEnabledStateOfControls();
62      cmbType.Enabled = Content != null && !this.ReadOnly;
63    }
64
65    private void cmbType_SelectedIndexChanged(object sender, EventArgs e) {
66      if (Content != null)
67        Content.ConstraintData = (Type)cmbType.SelectedItem;
68    }
69
70    private struct ComboBoxItem {
71      public ComboBoxItem(string name, Type type) {
72        this.Name = name;
73        this.Type = type;
74      }
75      public string Name;
76      public Type Type;
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.