Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding.Views/3.3/ValueConfigurationViews/ValueView.cs @ 8648

Last change on this file since 8648 was 8648, checked in by jkarder, 12 years ago

#1853: fixed loss of valid values caused by setting optimize to true

File size: 3.2 KB
RevLine 
[8535]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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;
[8517]23using System.Linq;
24using System.Windows.Forms;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27using HeuristicLab.PluginInfrastructure;
28
29namespace HeuristicLab.Encodings.ParameterConfigurationEncoding.Views {
[8535]30  /// <summary>
31  /// The visual representation of a <see cref="ConstrainedValue"/>.
32  /// </summary>
[8517]33  [View("Value View")]
34  [Content(typeof(ConstrainedValue), true)]
35  public partial class ValueView : ItemView {
[8535]36    /// <summary>
37    /// Gets or sets the variable to represent visually.
38    /// </summary>
[8517]39    public new ConstrainedValue Content {
40      get { return (ConstrainedValue)base.Content; }
41      set { base.Content = value; }
42    }
43
44    public ValueView() {
45      InitializeComponent();
46    }
47
48    protected override void OnContentChanged() {
49      base.OnContentChanged();
50      if (Content != null) {
51        valueViewHost.Content = Content.Value;
52      } else {
53        valueViewHost.Content = null;
54      }
55      SetEnabledStateOfControls();
56    }
57
58    protected override void SetEnabledStateOfControls() {
59      base.SetEnabledStateOfControls();
60      if (Content != null) {
[8535]61        clearValueButton.Enabled = Content.Value != null && Content.IsNullable; // in this case IsNullable is not set correctly
[8517]62        setValueButton.Enabled = Content.ValueDataType != null;
63      }
64    }
65
66    private void setValueButton_Click(object sender, EventArgs e) {
67      var withoutNullValue = Content.ValidValues.Where(x => x != null && !(x is NullValue));
[8544]68      var typeSelectorDialog = new TypeSelectorDialog();
69      typeSelectorDialog.Caption = "Select Item";
70      typeSelectorDialog.TypeSelector.Caption = "Available Items";
71      typeSelectorDialog.TypeSelector.Configure(withoutNullValue.Select(x => x.GetType()), false, false, false);
72      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
[8517]73        try {
[8544]74          Content.Value = withoutNullValue.Single(x => x.GetType() == typeSelectorDialog.TypeSelector.SelectedType);
[8517]75          valueViewHost.Content = Content.Value;
76        }
77        catch (Exception ex) {
78          ErrorHandling.ShowErrorDialog(this, ex);
79        }
80      }
81      SetEnabledStateOfControls();
82    }
83
84    private void clearValueButton_Click(object sender, EventArgs e) {
85      Content.Value = null;
86      valueViewHost.Content = null;
87      SetEnabledStateOfControls();
88    }
89  }
90}
Note: See TracBrowser for help on using the repository browser.