Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1853:

  • created branch for ParameterConfigurationEncoding
  • added CreateExperimentDialog that uses the extracted encoding
File size: 2.0 KB
Line 
1using System;
2using System.Linq;
3using System.Windows.Forms;
4using HeuristicLab.Core;
5using HeuristicLab.Core.Views;
6using HeuristicLab.MainForm;
7using HeuristicLab.PluginInfrastructure;
8
9namespace HeuristicLab.Encodings.ParameterConfigurationEncoding.Views {
10  [View("Value View")]
11  [Content(typeof(ConstrainedValue), true)]
12  public partial class ValueView : ItemView {
13
14    public new ConstrainedValue Content {
15      get { return (ConstrainedValue)base.Content; }
16      set { base.Content = value; }
17    }
18
19    public ValueView() {
20      InitializeComponent();
21    }
22
23    protected override void OnContentChanged() {
24      base.OnContentChanged();
25      if (Content != null) {
26        valueViewHost.Content = Content.Value;
27      } else {
28        valueViewHost.Content = null;
29      }
30      SetEnabledStateOfControls();
31    }
32
33    protected override void SetEnabledStateOfControls() {
34      base.SetEnabledStateOfControls();
35      if (Content != null) {
36        clearValueButton.Enabled = Content.Value != null && Content.IsNullable; // IsNullable ist in diesem fall nicht richtig gesetzt
37        setValueButton.Enabled = Content.ValueDataType != null;
38      }
39    }
40
41    private void setValueButton_Click(object sender, EventArgs e) {
42      var withoutNullValue = Content.ValidValues.Where(x => x != null && !(x is NullValue));
43      var objectSelectorDialog = new ObjectSelectorDialog<IItem>(withoutNullValue.GroupBy(x => ApplicationManager.Manager.GetDeclaringPlugin(x.GetType()).Name));
44      if (objectSelectorDialog.ShowDialog(this) == DialogResult.OK) {
45        try {
46          Content.Value = objectSelectorDialog.Item;
47          valueViewHost.Content = Content.Value;
48        }
49        catch (Exception ex) {
50          ErrorHandling.ShowErrorDialog(this, ex);
51        }
52      }
53      SetEnabledStateOfControls();
54    }
55
56    private void clearValueButton_Click(object sender, EventArgs e) {
57      Content.Value = null;
58      valueViewHost.Content = null;
59      SetEnabledStateOfControls();
60    }
61  }
62}
Note: See TracBrowser for help on using the repository browser.