[3390] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 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 System.Collections.Generic;
|
---|
| 24 | using System.Drawing;
|
---|
| 25 | using System.Linq;
|
---|
| 26 | using HeuristicLab.Collections;
|
---|
| 27 | using HeuristicLab.Common;
|
---|
| 28 | using HeuristicLab.Common.Resources;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 |
|
---|
| 31 | namespace HeuristicLab.Core {
|
---|
| 32 | [StorableClass]
|
---|
| 33 | [Item("ReadOnlyItemArray<T>", "Represents a read-only array of items.")]
|
---|
| 34 | public class ReadOnlyItemArray<T> : ReadOnlyObservableArray<T>, IItemArray<T> where T : class, IItem {
|
---|
[3483] | 35 | private string filename;
|
---|
| 36 | public string Filename {
|
---|
| 37 | get { return filename; }
|
---|
| 38 | set {
|
---|
| 39 | if (!filename.Equals(value)) {
|
---|
| 40 | filename = value;
|
---|
| 41 | OnFilenameChanged();
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[3390] | 46 | public virtual string ItemName {
|
---|
| 47 | get { return ItemAttribute.GetName(this.GetType()); }
|
---|
| 48 | }
|
---|
| 49 | public virtual string ItemDescription {
|
---|
| 50 | get { return ItemAttribute.GetDescription(this.GetType()); }
|
---|
| 51 | }
|
---|
| 52 | public virtual Image ItemImage {
|
---|
| 53 | get { return VS2008ImageLibrary.Class; }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | [Storable]
|
---|
| 57 | private IObservableArray<T> Items {
|
---|
| 58 | get { return array; }
|
---|
| 59 | set { array = value; }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | public ReadOnlyItemArray() : base(new ItemArray<T>()) { }
|
---|
| 63 | public ReadOnlyItemArray(IItemArray<T> array) : base(array) { }
|
---|
| 64 | [StorableConstructor]
|
---|
| 65 | protected ReadOnlyItemArray(bool deserializing) { }
|
---|
| 66 |
|
---|
| 67 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 68 | private void Initialize() {
|
---|
| 69 | RegisterEvents();
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | public object Clone() {
|
---|
| 73 | return Clone(new Cloner());
|
---|
| 74 | }
|
---|
| 75 | public virtual IDeepCloneable Clone(Cloner cloner) {
|
---|
| 76 | ReadOnlyItemArray<T> clone = (ReadOnlyItemArray<T>)Activator.CreateInstance(this.GetType());
|
---|
| 77 | cloner.RegisterClonedObject(this, clone);
|
---|
| 78 | clone.array = (IItemArray<T>)((IItemArray<T>)array).Clone(cloner);
|
---|
| 79 | clone.Initialize();
|
---|
| 80 | return clone;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | public override string ToString() {
|
---|
| 84 | return ItemName;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[3483] | 87 | public event EventHandler FilenameChanged;
|
---|
| 88 | protected virtual void OnFilenameChanged() {
|
---|
| 89 | EventHandler handler = FilenameChanged;
|
---|
| 90 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 91 | }
|
---|
[3390] | 92 | public event EventHandler ItemImageChanged;
|
---|
| 93 | protected virtual void OnItemImageChanged() {
|
---|
| 94 | EventHandler handler = ItemImageChanged;
|
---|
| 95 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 96 | }
|
---|
| 97 | public event EventHandler ToStringChanged;
|
---|
| 98 | protected virtual void OnToStringChanged() {
|
---|
| 99 | EventHandler handler = ToStringChanged;
|
---|
| 100 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 | }
|
---|