Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB/HeuristicLab.OKB.AlgorithmHost/ParameterizedNamedItemContainer.cs @ 5698

Last change on this file since 5698 was 4311, checked in by swagner, 14 years ago

Integrated OKB clients for HL 3.3 (#1166)

File size: 2.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Optimization;
6using HeuristicLab.Data;
7using HeuristicLab.Collections;
8using HeuristicLab.Core;
9using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
10using HeuristicLab.Common.Resources;
11using HeuristicLab.Common;
12using HeuristicLab.Parameters;
13
14namespace HeuristicLab.OKB.AlgorithmHost {
15
16  [StorableClass]
17  public class ParameterizedNamedItemContainer : Item {
18
19    public ParameterizedNamedItemContainer() {
20      ParameterMapping = new ObservableDictionary<string, string>();
21    }
22
23    [StorableConstructor]
24    public ParameterizedNamedItemContainer(bool deserializing) : base(deserializing) { }
25
26    [Storable]
27    private IParameterizedNamedItem item;
28    public IParameterizedNamedItem Item {
29      get { return item; }
30      set {
31        if (value == item) return;
32        if (item != null)
33          DeregisterItemEvents();
34        item = value;
35        if (item != null)
36          RegisterItemEvents();
37        OnItemChanged();
38      }
39    }
40    public event EventHandler ItemChanged;
41    protected void OnItemChanged() {
42      InitializeMapping();
43      EventHandler handler = ItemChanged;
44      if (handler != null)
45        handler(this, EventArgs.Empty);
46    }
47
48    public virtual Type ItemType { get { return typeof(IParameterizedNamedItem); } }
49
50    [Storable]
51    public ObservableDictionary<string, string> ParameterMapping { get; private set; }
52
53    public virtual void InitializeMapping() {
54      ParameterMapping.Clear();
55      foreach (Parameter p in item.Parameters) {
56        ParameterMapping.Add(p.Name, null);
57      }
58    }
59
60    protected virtual void RegisterItemEvents() {
61    }
62
63    protected virtual void DeregisterItemEvents() {
64    }
65
66
67    public override string ItemName { get { return "ParameterizedNamedItemContainer"; } }
68    public override string ItemDescription { get { return "Container for parameterized named items to be stored in the OKB"; } }
69    public override System.Drawing.Image ItemImage { get { return VS2008ImageLibrary.Module; } }
70    public override string ToString() { return Item == null ? "Empty Container" : string.Format("<{0}>", Item.Name); }
71    public override HeuristicLab.Common.IDeepCloneable Clone(Cloner cloner) {
72      ParameterizedNamedItemContainer clone = (ParameterizedNamedItemContainer)Activator.CreateInstance(this.GetType());
73      cloner.RegisterClonedObject(this, clone);
74      clone.Item = (IParameterizedNamedItem)cloner.Clone(Item);
75      clone.ParameterMapping = new ObservableDictionary<string, string>();
76      foreach (var item in ParameterMapping) {
77        clone.ParameterMapping.Add(item.Key, item.Value);
78      }
79      return clone;
80    }
81  }
82}
Note: See TracBrowser for help on using the repository browser.