[4311] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.Optimization;
|
---|
| 6 | using HeuristicLab.Data;
|
---|
| 7 | using HeuristicLab.Collections;
|
---|
| 8 | using HeuristicLab.Core;
|
---|
| 9 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 10 | using HeuristicLab.Common.Resources;
|
---|
| 11 | using HeuristicLab.Common;
|
---|
| 12 | using HeuristicLab.Parameters;
|
---|
| 13 |
|
---|
| 14 | namespace 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 | }
|
---|