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(IEnumerable<Type> validTypes) {
|
---|
27 | this.validValues = new ItemSet<IItem>();
|
---|
28 | foreach (Type t in validTypes) {
|
---|
29 | this.validValues.Add((IItem)Activator.CreateInstance(t));
|
---|
30 | }
|
---|
31 | RegisterEvents();
|
---|
32 | }
|
---|
33 | public CheckedValueConfigurationCollection() {
|
---|
34 | RegisterEvents();
|
---|
35 | }
|
---|
36 | [StorableConstructor]
|
---|
37 | protected CheckedValueConfigurationCollection(bool deserializing) : base(deserializing) {
|
---|
38 | RegisterEvents();
|
---|
39 | }
|
---|
40 | protected CheckedValueConfigurationCollection(CheckedValueConfigurationCollection original, Cloner cloner) : base(original, cloner) {
|
---|
41 | this.minItemCount = original.MinItemCount;
|
---|
42 | this.validValues = original.validValues;
|
---|
43 | RegisterEvents();
|
---|
44 | }
|
---|
45 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
46 | return new CheckedValueConfigurationCollection(this, cloner);
|
---|
47 | }
|
---|
48 | [StorableHook(HookType.AfterDeserialization)]
|
---|
49 | private void AfterDeserialization() {
|
---|
50 | RegisterEvents();
|
---|
51 | }
|
---|
52 |
|
---|
53 | private void RegisterEvents() {
|
---|
54 | this.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(CheckedValueConfigurationCollection_ItemsRemoved);
|
---|
55 | }
|
---|
56 | private void DeregisterEvents() {
|
---|
57 | this.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(CheckedValueConfigurationCollection_ItemsRemoved);
|
---|
58 | }
|
---|
59 |
|
---|
60 | private void CheckedValueConfigurationCollection_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IValueConfiguration> e) {
|
---|
61 | // auch collectionreset gehört berücksichtigt
|
---|
62 | // funktioniert so nicht ganz, weil die view das hinzufügen nicht mitkriegt
|
---|
63 | //if (this.Count < minItemCount) {
|
---|
64 | // foreach (var item in e.Items) {
|
---|
65 | // if (this.Count >= minItemCount)
|
---|
66 | // break;
|
---|
67 | // this.Add(item);
|
---|
68 | // }
|
---|
69 | //}
|
---|
70 | }
|
---|
71 | }
|
---|
72 | }
|
---|