1 | using System;
|
---|
2 | using HeuristicLab.Common;
|
---|
3 | using HeuristicLab.Core;
|
---|
4 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
5 |
|
---|
6 | namespace HeuristicLab.Problems.MetaOptimization {
|
---|
7 | [StorableClass]
|
---|
8 | public class ValueConfiguration : DeepCloneable, IValueConfiguration {
|
---|
9 | [Storable]
|
---|
10 | protected IItemList<IParameterConfiguration> parameterConfigurations = new ItemList<IParameterConfiguration>();
|
---|
11 | public IItemList<IParameterConfiguration> ParameterConfigurations {
|
---|
12 | get { return this.parameterConfigurations; }
|
---|
13 | protected set { this.parameterConfigurations = value; }
|
---|
14 | }
|
---|
15 |
|
---|
16 | protected IItem value;
|
---|
17 | public IItem Value {
|
---|
18 | get { return value; }
|
---|
19 | set {
|
---|
20 | if (this.value != value) {
|
---|
21 | ClearChildParameterConfigurations();
|
---|
22 | this.value = value;
|
---|
23 | if (this.value is IParameterizedNamedItem) AddChildParameterConfigurations(this.value as IParameterizedNamedItem);
|
---|
24 | OnValueChanged();
|
---|
25 | }
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | protected Type valueDataType;
|
---|
30 | public Type ValueDataType {
|
---|
31 | get { return this.valueDataType; }
|
---|
32 | protected set { this.valueDataType = value; }
|
---|
33 | }
|
---|
34 |
|
---|
35 | public ValueConfiguration(IItem value, Type valueDataType) {
|
---|
36 | this.Value = value;
|
---|
37 | this.ValueDataType = valueDataType;
|
---|
38 | }
|
---|
39 |
|
---|
40 | public ValueConfiguration() { }
|
---|
41 | [StorableConstructor]
|
---|
42 | protected ValueConfiguration(bool deserializing) { }
|
---|
43 | protected ValueConfiguration(ValueConfiguration original, Cloner cloner) : base(original, cloner) {
|
---|
44 | this.ParameterConfigurations = cloner.Clone(original.ParameterConfigurations);
|
---|
45 | this.Value = cloner.Clone(original.Value);
|
---|
46 | this.ValueDataType = original.ValueDataType;
|
---|
47 |
|
---|
48 | }
|
---|
49 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
50 | return new ValueConfiguration(this, cloner);
|
---|
51 | }
|
---|
52 |
|
---|
53 | protected virtual void AddChildParameterConfigurations(IParameterizedNamedItem parameterizedItem) {
|
---|
54 | foreach (var childParameter in parameterizedItem.Parameters) {
|
---|
55 | var pc = ParameterConfiguration.Create(parameterizedItem, childParameter);
|
---|
56 | if (pc != null) this.ParameterConfigurations.Add(pc);
|
---|
57 | }
|
---|
58 | }
|
---|
59 | protected virtual void ClearChildParameterConfigurations() {
|
---|
60 | ParameterConfigurations.Clear();
|
---|
61 | }
|
---|
62 |
|
---|
63 | #region IItem Members
|
---|
64 | public string ItemDescription {
|
---|
65 | get { return value.ItemDescription; }
|
---|
66 | }
|
---|
67 |
|
---|
68 | public System.Drawing.Image ItemImage {
|
---|
69 | get { return value.ItemImage; }
|
---|
70 | }
|
---|
71 |
|
---|
72 | public string ItemName {
|
---|
73 | get { return value.ItemDescription; }
|
---|
74 | }
|
---|
75 |
|
---|
76 | public Version ItemVersion {
|
---|
77 | get { return value.ItemVersion; }
|
---|
78 | }
|
---|
79 | #endregion
|
---|
80 |
|
---|
81 | #region Events
|
---|
82 | public virtual event EventHandler ItemImageChanged;
|
---|
83 | protected virtual void OnItemImageChanged(object sender, EventArgs e) {
|
---|
84 | var handler = ItemImageChanged;
|
---|
85 | if (handler != null) handler(sender, e);
|
---|
86 | }
|
---|
87 |
|
---|
88 | public virtual event EventHandler ToStringChanged;
|
---|
89 | protected virtual void OnStringChanged(object sender, EventArgs e) {
|
---|
90 | var handler = ToStringChanged;
|
---|
91 | if (handler != null) handler(this, e); // important to set 'this' as sender
|
---|
92 | }
|
---|
93 |
|
---|
94 | public virtual event EventHandler ValueChanged;
|
---|
95 | protected virtual void OnValueChanged() {
|
---|
96 | var handler = ValueChanged;
|
---|
97 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
98 | }
|
---|
99 | #endregion
|
---|
100 |
|
---|
101 | public override string ToString() {
|
---|
102 | return value.ItemName;
|
---|
103 | }
|
---|
104 | }
|
---|
105 | }
|
---|