Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ValueConfigurationViews/ValueView.cs @ 5207

Last change on this file since 5207 was 5207, checked in by cneumuel, 14 years ago

#1215

  • lots of memory-consumption improvements
  • validValues -> validTypes (this saves memory!)
  • changed manipulators; modifications are less significant, out-of-bound-values are resampled instead of set to lower or upper bound
  • changed the way a base-level algorithm gets executed -> introduced AlgorithmExecutor
File size: 2.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9using HeuristicLab.Core.Views;
10using HeuristicLab.MainForm;
11using HeuristicLab.Core;
12using HeuristicLab.Parameters.Views;
13using HeuristicLab.PluginInfrastructure;
14
15namespace HeuristicLab.Problems.MetaOptimization.Views {
16  [View("Value View")]
17  [Content(typeof(ConstrainedValue), true)]
18  public partial class ValueView : ItemView {
19
20    public new ConstrainedValue Content {
21      get { return (ConstrainedValue)base.Content; }
22      set { base.Content = value; }
23    }
24
25    public ValueView() {
26      InitializeComponent();
27    }
28
29    protected override void OnContentChanged() {
30      base.OnContentChanged();
31      if (Content != null) {
32        valueViewHost.Content = Content.Value;
33      } else {
34        valueViewHost.Content = null;
35      }
36      SetEnabledStateOfControls();
37    }
38
39    protected override void SetEnabledStateOfControls() {
40      base.SetEnabledStateOfControls();
41      if (Content != null) {
42        clearValueButton.Enabled = Content.Value != null && Content.IsNullable; // IsNullable ist in diesem fall nicht richtig gesetzt
43        setValueButton.Enabled = Content.ValueDataType != null;
44      }
45    }
46
47    private void setValueButton_Click(object sender, EventArgs e) {
48      var typesWithoutNullValue = Content.ValidTypes.Where(x => x != typeof(NullValue));
49      var instances = typesWithoutNullValue.Select(x => (IItem)Activator.CreateInstance(x));
50      var groupedInstances = instances.GroupBy(x => ApplicationManager.Manager.GetDeclaringPlugin(x.GetType()).Name);
51
52      var objectSelectorDialog = new ObjectSelectorDialog<IItem>(groupedInstances);
53      if (objectSelectorDialog.ShowDialog(this) == DialogResult.OK) {
54        try {
55          Content.Value = objectSelectorDialog.Item;
56          valueViewHost.Content = Content.Value;
57        }
58        catch (Exception ex) {
59          ErrorHandling.ShowErrorDialog(this, ex);
60        }
61      }
62      SetEnabledStateOfControls();
63    }
64
65    private void clearValueButton_Click(object sender, EventArgs e) {
66      Content.Value = null;
67      valueViewHost.Content = null;
68      SetEnabledStateOfControls();
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.