1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Data;
|
---|
6 | using System.Linq;
|
---|
7 | using System.Text;
|
---|
8 | using System.Windows.Forms;
|
---|
9 | using HeuristicLab.Core.Views;
|
---|
10 | using HeuristicLab.MainForm;
|
---|
11 | using HeuristicLab.Core;
|
---|
12 | using HeuristicLab.Parameters.Views;
|
---|
13 | using HeuristicLab.PluginInfrastructure;
|
---|
14 |
|
---|
15 | namespace 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 withoutNullValue = Content.ValidValues.Where(x => x != null && !(x is NullValue));
|
---|
49 | var objectSelectorDialog = new ObjectSelectorDialog<IItem>(withoutNullValue.GroupBy(x => ApplicationManager.Manager.GetDeclaringPlugin(x.GetType()).Name));
|
---|
50 | if (objectSelectorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
51 | try {
|
---|
52 | Content.Value = objectSelectorDialog.Item;
|
---|
53 | valueViewHost.Content = Content.Value;
|
---|
54 | }
|
---|
55 | catch (Exception ex) {
|
---|
56 | ErrorHandling.ShowErrorDialog(this, ex);
|
---|
57 | }
|
---|
58 | }
|
---|
59 | SetEnabledStateOfControls();
|
---|
60 | }
|
---|
61 |
|
---|
62 | private void clearValueButton_Click(object sender, EventArgs e) {
|
---|
63 | Content.Value = null;
|
---|
64 | valueViewHost.Content = null;
|
---|
65 | SetEnabledStateOfControls();
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|