Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ValueConfigurationViews/ValueView.cs @ 17717

Last change on this file since 17717 was 16996, checked in by gkronber, 6 years ago

#2520 Update plugin dependencies and references for HL.MetaOptimization for new persistence

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