1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
6 | using HeuristicLab.Core;
|
---|
7 | using HeuristicLab.Common;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Parameters {
|
---|
10 | [StorableClass]
|
---|
11 | public class ParameterActualNameBinding : IParameterBinding {
|
---|
12 | [Storable]
|
---|
13 | private ILookupParameter source;
|
---|
14 | public ILookupParameter Source {
|
---|
15 | get { return source; }
|
---|
16 | }
|
---|
17 | [Storable]
|
---|
18 | private ILookupParameter destination;
|
---|
19 | public ILookupParameter Destination {
|
---|
20 | get { return destination; }
|
---|
21 | }
|
---|
22 |
|
---|
23 | [StorableConstructor]
|
---|
24 | protected ParameterActualNameBinding(bool deserializing) { }
|
---|
25 | protected ParameterActualNameBinding(ParameterActualNameBinding original, Cloner cloner) {
|
---|
26 | this.source = cloner.Clone(source);
|
---|
27 | this.destination = cloner.Clone(destination);
|
---|
28 | RegisterEventHandlers();
|
---|
29 | }
|
---|
30 | public ParameterActualNameBinding(ILookupParameter source, ILookupParameter destination) {
|
---|
31 | if (source == null) throw new ArgumentNullException("source");
|
---|
32 | if (destination == null) throw new ArgumentNullException("destination");
|
---|
33 | this.source = source;
|
---|
34 | this.destination = destination;
|
---|
35 | RegisterEventHandlers();
|
---|
36 | }
|
---|
37 |
|
---|
38 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
39 | return new ParameterActualNameBinding(this, cloner);
|
---|
40 | }
|
---|
41 |
|
---|
42 | public void Bind() {
|
---|
43 | RegisterEventHandlers();
|
---|
44 | }
|
---|
45 |
|
---|
46 | public void Unbind() {
|
---|
47 | DeregisterEventHandlers();
|
---|
48 | }
|
---|
49 |
|
---|
50 | [StorableHook(HookType.AfterDeserialization)]
|
---|
51 | private void AfterDeserialization() {
|
---|
52 | RegisterEventHandlers();
|
---|
53 | }
|
---|
54 |
|
---|
55 | private void RegisterEventHandlers() {
|
---|
56 | source.ActualNameChanged += new EventHandler(source_ActualNameChanged);
|
---|
57 | }
|
---|
58 |
|
---|
59 | private void DeregisterEventHandlers() {
|
---|
60 | source.ActualNameChanged -= new EventHandler(source_ActualNameChanged);
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | private void source_ActualNameChanged(object sender, EventArgs e) {
|
---|
65 | if (destination.ActualName != source.ActualName)
|
---|
66 | destination.ActualName = source.ActualName;
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|