- Timestamp:
- 11/25/14 03:26:00 (10 years ago)
- Location:
- branches/OptimizationNetworks
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks
- Property svn:mergeinfo changed
-
branches/OptimizationNetworks/HeuristicLab.Optimization/3.3/RunCollection.cs
r9456 r11576 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.ComponentModel; 24 25 using System.Linq; 25 26 using HeuristicLab.Collections; … … 160 161 foreach (KeyValuePair<string, IItem> result in run.Results) 161 162 AddResult(result.Key, result.Value); 163 run.PropertyChanged += RunOnPropertyChanged; 164 RegisterRunParametersEvents(run); 165 RegisterRunResultsEvents(run); 166 } 167 foreach (IRun run in oldItems) { 168 run.PropertyChanged -= RunOnPropertyChanged; 169 DeregisterRunParametersEvents(run); 170 DeregisterRunResultsEvents(run); 162 171 } 163 172 columnNameCache = null; … … 178 187 foreach (KeyValuePair<string, IItem> result in run.Results) 179 188 columnsChanged |= AddResult(result.Key, result.Value); 189 run.PropertyChanged += RunOnPropertyChanged; 190 RegisterRunParametersEvents(run); 191 RegisterRunResultsEvents(run); 180 192 } 181 193 if (columnsChanged) columnNameCache = null; … … 198 210 foreach (string resultName in run.Results.Keys) 199 211 columnsChanged |= RemoveResultName(resultName); 212 run.PropertyChanged -= RunOnPropertyChanged; 213 DeregisterRunParametersEvents(run); 214 DeregisterRunResultsEvents(run); 200 215 } 201 216 if (columnsChanged) columnNameCache = null; … … 205 220 OnRowsChanged(); 206 221 OnRowNamesChanged(); 222 if (columnsChanged) { 223 OnColumnsChanged(); 224 OnColumnNamesChanged(); 225 } 226 } 227 228 private void RunOnPropertyChanged(object sender, PropertyChangedEventArgs e) { 229 if (e.PropertyName == "Parameters") { 230 RegisterRunParametersEvents((IRun)sender); 231 } else if (e.PropertyName == "Results") { 232 RegisterRunResultsEvents((IRun)sender); 233 } 234 } 235 236 private void RegisterRunParametersEvents(IRun run) { 237 IObservableDictionary<string, IItem> dict = run.Parameters; 238 dict.ItemsAdded += RunOnParameterChanged; 239 dict.ItemsRemoved += RunOnParameterRemoved; 240 dict.ItemsReplaced += RunOnParameterChanged; 241 dict.CollectionReset += RunOnParameterChanged; 242 } 243 244 private void RegisterRunResultsEvents(IRun run) { 245 IObservableDictionary<string, IItem> dict = run.Results; 246 dict.ItemsAdded += RunOnResultChanged; 247 dict.ItemsRemoved += RunOnResultRemoved; 248 dict.ItemsReplaced += RunOnResultChanged; 249 dict.CollectionReset += RunOnResultChanged; 250 } 251 252 private void DeregisterRunParametersEvents(IRun run) { 253 IObservableDictionary<string, IItem> dict = run.Parameters; 254 dict.ItemsAdded -= RunOnParameterChanged; 255 dict.ItemsRemoved -= RunOnParameterRemoved; 256 dict.ItemsReplaced -= RunOnParameterChanged; 257 dict.CollectionReset -= RunOnParameterChanged; 258 } 259 260 private void DeregisterRunResultsEvents(IRun run) { 261 IObservableDictionary<string, IItem> dict = run.Results; 262 dict.ItemsAdded -= RunOnResultChanged; 263 dict.ItemsRemoved -= RunOnResultRemoved; 264 dict.ItemsReplaced -= RunOnResultChanged; 265 dict.CollectionReset -= RunOnResultChanged; 266 } 267 268 private void RunOnParameterChanged(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>> e) { 269 bool columnsChanged = false; 270 foreach (var param in e.Items) 271 columnsChanged |= AddParameter(param.Key, param.Value); 272 foreach (var param in e.OldItems) 273 columnsChanged |= RemoveParameterName(param.Key); 274 if (columnsChanged) columnNameCache = null; 275 OnReset(); 276 if (columnsChanged) { 277 OnColumnsChanged(); 278 OnColumnNamesChanged(); 279 } 280 } 281 282 private void RunOnParameterRemoved(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>> e) { 283 bool columnsChanged = false; 284 foreach (var param in e.Items) 285 columnsChanged |= RemoveParameterName(param.Key); 286 if (columnsChanged) columnNameCache = null; 287 OnReset(); 288 if (columnsChanged) { 289 OnColumnsChanged(); 290 OnColumnNamesChanged(); 291 } 292 } 293 294 private void RunOnResultChanged(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>> e) { 295 bool columnsChanged = false; 296 foreach (var result in e.Items) 297 columnsChanged |= AddResult(result.Key, result.Value); 298 foreach (var result in e.OldItems) 299 columnsChanged |= RemoveResultName(result.Key); 300 if (columnsChanged) columnNameCache = null; 301 OnReset(); 302 if (columnsChanged) { 303 OnColumnsChanged(); 304 OnColumnNamesChanged(); 305 } 306 } 307 308 private void RunOnResultRemoved(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>> e) { 309 bool columnsChanged = false; 310 foreach (var result in e.Items) 311 columnsChanged |= RemoveResultName(result.Key); 312 if (columnsChanged) columnNameCache = null; 313 OnReset(); 207 314 if (columnsChanged) { 208 315 OnColumnsChanged();
Note: See TracChangeset
for help on using the changeset viewer.