Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/17/14 17:34:43 (10 years ago)
Author:
ascheibe
Message:

#2031 improved correlation view and some clean ups

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/CorrelationView.cs

    r11375 r11378  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using System.Windows.Forms;
     25using HeuristicLab.Collections;
     26using HeuristicLab.Core;
    2627using HeuristicLab.Core.Views;
    2728using HeuristicLab.Data;
     
    4950
    5051    private Dictionary<string, ResultParameterType> resultsParameters;
     52    private bool suppressUpdates = false;
    5153
    5254    public CorrelationView() {
     
    6163
    6264      if (Content != null) {
    63         resultsParameters = GetRowNames();
    6465        UpdateResultComboBox();
    6566      }
     
    7879      Content.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
    7980      Content.UpdateOfRunsInProgressChanged += Content_UpdateOfRunsInProgressChanged;
     81      RegisterRunEvents(Content);
    8082    }
    8183
     
    8688      Content.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
    8789      Content.UpdateOfRunsInProgressChanged -= Content_UpdateOfRunsInProgressChanged;
     90      DeregisterRunEvents(Content);
     91    }
     92
     93    private void RegisterRunEvents(IEnumerable<IRun> runs) {
     94      foreach (IRun run in runs) {
     95        RegisterRunResultsEvents(run);
     96        RegisterRunParametersEvents(run);
     97        run.PropertyChanged += run_PropertyChanged;
     98      }
     99    }
     100
     101    private void DeregisterRunEvents(IEnumerable<IRun> runs) {
     102      foreach (IRun run in runs) {
     103        DeregisterRunResultsEvents(run);
     104        DeregisterRunParametersEvents(run);
     105        run.PropertyChanged -= run_PropertyChanged;
     106      }
     107    }
     108
     109    private void RegisterRunResultsEvents(IRun run) {
     110      IObservableDictionary<string, IItem> dict = run.Results;
     111      dict.ItemsAdded += run_Changed;
     112      dict.ItemsRemoved += run_Changed;
     113      dict.ItemsReplaced += run_Changed;
     114      dict.CollectionReset += run_Changed;
     115    }
     116
     117    private void DeregisterRunResultsEvents(IRun run) {
     118      IObservableDictionary<string, IItem> dict = run.Results;
     119      dict.ItemsAdded -= run_Changed;
     120      dict.ItemsRemoved -= run_Changed;
     121      dict.ItemsReplaced -= run_Changed;
     122      dict.CollectionReset -= run_Changed;
     123    }
     124
     125    private void RegisterRunParametersEvents(IRun run) {
     126      IObservableDictionary<string, IItem> dict = run.Parameters;
     127      dict.ItemsAdded += run_Changed;
     128      dict.ItemsRemoved += run_Changed;
     129      dict.ItemsReplaced += run_Changed;
     130      dict.CollectionReset += run_Changed;
     131    }
     132
     133    private void DeregisterRunParametersEvents(IRun run) {
     134      IObservableDictionary<string, IItem> dict = run.Parameters;
     135      dict.ItemsAdded -= run_Changed;
     136      dict.ItemsRemoved -= run_Changed;
     137      dict.ItemsReplaced -= run_Changed;
     138      dict.CollectionReset -= run_Changed;
    88139    }
    89140
    90141    private void Content_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
    91       RebuildCorrelationTable();
     142      UpdateUI();
    92143    }
    93144
    94145    private void Content_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
    95       RebuildCorrelationTable();
     146      UpdateUI();
    96147    }
    97148
    98149    private void Content_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
    99       RebuildCorrelationTable();
    100     }
    101 
    102     void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
    103       if (!Content.UpdateOfRunsInProgress) {
     150      UpdateUI();
     151    }
     152
     153    private void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
     154      suppressUpdates = Content.UpdateOfRunsInProgress;
     155      UpdateUI();
     156    }
     157
     158    private void run_Changed(object sender, EventArgs e) {
     159      if (InvokeRequired) {
     160        Invoke(new EventHandler(run_Changed), sender, e);
     161      }
     162      UpdateUI();
     163    }
     164
     165    void run_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) {
     166      UpdateUI();
     167    }
     168    #endregion
     169
     170    private void UpdateUI() {
     171      if (!suppressUpdates) {
     172        UpdateResultComboBox();
    104173        RebuildCorrelationTable();
    105174      }
    106175    }
    107     #endregion
    108176
    109177    private void UpdateResultComboBox() {
     178      resultsParameters = GetRowNames();
     179      string selectedResult = (string)this.resultComboBox.SelectedItem;
    110180      resultComboBox.Items.Clear();
    111 
    112181      resultComboBox.Items.AddRange(resultsParameters.Keys.ToArray());
    113       if (resultComboBox.Items.Count > 0) resultComboBox.SelectedItem = resultComboBox.Items[0];
     182
     183      if (selectedResult != null && resultComboBox.Items.Contains(selectedResult)) {
     184        resultComboBox.SelectedItem = selectedResult;
     185      } else if (resultComboBox.Items.Count > 0) {
     186        resultComboBox.SelectedItem = resultComboBox.Items[0];
     187      }
    114188    }
    115189
     
    195269        var resultVals = GetDoublesFromResults(runs.Where(x => x.Results.ContainsKey(resultName)).Where(x => x.Results[resultName] is DoubleValue || x.Results[resultName] is IntValue).ToList(), resultName);
    196270
    197         List<double> resultRowVals = new List<double>();
     271        List<double> resultRowVals;
    198272        if (rowName.Value == ResultParameterType.Result) {
    199273          resultRowVals = GetDoublesFromResults(runs.Where(x => x.Results.ContainsKey(rowName.Key)).Where(x => x.Results[rowName.Key] is DoubleValue || x.Results[rowName.Key] is IntValue).ToList(), rowName.Key);
Note: See TracChangeset for help on using the changeset viewer.