Changeset 2932 for trunk/sources/HeuristicLab.Core/3.3/ItemList.cs
- Timestamp:
- 03/05/10 03:07:12 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/3.3/ItemList.cs
r2833 r2932 36 36 [Item("ItemList<T>", "Represents a list of items.")] 37 37 public class ItemList<T> : ObservableList<T>, IItem where T : class, IItem { 38 [Storable(Name = "RestoreEvents")]39 private object RestoreEvents {40 get { return null; }41 set {42 foreach (T item in this)43 if (item != null) item.Changed += new ChangedEventHandler(Item_Changed);44 }45 }46 47 38 public virtual string ItemName { 48 39 get { return ItemAttribute.GetName(this.GetType()); } … … 57 48 public ItemList() : base() { } 58 49 public ItemList(int capacity) : base(capacity) { } 59 public ItemList(IEnumerable<T> collection) : base(collection) { 60 foreach (T item in this) 61 if (item != null) item.Changed += new ChangedEventHandler(Item_Changed); 62 } 50 public ItemList(IEnumerable<T> collection) : base(collection) { } 63 51 64 52 public object Clone() { … … 76 64 } 77 65 78 public event ChangedEventHandler Changed; 79 protected void OnChanged() { 80 OnChanged(new ChangedEventArgs()); 81 } 82 protected virtual void OnChanged(ChangedEventArgs e) { 83 if ((e.RegisterChangedObject(this)) && (Changed != null)) 84 Changed(this, e); 85 } 86 87 protected override void OnItemsAdded(IEnumerable<IndexedItem<T>> items) { 88 foreach (IndexedItem<T> item in items) 89 if (item.Value != null) item.Value.Changed += new ChangedEventHandler(Item_Changed); 90 base.OnItemsAdded(items); 91 } 92 protected override void OnItemsRemoved(IEnumerable<IndexedItem<T>> items) { 93 foreach (IndexedItem<T> item in items) 94 if (item.Value != null) item.Value.Changed -= new ChangedEventHandler(Item_Changed); 95 base.OnItemsRemoved(items); 96 } 97 protected override void OnItemsReplaced(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) { 98 foreach (IndexedItem<T> oldItem in oldItems) 99 if (oldItem.Value != null) oldItem.Value.Changed -= new ChangedEventHandler(Item_Changed); 100 foreach (IndexedItem<T> item in items) 101 if (item.Value != null) item.Value.Changed += new ChangedEventHandler(Item_Changed); 102 base.OnItemsReplaced(items, oldItems); 103 } 104 protected override void OnCollectionReset(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) { 105 foreach (IndexedItem<T> oldItem in oldItems) 106 if (oldItem.Value != null) oldItem.Value.Changed -= new ChangedEventHandler(Item_Changed); 107 foreach (IndexedItem<T> item in items) 108 if (item.Value != null) item.Value.Changed += new ChangedEventHandler(Item_Changed); 109 base.OnCollectionReset(items, oldItems); 110 } 111 protected override void OnPropertyChanged(string propertyName) { 112 base.OnPropertyChanged(propertyName); 113 OnChanged(); 114 } 115 116 private void Item_Changed(object sender, ChangedEventArgs e) { 117 OnChanged(e); 66 public event EventHandler ToStringChanged; 67 protected virtual void OnToStringChanged() { 68 if (ToStringChanged != null) 69 ToStringChanged(this, EventArgs.Empty); 118 70 } 119 71 }
Note: See TracChangeset
for help on using the changeset viewer.