Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/CheckedValueConfigurationCollection.cs @ 5113

Last change on this file since 5113 was 5112, checked in by cneumuel, 13 years ago

#1215

  • resolving svn issue
File size: 2.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Common;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8
9namespace HeuristicLab.Problems.MetaOptimization {
10  // todo: check that at least 1 elements needs to be selected
11  // todo: control creatable item types
12  [StorableClass]
13  public class CheckedValueConfigurationCollection : CheckedItemCollection<IValueConfiguration>, ICheckedValueConfigurationCollection {
14    [Storable]
15    private int minItemCount = 1;
16    public int MinItemCount {
17      get { return minItemCount; }
18    }
19
20    [Storable]
21    protected IItemSet<IItem> validValues;
22    public IItemSet<IItem> ValidValues {
23      get { return validValues; }
24    }
25
26    public CheckedValueConfigurationCollection(IItemSet<IItem> validValues) {
27      this.validValues = validValues;
28      RegisterEvents();
29    }
30    public CheckedValueConfigurationCollection() {
31      RegisterEvents();
32    }
33    [StorableConstructor]
34    protected CheckedValueConfigurationCollection(bool deserializing) : base(deserializing) {
35      RegisterEvents();
36    }
37    protected CheckedValueConfigurationCollection(CheckedValueConfigurationCollection original, Cloner cloner) : base(original, cloner) {
38      this.minItemCount = original.MinItemCount;
39      this.validValues = original.validValues;
40      RegisterEvents();
41    }
42    public override IDeepCloneable Clone(Cloner cloner) {
43      return new CheckedValueConfigurationCollection(this, cloner);
44    }
45    [StorableHook(HookType.AfterDeserialization)]
46    private void AfterDeserialization() {
47      RegisterEvents();
48    }
49
50    private void RegisterEvents() {
51      this.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(CheckedValueConfigurationCollection_ItemsRemoved);
52    }
53    private void DeregisterEvents() {
54      this.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(CheckedValueConfigurationCollection_ItemsRemoved);
55    }
56
57    private void CheckedValueConfigurationCollection_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IValueConfiguration> e) {
58      // auch collectionreset gehört berücksichtigt
59      // funktioniert so nicht ganz, weil die view das hinzufügen nicht mitkriegt
60      //if (this.Count < minItemCount) {
61      //  foreach (var item in e.Items) {
62      //    if (this.Count >= minItemCount)
63      //      break;
64      //    this.Add(item);
65      //  }
66      //}
67    }
68  }
69}
Note: See TracBrowser for help on using the repository browser.