using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Core; using HeuristicLab.Common; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.MetaOptimization { // todo: check that at least 1 elements needs to be selected // todo: control creatable item types [StorableClass] public class CheckedValueConfigurationCollection : CheckedItemCollection, ICheckedValueConfigurationCollection { [Storable] private int minItemCount = 1; public int MinItemCount { get { return minItemCount; } } [Storable] protected IItemSet validValues; public IItemSet ValidValues { get { return validValues; } } public CheckedValueConfigurationCollection(IItemSet validValues) { this.validValues = validValues; RegisterEvents(); } public CheckedValueConfigurationCollection() { RegisterEvents(); } [StorableConstructor] protected CheckedValueConfigurationCollection(bool deserializing) : base(deserializing) { RegisterEvents(); } protected CheckedValueConfigurationCollection(CheckedValueConfigurationCollection original, Cloner cloner) : base(original, cloner) { this.minItemCount = original.MinItemCount; this.validValues = original.validValues; RegisterEvents(); } public override IDeepCloneable Clone(Cloner cloner) { return new CheckedValueConfigurationCollection(this, cloner); } [StorableHook(HookType.AfterDeserialization)] private void AfterDeserialization() { RegisterEvents(); } private void RegisterEvents() { this.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler(CheckedValueConfigurationCollection_ItemsRemoved); } private void DeregisterEvents() { this.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler(CheckedValueConfigurationCollection_ItemsRemoved); } private void CheckedValueConfigurationCollection_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs e) { // auch collectionreset gehört berücksichtigt // funktioniert so nicht ganz, weil die view das hinzufügen nicht mitkriegt //if (this.Count < minItemCount) { // foreach (var item in e.Items) { // if (this.Count >= minItemCount) // break; // this.Add(item); // } //} } } }