1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Common;
|
---|
7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
8 |
|
---|
9 | namespace 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 | }
|
---|