Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11344


Ignore:
Timestamp:
09/04/14 19:40:22 (10 years ago)
Author:
abeham
Message:

#2120:

  • Parameters and Results are now ObservableDictionaries
  • PropertyChanged event handler replaces the Changed event handler
  • RunCollection listens to changed events to each run's parameters and results (8 additional event handlers per run)
Location:
trunk/sources
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBRunView.cs

    r11171 r11344  
    2121
    2222using System;
     23using System.ComponentModel;
    2324using System.Windows.Forms;
    2425using HeuristicLab.Core.Views;
     
    4041
    4142    protected override void DeregisterContentEvents() {
    42       Content.StoredChanged -= new System.EventHandler(Content_StoredChanged);
     43      Content.PropertyChanged -= Content_PropertyChanged;
    4344      base.DeregisterContentEvents();
    4445    }
    4546    protected override void RegisterContentEvents() {
    4647      base.RegisterContentEvents();
    47       Content.StoredChanged += new System.EventHandler(Content_StoredChanged);
     48      Content.PropertyChanged += Content_PropertyChanged;
    4849    }
    4950
     
    5960
    6061    #region Content Events
    61     private void Content_StoredChanged(object sender, System.EventArgs e) {
    62       storeButton.Enabled = !Content.Stored;
     62    private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
     63      if (e.PropertyName == "Stored")
     64        storeButton.Enabled = !Content.Stored;
    6365    }
    6466    #endregion
     
    6870      try {
    6971        Content.Store();
    70       }
    71       catch (MissingClientRegistrationException) {
     72      } catch (MissingClientRegistrationException) {
    7273        MessageBox.Show("You have to register your client to be able to store OKB runs." + Environment.NewLine
    7374          + " Please click in the menu bar on Services -> Access -> Client Information and register your client. ", "Missing client registration", MessageBoxButtons.OK, MessageBoxIcon.Information);
    74       }
    75       catch (Exception ex) {
     75      } catch (Exception ex) {
    7676        ErrorHandling.ShowErrorDialog(this, "Store failed.", ex);
    7777      }
  • trunk/sources/HeuristicLab.Clients.OKB/3.3/RunCreation/OKBRun.cs

    r11171 r11344  
    2222using System;
    2323using System.Collections.Generic;
     24using System.ComponentModel;
    2425using System.Drawing;
    2526using System.IO;
    2627using HeuristicLab.Clients.Access;
     28using HeuristicLab.Collections;
    2729using HeuristicLab.Common;
    2830using HeuristicLab.Core;
     
    5153        if (value != stored) {
    5254          stored = value;
    53           OnStoredChanged();
     55          OnPropertyChanged("Stored");
    5456          OnItemImageChanged();
    5557        }
     
    6062      get { return WrappedItem.Algorithm; }
    6163    }
    62     public IDictionary<string, IItem> Parameters {
     64    public IObservableDictionary<string, IItem> Parameters {
    6365      get { return WrappedItem.Parameters; }
    6466    }
    65     public IDictionary<string, IItem> Results {
     67    public IObservableDictionary<string, IItem> Results {
    6668      get { return WrappedItem.Results; }
    6769    }
     
    162164
    163165    #region Events
    164     public event EventHandler Changed;
    165     private void OnChanged() {
    166       var handler = Changed;
    167       if (handler != null) handler(this, EventArgs.Empty);
    168     }
    169     public event EventHandler StoredChanged;
    170     private void OnStoredChanged() {
    171       var handler = StoredChanged;
    172       if (handler != null) handler(this, EventArgs.Empty);
     166    public event PropertyChangedEventHandler PropertyChanged;
     167    private void OnPropertyChanged(string property) {
     168      var handler = PropertyChanged;
     169      if (handler != null) handler(this, new PropertyChangedEventArgs(property));
    173170    }
    174171
    175172    protected override void RegisterWrappedItemEvents() {
    176173      base.RegisterWrappedItemEvents();
    177       WrappedItem.Changed += new EventHandler(WrappedItem_Changed);
     174      WrappedItem.PropertyChanged += WrappedItem_PropertyChanged;
    178175    }
    179176    protected override void DeregisterWrappedItemEvents() {
    180       WrappedItem.Changed -= new EventHandler(WrappedItem_Changed);
     177      WrappedItem.PropertyChanged -= WrappedItem_PropertyChanged;
    181178      base.DeregisterWrappedItemEvents();
    182179    }
    183180
    184     private void WrappedItem_Changed(object sender, EventArgs e) {
    185       OnChanged();
     181    private void WrappedItem_PropertyChanged(object sender, PropertyChangedEventArgs e) {
     182      OnPropertyChanged(e.PropertyName);
    186183    }
    187184    #endregion
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionBoxPlotView.cs

    r11171 r11344  
    2222using System;
    2323using System.Collections.Generic;
     24using System.ComponentModel;
    2425using System.Linq;
    2526using System.Windows.Forms;
     
    9293    protected virtual void RegisterRunEvents(IEnumerable<IRun> runs) {
    9394      foreach (IRun run in runs)
    94         run.Changed += new EventHandler(run_Changed);
     95        run.PropertyChanged += run_PropertyChanged;
    9596    }
    9697    protected virtual void DeregisterRunEvents(IEnumerable<IRun> runs) {
    9798      foreach (IRun run in runs)
    98         run.Changed -= new EventHandler(run_Changed);
     99        run.PropertyChanged -= run_PropertyChanged;
    99100    }
    100101
     
    133134      }
    134135    }
    135     private void run_Changed(object sender, EventArgs e) {
     136    private void run_PropertyChanged(object sender, PropertyChangedEventArgs e) {
    136137      if (InvokeRequired)
    137         this.Invoke(new EventHandler(run_Changed), sender, e);
     138        this.Invoke((Action<object, PropertyChangedEventArgs>)run_PropertyChanged, sender, e);
    138139      else if (!suppressUpdates) {
    139         UpdateDataPoints();
     140        if (e.PropertyName == "Visible")
     141          UpdateDataPoints();
    140142      }
    141143    }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionBubbleChartView.cs

    r11171 r11344  
    2222using System;
    2323using System.Collections.Generic;
     24using System.ComponentModel;
    2425using System.Drawing;
    2526using System.Linq;
     
    116117    protected virtual void RegisterRunEvents(IEnumerable<IRun> runs) {
    117118      foreach (IRun run in runs)
    118         run.Changed += new EventHandler(run_Changed);
     119        run.PropertyChanged += run_PropertyChanged;
    119120    }
    120121    protected virtual void DeregisterRunEvents(IEnumerable<IRun> runs) {
    121122      foreach (IRun run in runs)
    122         run.Changed -= new EventHandler(run_Changed);
     123        run.PropertyChanged -= run_PropertyChanged;
    123124    }
    124125
     
    133134      RegisterRunEvents(e.Items);
    134135    }
    135     private void run_Changed(object sender, EventArgs e) {
     136    private void run_PropertyChanged(object sender, PropertyChangedEventArgs e) {
    136137      if (suppressUpdates) return;
    137138      if (InvokeRequired)
    138         this.Invoke(new EventHandler(run_Changed), sender, e);
     139        this.Invoke((Action<object, PropertyChangedEventArgs>)run_PropertyChanged, sender, e);
    139140      else {
    140         IRun run = (IRun)sender;
    141         UpdateRun(run);
    142         UpdateCursorInterval();
    143         chart.ChartAreas[0].RecalculateAxesScale();
    144         UpdateAxisLabels();
     141        if (e.PropertyName == "Color" || e.PropertyName == "Visible") {
     142          IRun run = (IRun)sender;
     143          UpdateRun(run);
     144          UpdateCursorInterval();
     145          chart.ChartAreas[0].RecalculateAxesScale();
     146          UpdateAxisLabels();
     147        }
    145148      }
    146149    }
     
    670673      if (xAxisValue != null)
    671674        xAxis.Title = xAxisValue;
    672       if(yAxisValue != null)
    673       yAxis.Title = yAxisValue;
     675      if (yAxisValue != null)
     676        yAxis.Title = yAxisValue;
    674677    }
    675678
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionChartAggregationView.cs

    r11171 r11344  
    2222using System;
    2323using System.Collections.Generic;
     24using System.ComponentModel;
    2425using System.Linq;
    2526using System.Windows.Forms;
     
    111112
    112113    private void RegisterRunEvents(IRun run) {
    113       run.Changed += new System.EventHandler(run_Changed);
     114      run.PropertyChanged += run_PropertyChanged;
    114115    }
    115116    private void DeregisterRunEvents(IRun run) {
    116       run.Changed -= new System.EventHandler(run_Changed);
    117     }
    118     private void run_Changed(object sender, EventArgs e) {
     117      run.PropertyChanged -= run_PropertyChanged;
     118    }
     119    private void run_PropertyChanged(object sender, PropertyChangedEventArgs e) {
    119120      if (suppressUpdates) return;
    120       var run = (IRun)sender;
    121       UpdateRuns(new IRun[] { run });
     121      if (InvokeRequired) {
     122        Invoke((Action<object, PropertyChangedEventArgs>)run_PropertyChanged, sender, e);
     123      } else {
     124        var run = (IRun)sender;
     125        if (e.PropertyName == "Color" || e.PropertyName == "Visible")
     126          UpdateRuns(new IRun[] { run });
     127      }
    122128    }
    123129    #endregion
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionTableView.cs

    r11171 r11344  
    2222using System;
    2323using System.Collections.Generic;
     24using System.ComponentModel;
    2425using System.Linq;
    2526using System.Windows.Forms;
     
    7071    private void RegisterRunEvents(IEnumerable<IRun> runs) {
    7172      foreach (IRun run in runs)
    72         run.Changed += new EventHandler(run_Changed);
     73        run.PropertyChanged += run_PropertyChanged;
    7374    }
    7475    protected override void DeregisterContentEvents() {
     
    8384    private void DeregisterRunEvents(IEnumerable<IRun> runs) {
    8485      foreach (IRun run in runs)
    85         run.Changed -= new EventHandler(run_Changed);
     86        run.PropertyChanged -= run_PropertyChanged;
    8687    }
    8788    private void Content_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
     
    100101      else UpdateCaption();
    101102    }
    102     private void run_Changed(object sender, EventArgs e) {
     103    private void run_PropertyChanged(object sender, PropertyChangedEventArgs e) {
    103104      if (suppressUpdates) return;
    104105      if (InvokeRequired)
    105         this.Invoke(new EventHandler(run_Changed), sender, e);
     106        this.Invoke((Action<object, PropertyChangedEventArgs>)run_PropertyChanged, sender, e);
    106107      else {
    107108        IRun run = (IRun)sender;
    108         UpdateRun(run);
     109        if (e.PropertyName == "Color" || e.PropertyName == "Visible")
     110          UpdateRun(run);
    109111      }
    110112    }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionView.cs

    r11171 r11344  
    2323using System.Collections;
    2424using System.Collections.Generic;
     25using System.ComponentModel;
    2526using System.Drawing;
    2627using System.Linq;
     
    7980      item.ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
    8081      item.ToStringChanged -= new EventHandler(Item_ToStringChanged);
    81       item.Changed -= new EventHandler(Item_Changed);
     82      item.PropertyChanged -= Item_PropertyChanged;
    8283    }
    8384    private void RegisterItemEvents(IRun item) {
    8485      item.ItemImageChanged += new EventHandler(Item_ItemImageChanged);
    8586      item.ToStringChanged += new EventHandler(Item_ToStringChanged);
    86       item.Changed += new EventHandler(Item_Changed);
     87      item.PropertyChanged += Item_PropertyChanged;
    8788    }
    8889
     
    385386      try {
    386387        RunCollection.Modify();
    387       }
    388       finally {
     388      } finally {
    389389        ReadOnly = false;
    390390      }
     
    462462      }
    463463    }
    464     private void Item_Changed(object sender, EventArgs e) {
     464    private void Item_PropertyChanged(object sender, PropertyChangedEventArgs e) {
    465465      if (InvokeRequired)
    466         this.Invoke(new EventHandler(Item_Changed), sender, e);
     466        this.Invoke((Action<object, PropertyChangedEventArgs>)Item_PropertyChanged, sender, e);
    467467      else {
    468468        IRun run = (IRun)sender;
    469         UpdateRun(run);
     469        if (e.PropertyName == "Color" || e.PropertyName == "Visible")
     470          UpdateRun(run);
    470471      }
    471472    }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunView.cs

    r11171 r11344  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using System.ComponentModel;
     25using System.Linq;
    2326using System.Windows.Forms;
     27using HeuristicLab.Collections;
    2428using HeuristicLab.Common;
    2529using HeuristicLab.Core;
     
    3438  [Content(typeof(IRun), true)]
    3539  public sealed partial class RunView : NamedItemView {
     40    private readonly Dictionary<string, ListViewItem> parametersItemToListViewItem;
     41    private readonly Dictionary<string, ListViewItem> resultsItemToListViewItem;
    3642    /// <summary>
    3743    /// Gets or sets the variable to represent visually.
     
    4955    public RunView() {
    5056      InitializeComponent();
     57      parametersItemToListViewItem = new Dictionary<string, ListViewItem>();
     58      resultsItemToListViewItem = new Dictionary<string, ListViewItem>();
    5159    }
    5260
    5361    protected override void RegisterContentEvents() {
    5462      base.RegisterContentEvents();
    55       Content.Changed += new EventHandler(Content_Changed);
     63      Content.PropertyChanged += Content_PropertyChanged;
     64      RegisterContentParametersEvents();
     65      RegisterContentResultsEents();
     66    }
     67    private void RegisterContentParametersEvents() {
     68      Content.Parameters.ItemsAdded += ParametersOnItemsChanged;
     69      Content.Parameters.ItemsRemoved += ParametersOnItemsChanged;
     70      Content.Parameters.ItemsReplaced += ParametersOnItemsChanged;
     71      Content.Parameters.CollectionReset += ParametersOnItemsChanged;
     72    }
     73    private void RegisterContentResultsEents() {
     74      Content.Results.ItemsAdded += ResultsOnItemsChanged;
     75      Content.Results.ItemsRemoved += ResultsOnItemsChanged;
     76      Content.Results.ItemsReplaced += ResultsOnItemsChanged;
     77      Content.Results.CollectionReset += ResultsOnItemsChanged;
    5678    }
    5779    protected override void DeregisterContentEvents() {
    5880      base.DeregisterContentEvents();
    59       Content.Changed -= new EventHandler(Content_Changed);
    60     }
    61     private void Content_Changed(object sender, EventArgs e) {
    62       if (InvokeRequired)
    63         this.Invoke(new EventHandler(Content_Changed), sender, e);
    64       else
    65         UpdateColor();
     81      Content.PropertyChanged -= Content_PropertyChanged;
     82      DeregisterContentParametersEvents();
     83      DeregisterContentResultsEvents();
     84    }
     85    private void DeregisterContentParametersEvents() {
     86      Content.Parameters.ItemsAdded -= ParametersOnItemsChanged;
     87      Content.Parameters.ItemsRemoved -= ParametersOnItemsChanged;
     88      Content.Parameters.ItemsReplaced -= ParametersOnItemsChanged;
     89      Content.Parameters.CollectionReset -= ParametersOnItemsChanged;
     90    }
     91    private void DeregisterContentResultsEvents() {
     92      Content.Results.ItemsAdded -= ResultsOnItemsChanged;
     93      Content.Results.ItemsRemoved -= ResultsOnItemsChanged;
     94      Content.Results.ItemsReplaced -= ResultsOnItemsChanged;
     95      Content.Results.CollectionReset -= ResultsOnItemsChanged;
     96    }
     97
     98    private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
     99      if (e.PropertyName == "Color") {
     100        if (InvokeRequired) this.Invoke((Action)UpdateColor, null);
     101        else UpdateColor();
     102      } else if (e.PropertyName == "Parameters") {
     103        if (InvokeRequired) this.Invoke((Action<bool>)FillParametersListView, true);
     104        else FillParametersListView();
     105        RegisterContentParametersEvents();
     106      } else if (e.PropertyName == "Results") {
     107        if (InvokeRequired) this.Invoke((Action<bool>)FillResultsListView, true);
     108        else FillResultsListView();
     109        RegisterContentResultsEents();
     110      }
     111    }
     112
     113    private void ParametersOnItemsChanged(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>> e) {
     114      foreach (var item in e.OldItems) {
     115        listView.Items.Remove(parametersItemToListViewItem[item.Key]);
     116        parametersItemToListViewItem.Remove(item.Key);
     117      }
     118      foreach (var item in e.Items) {
     119        var listViewItem = CreateListViewItem(item.Key, Content.Parameters[item.Key], listView.Groups["parametersGroup"]);
     120        listView.Items.Add(listViewItem);
     121        parametersItemToListViewItem[item.Key] = listViewItem;
     122      }
     123    }
     124
     125    private void ResultsOnItemsChanged(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>> e) {
     126      foreach (var item in e.OldItems) {
     127        listView.Items.Remove(resultsItemToListViewItem[item.Key]);
     128        resultsItemToListViewItem.Remove(item.Key);
     129      }
     130      foreach (var item in e.Items) {
     131        var listViewItem = CreateListViewItem(item.Key, Content.Results[item.Key], listView.Groups["resultsGroup"]);
     132        listView.Items.Add(listViewItem);
     133        resultsItemToListViewItem[item.Key] = listViewItem;
     134      }
    66135    }
    67136
     
    101170      if (listView.SelectedItems.Count == 1) selectedName = listView.SelectedItems[0].SubItems[0].Text;
    102171
    103       listView.Items.Clear();
    104       listView.SmallImageList.Images.Clear();
     172      FillParametersListView(false);
     173      FillResultsListView(false);
     174      if (listView.Items.Count > 0) {
     175        for (int i = 0; i < listView.Columns.Count; i++)
     176          listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
     177        selectedName = null;
     178      }
     179    }
     180
     181    private void FillParametersListView(bool resize = true) {
     182      listView.BeginUpdate();
     183      foreach (var item in listView.Groups["parametersGroup"].Items.OfType<ListViewItem>().OrderByDescending(x => x.ImageIndex).ToList()) {
     184        listView.SmallImageList.Images.RemoveAt(item.ImageIndex);
     185        listView.Items.Remove(item);
     186      }
     187      parametersItemToListViewItem.Clear();
     188
     189      var counter = 0;
     190      foreach (var item in listView.Items.OfType<ListViewItem>().OrderBy(x => x.ImageIndex).ToList())
     191        item.ImageIndex = counter++;
     192      listView.EndUpdate();
     193
    105194      if (Content != null) {
    106         foreach (string key in Content.Parameters.Keys)
    107           CreateListViewItem(key, Content.Parameters[key], listView.Groups["parametersGroup"], selectedName);
    108         foreach (string key in Content.Results.Keys)
    109           CreateListViewItem(key, Content.Results[key], listView.Groups["resultsGroup"], selectedName);
    110         if (listView.Items.Count > 0) {
     195        foreach (string key in Content.Parameters.Keys) {
     196          var listViewItem = CreateListViewItem(key, Content.Parameters[key], listView.Groups["parametersGroup"]);
     197          listView.Items.Add(listViewItem);
     198          if ((selectedName != null) && key.Equals(selectedName)) listViewItem.Selected = true;
     199          parametersItemToListViewItem[key] = listViewItem;
     200        }
     201        if (resize && listView.Items.Count > 0) {
    111202          for (int i = 0; i < listView.Columns.Count; i++)
    112203            listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
    113           selectedName = null;
    114         }
    115       }
    116     }
    117 
    118     private void CreateListViewItem(string name, IItem value, ListViewGroup group, string selectedName) {
    119       ListViewItem item = new ListViewItem(new string[] { name, value != null ? value.ToString() : "-" });
     204        }
     205      }
     206    }
     207
     208    private void FillResultsListView(bool resize = true) {
     209      listView.BeginUpdate();
     210      foreach (var item in listView.Groups["resultsGroup"].Items.OfType<ListViewItem>().OrderByDescending(x => x.ImageIndex).ToList()) {
     211        listView.SmallImageList.Images.RemoveAt(item.ImageIndex);
     212        listView.Items.Remove(item);
     213      }
     214      resultsItemToListViewItem.Clear();
     215
     216      var counter = 0;
     217      foreach (var item in listView.Items.OfType<ListViewItem>().OrderBy(x => x.ImageIndex).ToList())
     218        item.ImageIndex = counter++;
     219      listView.EndUpdate();
     220
     221      if (Content != null) {
     222        foreach (string key in Content.Results.Keys) {
     223          var listViewItem = CreateListViewItem(key, Content.Results[key], listView.Groups["resultsGroup"]);
     224          listView.Items.Add(listViewItem);
     225          if ((selectedName != null) && key.Equals(selectedName)) listViewItem.Selected = true;
     226          resultsItemToListViewItem[key] = listViewItem;
     227        }
     228        if (resize && listView.Items.Count > 0) {
     229          for (int i = 0; i < listView.Columns.Count; i++)
     230            listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
     231        }
     232      }
     233    }
     234
     235    private ListViewItem CreateListViewItem(string name, IItem value, ListViewGroup group) {
     236      var item = new ListViewItem(new string[] { name, value != null ? value.ToString() : "-" });
    120237      item.Tag = value;
    121238      item.Group = group;
    122239      listView.SmallImageList.Images.Add(value == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : value.ItemImage);
    123240      item.ImageIndex = listView.SmallImageList.Images.Count - 1;
    124       listView.Items.Add(item);
    125       if ((selectedName != null) && name.Equals(selectedName)) item.Selected = true;
     241      return item;
    126242    }
    127243
  • trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/IRun.cs

    r11171 r11344  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
     22using System.ComponentModel;
    2423using System.Drawing;
     24using HeuristicLab.Collections;
    2525using HeuristicLab.Core;
    2626
     
    2929  /// Represents the parameters and results of an algorithm run.
    3030  /// </summary>
    31   public interface IRun : INamedItem {
     31  public interface IRun : INamedItem, INotifyPropertyChanged {
    3232    IAlgorithm Algorithm { get; }
    33     IDictionary<string, IItem> Parameters { get; }
    34     IDictionary<string, IItem> Results { get; }
     33    IObservableDictionary<string, IItem> Parameters { get; }
     34    IObservableDictionary<string, IItem> Results { get; }
    3535
    3636    Color Color { get; set; }
    3737    bool Visible { get; set; }
    38     event EventHandler Changed;
    3938  }
    4039}
  • trunk/sources/HeuristicLab.Optimization/3.3/Run.cs

    r11171 r11344  
    2222using System;
    2323using System.Collections.Generic;
     24using System.ComponentModel;
    2425using System.Drawing;
    25 using System.Linq;
     26using HeuristicLab.Collections;
    2627using HeuristicLab.Common;
    2728using HeuristicLab.Core;
     
    4445      algorithm = cloner.Clone(original.algorithm);
    4546
    46       parameters = new Dictionary<string, IItem>();
     47      parameters = new ObservableDictionary<string, IItem>();
    4748      foreach (string key in original.parameters.Keys)
    4849        parameters.Add(key, cloner.Clone(original.parameters[key]));
    4950
    50       results = new Dictionary<string, IItem>();
     51      results = new ObservableDictionary<string, IItem>();
    5152      foreach (string key in original.results.Keys)
    5253        results.Add(key, cloner.Clone(original.results[key]));
    5354    }
     55
    5456    public override IDeepCloneable Clone(Cloner cloner) {
    5557      return new Run(this, cloner);
     
    6264      color = Color.Black;
    6365      algorithm = null;
    64       parameters = new Dictionary<string, IItem>();
    65       results = new Dictionary<string, IItem>();
     66      parameters = new ObservableDictionary<string, IItem>();
     67      results = new ObservableDictionary<string, IItem>();
    6668    }
    6769    public Run(IAlgorithm algorithm)
     
    8890
    8991    private void Initialize(IAlgorithm algorithm) {
    90       parameters = new Dictionary<string, IItem>();
    91       results = new Dictionary<string, IItem>();
     92      parameters = new ObservableDictionary<string, IItem>();
     93      results = new ObservableDictionary<string, IItem>();
    9294
    9395      if (algorithm.StoreAlgorithmInEachRun) {
    94         IAlgorithm clone = (IAlgorithm)algorithm.Clone();
     96        var clone = (IAlgorithm)algorithm.Clone();
    9597        clone.CollectParameterValues(parameters);
    9698        clone.CollectResultValues(results);
     
    98100        this.algorithm = clone;
    99101      } else {
    100         algorithm.CollectParameterValues(parameters);
    101         algorithm.CollectResultValues(results);
    102         Cloner cloner = new Cloner();
    103         parameters = parameters.Select(x => new KeyValuePair<string, IItem>(x.Key, cloner.Clone(x.Value))).ToDictionary(x => x.Key, x => x.Value);
    104         results = results.Select(x => new KeyValuePair<string, IItem>(x.Key, cloner.Clone(x.Value))).ToDictionary(x => x.Key, x => x.Value);
     102        var par = new Dictionary<string, IItem>();
     103        var res = new Dictionary<string, IItem>();
     104        algorithm.CollectParameterValues(par);
     105        algorithm.CollectResultValues(res);
     106        var cloner = new Cloner();
     107        foreach (var k in par) parameters.Add(k.Key, cloner.Clone(k.Value));
     108        foreach (var k in res) results.Add(k.Key, cloner.Clone(k.Value));
    105109      }
    106110    }
     
    115119      get { return algorithm; }
    116120    }
    117     [Storable]
    118     private Dictionary<string, IItem> parameters;
    119     public IDictionary<string, IItem> Parameters {
     121
     122    [Storable(Name = "parameters")]
     123    private IDictionary<string, IItem> StorableParameters {
    120124      get { return parameters; }
     125      set {
     126        if (!(value is IObservableDictionary<string, IItem>))
     127          parameters = new ObservableDictionary<string, IItem>(value);
     128        else parameters = (IObservableDictionary<string, IItem>)value;
     129      }
    121130    }
    122     [Storable]
    123     private Dictionary<string, IItem> results;
    124     public IDictionary<string, IItem> Results {
     131    private IObservableDictionary<string, IItem> parameters;
     132    public IObservableDictionary<string, IItem> Parameters {
     133      get { return parameters; }
     134      private set {
     135        if (parameters != value) {
     136          parameters = value;
     137          OnPropertyChanged("Parameters");
     138        }
     139      }
     140    }
     141
     142    [Storable(Name = "results")]
     143    private IDictionary<string, IItem> StorableResults {
    125144      get { return results; }
     145      set {
     146        if (!(value is IObservableDictionary<string, IItem>))
     147          results = new ObservableDictionary<string, IItem>(value);
     148        else results = (IObservableDictionary<string, IItem>)value;
     149      }
     150    }
     151    private IObservableDictionary<string, IItem> results;
     152    public IObservableDictionary<string, IItem> Results {
     153      get { return results; }
     154      set {
     155        if (results != value) {
     156          results = value;
     157          OnPropertyChanged("Results");
     158        }
     159      }
    126160    }
    127161
     
    133167        if (color != value) {
    134168          this.color = value;
    135           this.OnChanged();
     169          OnPropertyChanged("Color");
    136170        }
    137171      }
     
    143177        if (visible != value) {
    144178          this.visible = value;
    145           this.OnChanged();
     179          OnPropertyChanged("Visible");
    146180        }
    147181      }
    148182    }
    149     public event EventHandler Changed;
    150     private void OnChanged() {
    151       EventHandler handler = Changed;
    152       if (handler != null)
    153         handler(this, EventArgs.Empty);
     183
     184    public event PropertyChangedEventHandler PropertyChanged;
     185    private void OnPropertyChanged(string property) {
     186      var handler = PropertyChanged;
     187      if (handler != null) handler(this, new PropertyChangedEventArgs(property));
    154188    }
    155189  }
  • trunk/sources/HeuristicLab.Optimization/3.3/RunCollection.cs

    r11171 r11344  
    2222using System;
    2323using System.Collections.Generic;
     24using System.ComponentModel;
    2425using System.Linq;
    2526using HeuristicLab.Collections;
     
    160161        foreach (KeyValuePair<string, IItem> result in run.Results)
    161162          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);
    162171      }
    163172      columnNameCache = null;
     
    178187        foreach (KeyValuePair<string, IItem> result in run.Results)
    179188          columnsChanged |= AddResult(result.Key, result.Value);
     189        run.PropertyChanged += RunOnPropertyChanged;
     190        RegisterRunParametersEvents(run);
     191        RegisterRunResultsEvents(run);
    180192      }
    181193      if (columnsChanged) columnNameCache = null;
     
    198210        foreach (string resultName in run.Results.Keys)
    199211          columnsChanged |= RemoveResultName(resultName);
     212        run.PropertyChanged -= RunOnPropertyChanged;
     213        DeregisterRunParametersEvents(run);
     214        DeregisterRunResultsEvents(run);
    200215      }
    201216      if (columnsChanged) columnNameCache = null;
     
    205220      OnRowsChanged();
    206221      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 += RunOnParameterChanged;
     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 += RunOnResultChanged;
     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 -= RunOnParameterChanged;
     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 -= RunOnResultChanged;
     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 RunOnResultChanged(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>> e) {
     283      bool columnsChanged = false;
     284      foreach (var result in e.Items)
     285        columnsChanged |= AddResult(result.Key, result.Value);
     286      foreach (var result in e.OldItems)
     287        columnsChanged |= RemoveResultName(result.Key);
     288      if (columnsChanged) columnNameCache = null;
     289      OnReset();
    207290      if (columnsChanged) {
    208291        OnColumnsChanged();
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/RunCollectionVariableImpactView.cs

    r11171 r11344  
    2222using System;
    2323using System.Collections.Generic;
     24using System.ComponentModel;
    2425using System.Drawing;
    2526using System.Linq;
     
    6667    private void RegisterRunEvents(IEnumerable<IRun> runs) {
    6768      foreach (IRun run in runs)
    68         run.Changed += Run_Changed;
     69        run.PropertyChanged += Run_PropertyChanged;
    6970    }
    7071    private void DeregisterRunEvents(IEnumerable<IRun> runs) {
    7172      foreach (IRun run in runs)
    72         run.Changed -= Run_Changed;
     73        run.PropertyChanged -= Run_PropertyChanged;
    7374    }
    7475    private void Content_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
     
    8889      if (!Content.UpdateOfRunsInProgress) UpdateData();
    8990    }
    90     private void Run_Changed(object sender, EventArgs e) {
    91       if (!Content.UpdateOfRunsInProgress) UpdateData();
     91    private void Run_PropertyChanged(object sender, PropertyChangedEventArgs e) {
     92      if (!Content.UpdateOfRunsInProgress && e.PropertyName == "Visible")
     93        UpdateData();
    9294    }
    9395    #endregion
Note: See TracChangeset for help on using the changeset viewer.