using System; using System.Linq; using System.Windows.Forms; using HeuristicLab.Core; using HeuristicLab.Core.Views; using HeuristicLab.Encodings.ParameterConfigurationEncoding; using HeuristicLab.MainForm; using HeuristicLab.PluginInfrastructure; namespace HeuristicLab.Problems.MetaOptimization.Views { [View("ValueConfigurationList View")] [Content(typeof(ICheckedValueConfigurationList), IsDefaultView = true)] public sealed partial class ValueConfigurationCheckedItemCollectionView : CheckedItemListView { public new ICheckedValueConfigurationList Content { get { return (ICheckedValueConfigurationList)base.Content; } set { base.Content = value; } } public ValueConfigurationCheckedItemCollectionView() { InitializeComponent(); this.viewHost.ViewsLabelVisible = false; this.typeSelectorDialog = new TypeSelectorDialog(); } #region Event Handlers (Content) #endregion protected override void OnContentChanged() { base.OnContentChanged(); if (Content != null) { SetEnabledStateOfControls(); } else { } } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); if (Content != null) this.removeButton.Enabled = Content.Count > Content.MinItemCount; } #region Event Handlers (child controls) protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) { base.itemsListView_SelectedIndexChanged(sender, e); this.removeButton.Enabled = removeButton.Enabled && (Content.Count > Content.MinItemCount); } #endregion protected override IValueConfiguration CreateItem() { typeSelectorDialog.Caption = "Select Item"; typeSelectorDialog.TypeSelector.Caption = "Available Items"; typeSelectorDialog.TypeSelector.Configure(Content.ValidValues.Select(x => x.GetType()), false, false, false); if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) { try { IItem value = (IItem)Content.ValidValues.Single(x => x.GetType() == typeSelectorDialog.TypeSelector.SelectedType).Clone(); if (value is NullValue) { return new NullValueConfiguration(); } else if (value is IParameterizedItem) { return new ParameterizedValueConfiguration(value, value.GetType(), true); } else { return new RangeValueConfiguration(value, value.GetType()); } } catch (Exception ex) { ErrorHandling.ShowErrorDialog(this, ex); } } return null; } } }