using System; using System.Data; using System.Linq; using System.Windows.Forms; using HeuristicLab.Core.Views; using HeuristicLab.MainForm; using HeuristicLab.Core; using HeuristicLab.PluginInfrastructure; namespace HeuristicLab.Problems.MetaOptimization.Views { [View("Value View")] [Content(typeof(ConstrainedValue), true)] public partial class ValueView : ItemView { public new ConstrainedValue Content { get { return (ConstrainedValue)base.Content; } set { base.Content = value; } } public ValueView() { InitializeComponent(); } protected override void OnContentChanged() { base.OnContentChanged(); if (Content != null) { valueViewHost.Content = Content.Value; } else { valueViewHost.Content = null; } SetEnabledStateOfControls(); } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); if (Content != null) { clearValueButton.Enabled = Content.Value != null && Content.IsNullable; // IsNullable ist in diesem fall nicht richtig gesetzt setValueButton.Enabled = Content.ValueDataType != null; } } private void setValueButton_Click(object sender, EventArgs e) { var withoutNullValue = Content.ValidValues.Where(x => x != null && !(x is NullValue)); var objectSelectorDialog = new ObjectSelectorDialog(withoutNullValue.GroupBy(x => ApplicationManager.Manager.GetDeclaringPlugin(x.GetType()).Name)); if (objectSelectorDialog.ShowDialog(this) == DialogResult.OK) { try { Content.Value = objectSelectorDialog.Item; valueViewHost.Content = Content.Value; } catch (Exception ex) { ErrorHandling.ShowErrorDialog(this, ex); } } SetEnabledStateOfControls(); } private void clearValueButton_Click(object sender, EventArgs e) { Content.Value = null; valueViewHost.Content = null; SetEnabledStateOfControls(); } } }