Changeset 8610
- Timestamp:
- 09/10/12 13:17:25 (12 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 added
- 4 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Collections/3.3/HeuristicLab.Collections-3.3.csproj
r8600 r8610 114 114 <ItemGroup> 115 115 <None Include="Plugin.cs.frame" /> 116 <Compile Include="ReadOnlyObservableKeyedList.cs" /> 116 117 <Compile Include="INotifyObservableListItemsChanged.cs" /> 117 118 <Compile Include="INotifyObservableKeyedCollectionItemsChanged.cs" /> … … 119 120 <Compile Include="INotifyObservableCollectionItemsChanged.cs" /> 120 121 <Compile Include="INotifyObservableArrayItemsChanged.cs" /> 122 <Compile Include="IObservableKeyedList.cs" /> 123 <Compile Include="ObservableKeyedList.cs" /> 121 124 <Compile Include="Plugin.cs" /> 122 125 <Compile Include="ReadOnlyObservableArray.cs" /> … … 189 192 --> 190 193 <PropertyGroup> 191 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)194 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir) 192 195 set ProjectDir=$(ProjectDir) 193 196 set SolutionDir=$(SolutionDir) … … 196 199 call PreBuildEvent.cmd 197 200 </PreBuildEvent> 198 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">201 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' "> 199 202 export ProjectDir=$(ProjectDir) 200 203 export SolutionDir=$(SolutionDir) -
trunk/sources/HeuristicLab.Collections/3.3/ObservableList.cs
r7259 r8610 158 158 int capacity = list.Capacity; 159 159 list.Add(item); 160 OnItemsAdded(new IndexedItem<T>[] { new IndexedItem<T>(list.Count - 1, item) }); 161 OnItemsAdded(new T[] { item }); 160 162 if (list.Capacity != capacity) 161 163 OnPropertyChanged("Capacity"); 162 164 OnPropertyChanged("Item[]"); 163 165 OnPropertyChanged("Count"); 164 OnItemsAdded(new IndexedItem<T>[] { new IndexedItem<T>(list.Count - 1, item) });165 OnItemsAdded(new T[] { item });166 166 } 167 167 public void AddRange(IEnumerable<T> collection) { … … 175 175 } 176 176 if (items.Count > 0) { 177 OnItemsAdded(items); 178 OnItemsAdded(collection); 177 179 if (list.Capacity != capacity) 178 180 OnPropertyChanged("Capacity"); 179 181 OnPropertyChanged("Item[]"); 180 182 OnPropertyChanged("Count"); 181 OnItemsAdded(items);182 OnItemsAdded(collection);183 183 } 184 184 } … … 187 187 int capacity = list.Capacity; 188 188 list.Insert(index, item); 189 OnItemsAdded(new IndexedItem<T>[] { new IndexedItem<T>(index, item) }); 190 OnItemsAdded(new T[] { item }); 189 191 if (list.Capacity != capacity) 190 192 OnPropertyChanged("Capacity"); 191 193 OnPropertyChanged("Item[]"); 192 194 OnPropertyChanged("Count"); 193 OnItemsAdded(new IndexedItem<T>[] { new IndexedItem<T>(index, item) });194 OnItemsAdded(new T[] { item });195 195 } 196 196 public void InsertRange(int index, IEnumerable<T> collection) { … … 203 203 } 204 204 if (items.Count > 0) { 205 OnItemsAdded(items); 206 OnItemsAdded(collection); 205 207 if (list.Capacity != capacity) 206 208 OnPropertyChanged("Capacity"); 207 209 OnPropertyChanged("Item[]"); 208 210 OnPropertyChanged("Count"); 209 OnItemsAdded(items);210 OnItemsAdded(collection);211 211 } 212 212 } … … 229 229 else items = new List<IndexedItem<T>>(); 230 230 231 OnItemsReplaced(items, oldItems); 231 232 if (oldCapacity != list.Capacity) OnPropertyChanged("Capacity"); 232 233 OnPropertyChanged("Item[]"); 233 234 if (oldItems.Count != items.Count) OnPropertyChanged("Count"); 234 OnItemsReplaced(items, oldItems);235 235 } 236 236 … … 239 239 if (index != -1) { 240 240 list.RemoveAt(index); 241 OnPropertyChanged("Item[]");242 OnPropertyChanged("Count");243 241 OnItemsRemoved(new IndexedItem<T>[] { new IndexedItem<T>(index, item) }); 244 242 OnItemsRemoved(new T[] { item }); 243 OnPropertyChanged("Item[]"); 244 OnPropertyChanged("Count"); 245 245 return true; 246 246 } … … 260 260 if (indexedItems.Count > 0) { 261 261 result = list.RemoveAll(match); 262 OnPropertyChanged("Item[]");263 OnPropertyChanged("Count");264 262 OnItemsRemoved(indexedItems); 265 263 OnItemsRemoved(items); 264 OnPropertyChanged("Item[]"); 265 OnPropertyChanged("Count"); 266 266 } 267 267 return result; … … 270 270 T item = list[index]; 271 271 list.RemoveAt(index); 272 OnItemsRemoved(new IndexedItem<T>[] { new IndexedItem<T>(index, item) }); 273 OnItemsRemoved(new T[] { item }); 272 274 OnPropertyChanged("Item[]"); 273 275 OnPropertyChanged("Count"); 274 OnItemsRemoved(new IndexedItem<T>[] { new IndexedItem<T>(index, item) });275 OnItemsRemoved(new T[] { item });276 276 } 277 277 public void RemoveRange(int index, int count) { … … 281 281 list.CopyTo(index, items, 0, count); 282 282 list.RemoveRange(index, count); 283 OnPropertyChanged("Item[]");284 OnPropertyChanged("Count");285 283 OnItemsRemoved(indexedItems); 286 284 OnItemsRemoved(items); 285 OnPropertyChanged("Item[]"); 286 OnPropertyChanged("Count"); 287 287 } 288 288 } … … 293 293 T[] items = list.ToArray(); 294 294 list.Clear(); 295 OnPropertyChanged("Item[]");296 OnPropertyChanged("Count");297 295 OnCollectionReset(new IndexedItem<T>[0], indexedItems); 298 296 OnCollectionReset(new T[0], items); 297 OnPropertyChanged("Item[]"); 298 OnPropertyChanged("Count"); 299 299 } 300 300 } … … 304 304 IndexedItem<T>[] oldItems = GetIndexedItems(); 305 305 list.Reverse(); 306 OnPropertyChanged("Item[]");307 306 OnItemsMoved(GetIndexedItems(), oldItems); 307 OnPropertyChanged("Item[]"); 308 308 } 309 309 } … … 312 312 IndexedItem<T>[] oldItems = GetIndexedItems(index, count); 313 313 list.Reverse(index, count); 314 OnPropertyChanged("Item[]");315 314 OnItemsMoved(GetIndexedItems(index, count), oldItems); 315 OnPropertyChanged("Item[]"); 316 316 } 317 317 } … … 321 321 IndexedItem<T>[] oldItems = GetIndexedItems(); 322 322 list.Sort(); 323 OnPropertyChanged("Item[]");324 323 OnItemsMoved(GetIndexedItems(), oldItems); 324 OnPropertyChanged("Item[]"); 325 325 } 326 326 } … … 329 329 IndexedItem<T>[] oldItems = GetIndexedItems(); 330 330 list.Sort(comparison); 331 OnPropertyChanged("Item[]");332 331 OnItemsMoved(GetIndexedItems(), oldItems); 332 OnPropertyChanged("Item[]"); 333 333 } 334 334 } … … 337 337 IndexedItem<T>[] oldItems = GetIndexedItems(); 338 338 list.Sort(comparer); 339 OnPropertyChanged("Item[]");340 339 OnItemsMoved(GetIndexedItems(), oldItems); 340 OnPropertyChanged("Item[]"); 341 341 } 342 342 } … … 345 345 IndexedItem<T>[] oldItems = GetIndexedItems(index, count); 346 346 list.Sort(index, count, comparer); 347 OnPropertyChanged("Item[]");348 347 OnItemsMoved(GetIndexedItems(index, count), oldItems); 348 OnPropertyChanged("Item[]"); 349 349 } 350 350 } … … 355 355 return new ReadOnlyObservableList<T>(this); 356 356 } 357 357 358 public T[] ToArray() { 358 359 return list.ToArray(); -
trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableKeyedList.cs
r8606 r8610 21 21 22 22 using System; 23 using System.Collections;24 23 using System.Collections.Generic; 25 using System.ComponentModel;26 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 25 … … 29 27 [StorableClass] 30 28 [Serializable] 31 public class ReadOnlyObservableList<T> : IObservableList<T> { 32 [Storable] 33 protected IObservableList<T> list; 29 public class ReadOnlyObservableKeyedList<TKey, TItem> : ReadOnlyObservableList<TItem>, IObservableKeyedList<TKey, TItem> { 34 30 35 #region Properties 36 public int Count { 37 get { return ((ICollection<T>)list).Count; } 31 protected IObservableKeyedList<TKey, TItem> KeyedList { 32 get { return (IObservableKeyedList<TKey, TItem>)base.list; } 38 33 } 39 bool ICollection<T>.IsReadOnly { 34 35 bool ICollection<TItem>.IsReadOnly { 40 36 get { return true; } 41 37 } 42 43 public T this[int index] { 44 get { return list[index]; } 38 public TItem this[TKey key] { 39 get { return KeyedList[key]; } 45 40 } 46 T IList<T>.this[int index] {47 get { return list[index]; }48 set { throw new NotSupportedException(); }49 }50 #endregion51 41 52 42 #region Constructors 53 protected ReadOnlyObservableList() { } 54 public ReadOnlyObservableList(IObservableList<T> list) { 55 if (list == null) throw new ArgumentNullException(); 56 this.list = list; 43 protected ReadOnlyObservableKeyedList() { } 44 public ReadOnlyObservableKeyedList(IObservableKeyedList<TKey, TItem> keyedList) 45 : base(keyedList) { 57 46 RegisterEvents(); 58 47 } 59 48 [StorableConstructor] 60 protected ReadOnlyObservableList(bool deserializing) { } 61 49 protected ReadOnlyObservableKeyedList(bool deserializing) { } 62 50 [StorableHook(HookType.AfterDeserialization)] 63 51 private void AfterDeserialization() { … … 66 54 #endregion 67 55 68 #region Access 69 public bool Contains(T item) { 70 return list.Contains(item); 56 public bool ContainsKey(TKey key) { 57 return KeyedList.ContainsKey(key); 58 } 59 public bool TryGetValue(TKey key, out TItem item) { 60 return KeyedList.TryGetValue(key, out item); 71 61 } 72 62 73 public int IndexOf(T item) { 74 return list.IndexOf(item); 75 } 76 #endregion 77 78 #region Manipulation 79 void ICollection<T>.Add(T item) { 63 bool IObservableKeyedCollection<TKey, TItem>.Remove(TKey key) { 80 64 throw new NotSupportedException(); 81 65 } 82 66 83 void IList<T>.Insert(int index, T item) { 84 throw new NotSupportedException(); 85 } 86 87 bool ICollection<T>.Remove(T item) { 88 throw new NotSupportedException(); 89 } 90 void IList<T>.RemoveAt(int index) { 91 throw new NotSupportedException(); 92 } 93 94 void ICollection<T>.Clear() { 95 throw new NotSupportedException(); 96 } 97 98 void IObservableList<T>.Reverse() { 99 throw new NotSupportedException(); 100 } 101 void IObservableList<T>.Reverse(int index, int count) { 102 throw new NotSupportedException(); 103 } 104 #endregion 105 106 #region Conversion 107 public void CopyTo(T[] array, int arrayIndex) { 108 list.CopyTo(array, arrayIndex); 109 } 110 #endregion 111 112 #region Enumeration 113 public IEnumerator<T> GetEnumerator() { 114 return ((ICollection<T>)list).GetEnumerator(); 115 } 116 IEnumerator IEnumerable.GetEnumerator() { 117 return ((IEnumerable)list).GetEnumerator(); 118 } 119 #endregion 120 121 #region Events 122 protected void RegisterEvents() { 123 list.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_ItemsAdded); 124 ((IObservableCollection<T>)list).ItemsAdded += new CollectionItemsChangedEventHandler<T>(list_ItemsAdded); 125 list.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_ItemsRemoved); 126 ((IObservableCollection<T>)list).ItemsRemoved += new CollectionItemsChangedEventHandler<T>(list_ItemsRemoved); 127 list.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_ItemsReplaced); 128 list.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_ItemsMoved); 129 list.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_CollectionReset); 130 ((IObservableCollection<T>)list).CollectionReset += new CollectionItemsChangedEventHandler<T>(list_CollectionReset); 131 list.PropertyChanged += new PropertyChangedEventHandler(list_PropertyChanged); 67 #region events 68 private void RegisterEvents() { 69 ((INotifyObservableKeyedCollectionItemsChanged<TKey, TItem>)KeyedList).ItemsReplaced += keyedList_ItemsReplaced; 132 70 } 133 71 134 72 [field: NonSerialized] 135 public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsAdded; 136 protected virtual void OnItemsAdded(IEnumerable<IndexedItem<T>> items) { 137 CollectionItemsChangedEventHandler<IndexedItem<T>> handler = ItemsAdded; 138 if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items)); 73 private event CollectionItemsChangedEventHandler<TItem> itemsReplaced; 74 event CollectionItemsChangedEventHandler<TItem> INotifyObservableKeyedCollectionItemsChanged<TKey, TItem>.ItemsReplaced { 75 add { itemsReplaced += value; } 76 remove { itemsReplaced -= value; } 77 } 78 private void OnItemsReplaced(IEnumerable<TItem> items, IEnumerable<TItem> oldItems) { 79 var handler = itemsReplaced; 80 if (handler != null) handler(this, new CollectionItemsChangedEventArgs<TItem>(items, oldItems)); 139 81 } 140 82 141 [field: NonSerialized] 142 private event CollectionItemsChangedEventHandler<T> itemsAdded; 143 event CollectionItemsChangedEventHandler<T> INotifyObservableCollectionItemsChanged<T>.ItemsAdded { 144 add { itemsAdded += value; } 145 remove { itemsAdded -= value; } 146 } 147 private void OnItemsAdded(IEnumerable<T> items) { 148 CollectionItemsChangedEventHandler<T> handler = itemsAdded; 149 if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items)); 83 private void keyedList_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<TItem> e) { 84 OnItemsReplaced(e.Items, e.OldItems); 150 85 } 151 86 152 [field: NonSerialized]153 public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsRemoved;154 protected virtual void OnItemsRemoved(IEnumerable<IndexedItem<T>> items) {155 CollectionItemsChangedEventHandler<IndexedItem<T>> handler = ItemsRemoved;156 if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items));157 }158 159 [field: NonSerialized]160 private event CollectionItemsChangedEventHandler<T> itemsRemoved;161 event CollectionItemsChangedEventHandler<T> INotifyObservableCollectionItemsChanged<T>.ItemsRemoved {162 add { itemsRemoved += value; }163 remove { itemsRemoved -= value; }164 }165 private void OnItemsRemoved(IEnumerable<T> items) {166 CollectionItemsChangedEventHandler<T> handler = itemsRemoved;167 if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items));168 }169 170 [field: NonSerialized]171 public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsReplaced;172 protected virtual void OnItemsReplaced(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) {173 CollectionItemsChangedEventHandler<IndexedItem<T>> handler = ItemsReplaced;174 if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));175 }176 177 [field: NonSerialized]178 public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsMoved;179 protected virtual void OnItemsMoved(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) {180 CollectionItemsChangedEventHandler<IndexedItem<T>> handler = ItemsMoved;181 if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));182 }183 184 [field: NonSerialized]185 public event CollectionItemsChangedEventHandler<IndexedItem<T>> CollectionReset;186 protected virtual void OnCollectionReset(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) {187 CollectionItemsChangedEventHandler<IndexedItem<T>> handler = CollectionReset;188 if (handler != null) handler(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems));189 }190 191 [field: NonSerialized]192 private event CollectionItemsChangedEventHandler<T> collectionReset;193 event CollectionItemsChangedEventHandler<T> INotifyObservableCollectionItemsChanged<T>.CollectionReset {194 add { collectionReset += value; }195 remove { collectionReset -= value; }196 }197 private void OnCollectionReset(IEnumerable<T> items, IEnumerable<T> oldItems) {198 CollectionItemsChangedEventHandler<T> handler = collectionReset;199 if (handler != null) handler(this, new CollectionItemsChangedEventArgs<T>(items, oldItems));200 }201 202 [field: NonSerialized]203 public event PropertyChangedEventHandler PropertyChanged;204 protected virtual void OnPropertyChanged(string propertyName) {205 PropertyChangedEventHandler handler = PropertyChanged;206 if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));207 }208 209 private void list_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {210 OnItemsAdded(e.Items);211 }212 private void list_ItemsAdded(object sender, CollectionItemsChangedEventArgs<T> e) {213 OnItemsAdded(e.Items);214 }215 private void list_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {216 OnItemsRemoved(e.Items);217 }218 private void list_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<T> e) {219 OnItemsRemoved(e.Items);220 }221 private void list_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {222 OnItemsReplaced(e.Items, e.OldItems);223 }224 private void list_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {225 OnItemsMoved(e.Items, e.OldItems);226 }227 private void list_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {228 OnCollectionReset(e.Items, e.OldItems);229 }230 private void list_CollectionReset(object sender, CollectionItemsChangedEventArgs<T> e) {231 OnCollectionReset(e.Items, e.OldItems);232 }233 private void list_PropertyChanged(object sender, PropertyChangedEventArgs e) {234 if (e.PropertyName.Equals("Item[]") || e.PropertyName.Equals("Count"))235 OnPropertyChanged(e.PropertyName);236 }237 87 #endregion 238 88 } -
trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableList.cs
r7259 r8610 120 120 121 121 #region Events 122 pr otectedvoid RegisterEvents() {122 private void RegisterEvents() { 123 123 list.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_ItemsAdded); 124 124 ((IObservableCollection<T>)list).ItemsAdded += new CollectionItemsChangedEventHandler<T>(list_ItemsAdded); -
trunk/sources/HeuristicLab.Core/3.3/Collections/ReadOnlyItemList.cs
r7259 r8610 48 48 [StorableConstructor] 49 49 protected ReadOnlyItemList(bool deserializing) : base(deserializing) { } 50 protected ReadOnlyItemList(ReadOnlyItemList<T> original, Cloner cloner) { 50 protected ReadOnlyItemList(ReadOnlyItemList<T> original, Cloner cloner) 51 : base(cloner.Clone((IItemList<T>)original.list)) { 51 52 cloner.RegisterClonedObject(original, this); 52 list = cloner.Clone((IItemList<T>)original.list);53 RegisterEvents();54 53 } 55 54 public ReadOnlyItemList() : base(new ItemList<T>()) { }
Note: See TracChangeset
for help on using the changeset viewer.