1 | using System;
|
---|
2 | using System.Data;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Windows.Forms;
|
---|
5 | using HeuristicLab.Core.Views;
|
---|
6 | using HeuristicLab.MainForm;
|
---|
7 | using HeuristicLab.Core;
|
---|
8 | using HeuristicLab.PluginInfrastructure;
|
---|
9 |
|
---|
10 | namespace 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 | }
|
---|