[4839] | 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")]
|
---|
[4981] | 12 | [Content(typeof(ConstrainedValue), true)]
|
---|
[4839] | 13 | public partial class ValueView : ItemView {
|
---|
| 14 |
|
---|
[4981] | 15 | public new ConstrainedValue Content {
|
---|
| 16 | get { return (ConstrainedValue)base.Content; }
|
---|
[4839] | 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 | }
|
---|
[5110] | 31 | SetEnabledStateOfControls();
|
---|
[4839] | 32 | }
|
---|
| 33 |
|
---|
[5110] | 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 |
|
---|
[4839] | 42 | private void setValueButton_Click(object sender, EventArgs e) {
|
---|
[5231] | 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));
|
---|
[5110] | 45 | if (objectSelectorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
[4839] | 46 | try {
|
---|
[5110] | 47 | Content.Value = objectSelectorDialog.Item;
|
---|
[4839] | 48 | valueViewHost.Content = Content.Value;
|
---|
| 49 | }
|
---|
| 50 | catch (Exception ex) {
|
---|
| 51 | ErrorHandling.ShowErrorDialog(this, ex);
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
[5110] | 54 | SetEnabledStateOfControls();
|
---|
[4839] | 55 | }
|
---|
| 56 |
|
---|
| 57 | private void clearValueButton_Click(object sender, EventArgs e) {
|
---|
| 58 | Content.Value = null;
|
---|
| 59 | valueViewHost.Content = null;
|
---|
[5110] | 60 | SetEnabledStateOfControls();
|
---|
[4839] | 61 | }
|
---|
| 62 | }
|
---|
| 63 | }
|
---|