Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11376


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

#2031 fixed RunCollection event handling in ChartAnalysisView

Location:
branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3
Files:
2 edited

Legend:

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

    r11375 r11376  
    2525using System.Threading.Tasks;
    2626using System.Windows.Forms;
     27using HeuristicLab.Collections;
    2728using HeuristicLab.Common;
     29using HeuristicLab.Core;
    2830using HeuristicLab.Core.Views;
    2931using HeuristicLab.Data;
    3032using HeuristicLab.MainForm;
    31 using HeuristicLab.MainForm.WindowsForms;
    3233using HeuristicLab.Optimization;
    3334using HeuristicLab.PluginInfrastructure;
     
    5051    private IProgress progress;
    5152    private bool valuesAdded = false;
     53    private bool suppressUpdates = false;
    5254
    5355    public ChartAnalysisView() {
     
    7577    protected override void OnContentChanged() {
    7678      base.OnContentChanged();
     79      UpdateComboboxes();
     80      UpdateCaption();
     81    }
     82
     83    private void UpdateCaption() {
     84      Caption = Content != null ? Content.OptimizerName + " Chart Analysis" : ViewAttribute.GetViewName(GetType());
     85    }
     86
     87    private void UpdateComboboxes() {
    7788      dataTableComboBox.Items.Clear();
    7889      dataRowComboBox.Items.Clear();
     
    8192        UpdateDataTableComboBox();
    8293      }
    83       UpdateCaption();
    84     }
    85 
    86     private void UpdateCaption() {
    87       Caption = Content != null ? Content.OptimizerName + " Chart Analysis" : ViewAttribute.GetViewName(GetType());
    8894    }
    8995
    9096    protected override void RegisterContentEvents() {
    9197      base.RegisterContentEvents();
    92       Content.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
    93       Content.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
    94       Content.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
     98      Content.ItemsAdded += Content_ItemsAdded;
     99      Content.ItemsRemoved += Content_ItemsRemoved;
     100      Content.CollectionReset += Content_CollectionReset;
    95101      Content.UpdateOfRunsInProgressChanged += Content_UpdateOfRunsInProgressChanged;
     102      RegisterRunEvents(Content);
    96103    }
    97104
    98105    protected override void DeregisterContentEvents() {
    99106      base.DeregisterContentEvents();
    100       Content.ItemsAdded -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
    101       Content.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
    102       Content.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
     107      Content.ItemsAdded -= Content_ItemsAdded;
     108      Content.ItemsRemoved -= Content_ItemsRemoved;
     109      Content.CollectionReset -= Content_CollectionReset;
    103110      Content.UpdateOfRunsInProgressChanged -= Content_UpdateOfRunsInProgressChanged;
    104     }
    105 
    106     private void Content_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
     111      DeregisterRunEvents(Content);
     112    }
     113
     114    private void RegisterRunEvents(IEnumerable<IRun> runs) {
     115      foreach (IRun run in runs) {
     116        RegisterRunParametersEvents(run);
     117        RegisterRunResultsEvents(run);
     118      }
     119    }
     120
     121    private void DeregisterRunEvents(IEnumerable<IRun> runs) {
     122      foreach (IRun run in runs) {
     123        DeregisterRunParametersEvents(run);
     124        DeregisterRunResultsEvents(run);
     125      }
     126    }
     127
     128    private void RegisterRunParametersEvents(IRun run) {
     129      IObservableDictionary<string, IItem> dict = run.Parameters;
     130      dict.ItemsAdded += run_Changed;
     131      dict.ItemsRemoved += run_Changed;
     132      dict.ItemsReplaced += run_Changed;
     133      dict.CollectionReset += run_Changed;
     134    }
     135
     136    private void RegisterRunResultsEvents(IRun run) {
     137      IObservableDictionary<string, IItem> dict = run.Results;
     138      dict.ItemsAdded += run_Changed;
     139      dict.ItemsRemoved += run_Changed;
     140      dict.ItemsReplaced += run_Changed;
     141      dict.CollectionReset += run_Changed;
     142    }
     143
     144    private void DeregisterRunParametersEvents(IRun run) {
     145      IObservableDictionary<string, IItem> dict = run.Parameters;
     146      dict.ItemsAdded -= run_Changed;
     147      dict.ItemsRemoved -= run_Changed;
     148      dict.ItemsReplaced -= run_Changed;
     149      dict.CollectionReset -= run_Changed;
     150    }
     151
     152    private void DeregisterRunResultsEvents(IRun run) {
     153      IObservableDictionary<string, IItem> dict = run.Results;
     154      dict.ItemsAdded -= run_Changed;
     155      dict.ItemsRemoved -= run_Changed;
     156      dict.ItemsReplaced -= run_Changed;
     157      dict.CollectionReset -= run_Changed;
     158    }
     159
     160    private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
     161      DeregisterRunEvents(e.OldItems);
     162      RegisterRunEvents(e.Items);
     163      UpdateComboboxes();
    107164      RebuildDataTableAsync();
    108165    }
    109166
    110     private void Content_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
     167    private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
     168      DeregisterRunEvents(e.Items);
    111169      RebuildDataTableAsync();
    112170    }
    113171
    114     private void Content_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
     172    private void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {
     173      RegisterRunEvents(e.Items);
    115174      RebuildDataTableAsync();
    116175    }
    117176
    118177    void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
    119       if (!Content.UpdateOfRunsInProgress && !valuesAdded) {
     178      suppressUpdates = Content.UpdateOfRunsInProgress;
     179
     180      if (!suppressUpdates && !valuesAdded) {
    120181        RebuildDataTableAsync();
    121182      }
    122183      if (valuesAdded) {
    123184        valuesAdded = false;
     185      }
     186    }
     187
     188    private void run_Changed(object sender, EventArgs e) {
     189      if (InvokeRequired)
     190        Invoke(new EventHandler(run_Changed), sender, e);
     191      else if (!suppressUpdates) {
     192        UpdateComboboxes();
    124193      }
    125194    }
     
    147216
    148217    private void addLineToChart_Click(object sender, EventArgs e) {
    149       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Adding fitted lines to charts...");
    150 
    151       var task = System.Threading.Tasks.Task.Factory.StartNew(AddLineToChart);
     218      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Adding fitted lines to charts...");
     219
     220      var task = Task.Factory.StartNew(AddLineToChart);
    152221
    153222      task.ContinueWith((t) => {
    154         MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     223        MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    155224        ErrorHandling.ShowErrorDialog("An error occured while adding lines to charts. ", t.Exception);
    156225      }, TaskContinuationOptions.OnlyOnFaulted);
    157226
    158227      task.ContinueWith((t) => {
    159         MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     228        MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    160229      }, TaskContinuationOptions.OnlyOnRanToCompletion);
    161230    }
     
    227296
    228297    private void RebuildDataTableAsync() {
    229       progress = MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Calculating values...");
     298      progress = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Calculating values...");
    230299
    231300      var task = Task.Factory.StartNew(RebuildDataTable);
    232301
    233302      task.ContinueWith((t) => {
    234         MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     303        MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    235304        ErrorHandling.ShowErrorDialog("An error occured while calculating values. ", t.Exception);
    236305      }, TaskContinuationOptions.OnlyOnFaulted);
    237306
    238307      task.ContinueWith((t) => {
    239         MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     308        MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    240309      }, TaskContinuationOptions.OnlyOnRanToCompletion);
    241310    }
     
    298367
    299368        i++;
    300         progress.ProgressValue = runs.Count / i;
     369        progress.ProgressValue = ((double)runs.Count) / i;
    301370      }
    302371      stringConvertibleMatrixView.Content = dt;
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/SampleSizeInfluenceView.cs

    r11375 r11376  
    4343
    4444    private bool suppressUpdates = false;
    45     private string xAxisValue;
    4645    private string yAxisValue;
    4746    private Dictionary<int, Dictionary<object, double>> categoricalMapping;
     
    139138    }
    140139
    141     private void Content_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
     140    private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    142141      DeregisterRunEvents(e.OldItems);
    143142      RegisterRunEvents(e.Items);
    144143    }
    145     private void Content_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
     144    private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    146145      DeregisterRunEvents(e.Items);
    147146    }
    148     private void Content_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
     147    private void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    149148      RegisterRunEvents(e.Items);
    150149    }
     
    397396
    398397
    399       this.xAxisValue = xAxisComboBox.Text;
    400398      if (!yAxisComboBox.DroppedDown)
    401399        this.yAxisValue = (string)yAxisComboBox.SelectedItem;
Note: See TracChangeset for help on using the changeset viewer.