[8055] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[11205] | 3 | * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[8055] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 26 | using HeuristicLab.PluginInfrastructure;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Clients.OKB.RunCreation {
|
---|
| 29 | [Item("NamedItemWrapper", "A wrapper which wraps an INamedItem.")]
|
---|
| 30 | [StorableClass]
|
---|
| 31 | [NonDiscoverableType]
|
---|
| 32 | public class NamedItemWrapper<T> : ItemWrapper<T>, INamedItem where T : class, INamedItem {
|
---|
| 33 | protected override T WrappedItem {
|
---|
| 34 | get { return base.WrappedItem; }
|
---|
| 35 | set {
|
---|
| 36 | if (value == null) throw new ArgumentNullException("WrappedItem", "WrappedItem cannot be null.");
|
---|
| 37 | if (value != base.WrappedItem) {
|
---|
| 38 | CancelEventArgs<string> e = new CancelEventArgs<string>(value.Name);
|
---|
| 39 | OnNameChanging(e);
|
---|
| 40 | if (!e.Cancel) base.WrappedItem = value;
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | public virtual string Name {
|
---|
| 46 | get { return WrappedItem.Name; }
|
---|
| 47 | set { WrappedItem.Name = value; }
|
---|
| 48 | }
|
---|
| 49 | public virtual bool CanChangeName {
|
---|
| 50 | get { return WrappedItem.CanChangeName; }
|
---|
| 51 | }
|
---|
| 52 | public virtual string Description {
|
---|
| 53 | get { return WrappedItem.Description; }
|
---|
| 54 | set { WrappedItem.Description = value; }
|
---|
| 55 | }
|
---|
| 56 | public virtual bool CanChangeDescription {
|
---|
| 57 | get { return WrappedItem.CanChangeDescription; }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | [StorableConstructor]
|
---|
| 61 | protected NamedItemWrapper(bool deserializing) : base(deserializing) { }
|
---|
| 62 | protected NamedItemWrapper(NamedItemWrapper<T> original, Cloner cloner) : base(original, cloner) { }
|
---|
| 63 | public NamedItemWrapper(T item) : base(item) { }
|
---|
| 64 |
|
---|
| 65 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 66 | return new NamedItemWrapper<T>(this, cloner);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | protected override void OnWrappedItemChanged() {
|
---|
| 70 | base.OnWrappedItemChanged();
|
---|
| 71 | OnNameChanged();
|
---|
| 72 | OnDescriptionChanged();
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | #region Events
|
---|
| 76 | public event EventHandler<CancelEventArgs<string>> NameChanging;
|
---|
| 77 | protected virtual void OnNameChanging(CancelEventArgs<string> e) {
|
---|
| 78 | var handler = NameChanging;
|
---|
| 79 | if (handler != null) handler(this, e);
|
---|
| 80 | }
|
---|
| 81 | public event EventHandler NameChanged;
|
---|
| 82 | protected virtual void OnNameChanged() {
|
---|
| 83 | var handler = NameChanged;
|
---|
| 84 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 85 | }
|
---|
| 86 | public event EventHandler DescriptionChanged;
|
---|
| 87 | protected virtual void OnDescriptionChanged() {
|
---|
| 88 | var handler = DescriptionChanged;
|
---|
| 89 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | protected override void RegisterWrappedItemEvents() {
|
---|
| 93 | base.RegisterWrappedItemEvents();
|
---|
| 94 | WrappedItem.NameChanging += new EventHandler<CancelEventArgs<string>>(WrappedItem_NameChanging);
|
---|
| 95 | WrappedItem.NameChanged += new EventHandler(WrappedItem_NameChanged);
|
---|
| 96 | WrappedItem.DescriptionChanged += new EventHandler(WrappedItem_DescriptionChanged);
|
---|
| 97 | }
|
---|
| 98 | protected override void DeregisterWrappedItemEvents() {
|
---|
| 99 | WrappedItem.NameChanging -= new EventHandler<CancelEventArgs<string>>(WrappedItem_NameChanging);
|
---|
| 100 | WrappedItem.NameChanged -= new EventHandler(WrappedItem_NameChanged);
|
---|
| 101 | WrappedItem.DescriptionChanged -= new EventHandler(WrappedItem_DescriptionChanged);
|
---|
| 102 | base.DeregisterWrappedItemEvents();
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | protected virtual void WrappedItem_NameChanging(object sender, CancelEventArgs<string> e) {
|
---|
| 106 | OnNameChanging(e);
|
---|
| 107 | }
|
---|
| 108 | protected virtual void WrappedItem_NameChanged(object sender, EventArgs e) {
|
---|
| 109 | OnNameChanged();
|
---|
| 110 | }
|
---|
| 111 | protected virtual void WrappedItem_DescriptionChanged(object sender, EventArgs e) {
|
---|
| 112 | OnDescriptionChanged();
|
---|
| 113 | }
|
---|
| 114 | #endregion
|
---|
| 115 | }
|
---|
| 116 | }
|
---|