[4839] | 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")]
|
---|
[4981] | 17 | [Content(typeof(ConstrainedValue), true)]
|
---|
[4839] | 18 | public partial class ValueView : ItemView {
|
---|
| 19 |
|
---|
[4981] | 20 | public new ConstrainedValue Content {
|
---|
| 21 | get { return (ConstrainedValue)base.Content; }
|
---|
[4839] | 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 | }
|
---|
[5110] | 36 | SetEnabledStateOfControls();
|
---|
[4839] | 37 | }
|
---|
| 38 |
|
---|
[5110] | 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 |
|
---|
[4839] | 47 | private void setValueButton_Click(object sender, EventArgs e) {
|
---|
[5231] | 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));
|
---|
[5110] | 50 | if (objectSelectorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
[4839] | 51 | try {
|
---|
[5110] | 52 | Content.Value = objectSelectorDialog.Item;
|
---|
[4839] | 53 | valueViewHost.Content = Content.Value;
|
---|
| 54 | }
|
---|
| 55 | catch (Exception ex) {
|
---|
| 56 | ErrorHandling.ShowErrorDialog(this, ex);
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
[5110] | 59 | SetEnabledStateOfControls();
|
---|
[4839] | 60 | }
|
---|
| 61 |
|
---|
| 62 | private void clearValueButton_Click(object sender, EventArgs e) {
|
---|
| 63 | Content.Value = null;
|
---|
| 64 | valueViewHost.Content = null;
|
---|
[5110] | 65 | SetEnabledStateOfControls();
|
---|
[4839] | 66 | }
|
---|
| 67 | }
|
---|
| 68 | }
|
---|