Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1853:

  • enhanced combinations count calculation
  • restructured code
  • minor code improvements
  • added license information
File size: 3.1 KB
Line 
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;
23using System.Linq;
24using System.Windows.Forms;
25using HeuristicLab.Core;
26using HeuristicLab.Core.Views;
27using HeuristicLab.MainForm;
28using HeuristicLab.PluginInfrastructure;
29
30namespace HeuristicLab.Encodings.ParameterConfigurationEncoding.Views {
31  /// <summary>
32  /// The visual representation of a <see cref="ConstrainedValue"/>.
33  /// </summary>
34  [View("Value View")]
35  [Content(typeof(ConstrainedValue), true)]
36  public partial class ValueView : ItemView {
37    /// <summary>
38    /// Gets or sets the variable to represent visually.
39    /// </summary>
40    public new ConstrainedValue Content {
41      get { return (ConstrainedValue)base.Content; }
42      set { base.Content = value; }
43    }
44
45    public ValueView() {
46      InitializeComponent();
47    }
48
49    protected override void OnContentChanged() {
50      base.OnContentChanged();
51      if (Content != null) {
52        valueViewHost.Content = Content.Value;
53      } else {
54        valueViewHost.Content = null;
55      }
56      SetEnabledStateOfControls();
57    }
58
59    protected override void SetEnabledStateOfControls() {
60      base.SetEnabledStateOfControls();
61      if (Content != null) {
62        clearValueButton.Enabled = Content.Value != null && Content.IsNullable; // in this case IsNullable is not set correctly
63        setValueButton.Enabled = Content.ValueDataType != null;
64      }
65    }
66
67    private void setValueButton_Click(object sender, EventArgs e) {
68      var withoutNullValue = Content.ValidValues.Where(x => x != null && !(x is NullValue));
69      var objectSelectorDialog = new ObjectSelectorDialog<IItem>(withoutNullValue.GroupBy(x => ApplicationManager.Manager.GetDeclaringPlugin(x.GetType()).Name));
70      if (objectSelectorDialog.ShowDialog(this) == DialogResult.OK) {
71        try {
72          Content.Value = objectSelectorDialog.Item;
73          valueViewHost.Content = Content.Value;
74        }
75        catch (Exception ex) {
76          ErrorHandling.ShowErrorDialog(this, ex);
77        }
78      }
79      SetEnabledStateOfControls();
80    }
81
82    private void clearValueButton_Click(object sender, EventArgs e) {
83      Content.Value = null;
84      valueViewHost.Content = null;
85      SetEnabledStateOfControls();
86    }
87  }
88}
Note: See TracBrowser for help on using the repository browser.