Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ValueConfigurations/CheckedValueConfigurationCollection.cs @ 4982

Last change on this file since 4982 was 4982, checked in by cneumuel, 14 years ago

#1215 worked on metaoptimization

File size: 2.4 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 Type valueDataType;
22    public Type ValueDataType {
23      get { return valueDataType; }
24    }
25
26    public CheckedValueConfigurationCollection(Type valueDataType) {
27      this.valueDataType = valueDataType;
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.valueDataType = original.valueDataType;
40      RegisterEvents();
41    }
42    public override IDeepCloneable Clone(Cloner cloner) {
43      return new CheckedValueConfigurationCollection(this, cloner);
44    }
45
46    private void RegisterEvents() {
47      this.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(CheckedValueConfigurationCollection_ItemsRemoved);
48    }
49    private void DeregisterEvents() {
50      this.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(CheckedValueConfigurationCollection_ItemsRemoved);
51    }
52
53    private void CheckedValueConfigurationCollection_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IValueConfiguration> e) {
54      // auch collectionreset gehört berücksichtigt
55      // funktioniert so nicht ganz, weil die view das hinzufügen nicht mitkriegt
56      //if (this.Count < minItemCount) {
57      //  foreach (var item in e.Items) {
58      //    if (this.Count >= minItemCount)
59      //      break;
60      //    this.Add(item);
61      //  }
62      //}
63    }
64  }
65}
Note: See TracBrowser for help on using the repository browser.