using System; using System.Linq; using System.Windows.Forms; using HeuristicLab.Core; using HeuristicLab.Core.Views; 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; } #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() { var objectSelectorDialog = new ObjectSelectorDialog(Content.ValidValues.GroupBy(x => ApplicationManager.Manager.GetDeclaringPlugin(x.GetType()).Name)); if (objectSelectorDialog.ShowDialog(this) == DialogResult.OK) { try { IItem value = (IItem)objectSelectorDialog.Item.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; } } }