Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12631


Ignore:
Timestamp:
07/07/15 11:05:07 (9 years ago)
Author:
ascheibe
Message:

#2270 added refresh of data table combobox for the chart analysis and aggregation view

Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Analysis.Statistics.Views/3.3/ChartAnalysisView.cs

    r12599 r12631  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Threading;
    2526using System.Threading.Tasks;
    2627using System.Windows.Forms;
     
    5253    private bool valuesAdded = false;
    5354    private bool suppressUpdates = false;
     55    private SemaphoreSlim sem = new SemaphoreSlim(1, 1);
    5456
    5557    public ChartAnalysisView() {
     
    119121      if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_ColumnsChanged, sender, e);
    120122      else {
     123        UpdateDataTableComboBox();
    121124        RebuildDataTableAsync();
    122125      }
     
    138141
    139142        if (!suppressUpdates && !valuesAdded) {
     143          UpdateDataTableComboBox();
    140144          RebuildDataTableAsync();
    141145        }
     
    164168
    165169    private void dataRowComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     170      if (suppressUpdates) return;
    166171      RebuildDataTableAsync();
    167172    }
     
    266271      string rowName = (string)dataRowComboBox.SelectedItem;
    267272
    268       progress = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Calculating values...");
    269       var task = Task.Factory.StartNew(() => RebuildDataTable(resultName, rowName));
     273      var task = Task.Factory.StartNew(() => {
     274        sem.Wait();
     275        progress = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Calculating values...");
     276        RebuildDataTable(resultName, rowName);
     277      });
    270278
    271279      task.ContinueWith((t) => {
    272280        MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    273281        ErrorHandling.ShowErrorDialog("An error occured while calculating values. ", t.Exception);
     282        sem.Release();
    274283      }, TaskContinuationOptions.OnlyOnFaulted);
    275284
    276285      task.ContinueWith((t) => {
    277286        MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     287        sem.Release();
    278288      }, TaskContinuationOptions.OnlyOnRanToCompletion);
    279289    }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionChartAggregationView.cs

    r12599 r12631  
    2424using System.ComponentModel;
    2525using System.Linq;
    26 using System.Windows.Forms;
    2726using HeuristicLab.Analysis;
    2827using HeuristicLab.Collections;
     
    4140    }
    4241
    43     private int rowNumber = 0;
     42    private int rowNumber;
    4443    private bool suppressUpdates;
    4544    private readonly Dictionary<IRun, IEnumerable<DataRow>> runMapping;
     
    6059    protected override void RegisterContentEvents() {
    6160      base.RegisterContentEvents();
    62       Content.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
    63       Content.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
    64       Content.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
    65       Content.UpdateOfRunsInProgressChanged += new EventHandler(Content_UpdateOfRunsInProgressChanged);
    66       Content.OptimizerNameChanged += new EventHandler(Content_AlgorithmNameChanged);
     61      Content.ItemsAdded += Content_ItemsAdded;
     62      Content.ItemsRemoved += Content_ItemsRemoved;
     63      Content.CollectionReset += Content_CollectionReset;
     64      Content.UpdateOfRunsInProgressChanged += Content_UpdateOfRunsInProgressChanged;
     65      Content.OptimizerNameChanged += Content_AlgorithmNameChanged;
    6766    }
    6867    protected override void DeregisterContentEvents() {
    69       Content.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
    70       Content.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
    71       Content.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
    72       Content.UpdateOfRunsInProgressChanged -= new EventHandler(Content_UpdateOfRunsInProgressChanged);
    73       Content.OptimizerNameChanged -= new EventHandler(Content_AlgorithmNameChanged);
     68      Content.ItemsAdded -= Content_ItemsAdded;
     69      Content.ItemsRemoved -= Content_ItemsRemoved;
     70      Content.CollectionReset -= Content_CollectionReset;
     71      Content.UpdateOfRunsInProgressChanged -= Content_UpdateOfRunsInProgressChanged;
     72      Content.OptimizerNameChanged -= Content_AlgorithmNameChanged;
    7473      base.DeregisterContentEvents();
    7574    }
    7675
    7776    private void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {
     77      if (suppressUpdates) return;
    7878      if (InvokeRequired) {
    7979        Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded), sender, e);
    8080        return;
    8181      }
     82      UpdateDataTableComboBox();
     83      UpdateDataRowComboBox();
    8284      AddRuns(e.Items);
    8385    }
    8486    private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
     87      if (suppressUpdates) return;
    8588      if (InvokeRequired) {
    8689        Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved), sender, e);
    8790        return;
    8891      }
     92      UpdateDataTableComboBox();
     93      UpdateDataRowComboBox();
    8994      RemoveRuns(e.Items);
    9095    }
    9196    private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
     97      if (suppressUpdates) return;
    9298      if (InvokeRequired) {
    9399        Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset), sender, e);
    94100        return;
    95101      }
     102      UpdateDataTableComboBox();
     103      UpdateDataRowComboBox();
    96104      RemoveRuns(e.OldItems);
    97105      AddRuns(e.Items);
     
    108116      }
    109117      suppressUpdates = Content.UpdateOfRunsInProgress;
    110       if (!suppressUpdates) UpdateRuns(Content);
     118      if (!suppressUpdates) {
     119        UpdateDataTableComboBox();
     120        UpdateDataRowComboBox();
     121        UpdateRuns(Content);
     122      }
    111123    }
    112124
     
    124136        var run = (IRun)sender;
    125137        if (e.PropertyName == "Color" || e.PropertyName == "Visible")
    126           UpdateRuns(new IRun[] { run });
     138          UpdateRuns(new[] { run });
    127139      }
    128140    }
     
    205217
    206218    private void UpdateDataTableComboBox() {
     219      string selectedItem = (string)dataTableComboBox.SelectedItem;
     220
    207221      dataTableComboBox.Items.Clear();
    208222      var dataTables = (from run in Content
     
    212226
    213227      dataTableComboBox.Items.AddRange(dataTables);
    214       if (dataTableComboBox.Items.Count > 0) dataTableComboBox.SelectedItem = dataTableComboBox.Items[0];
     228      if (selectedItem != null && dataTableComboBox.Items.Contains(selectedItem)) {
     229        dataTableComboBox.SelectedItem = selectedItem;
     230      } else if (dataTableComboBox.Items.Count > 0) {
     231        dataTableComboBox.SelectedItem = dataTableComboBox.Items[0];
     232      }
    215233    }
    216234
     
    220238
    221239    private void UpdateDataRowComboBox() {
     240      string selectedItem = (string)dataRowComboBox.SelectedItem;
     241
    222242      dataRowComboBox.Items.Clear();
    223243      var resultName = (string)dataTableComboBox.SelectedItem;
     
    231251      dataRowComboBox.Items.AddRange(rowNames);
    232252      dataRowComboBox.Items.Add(AllDataRows);
    233       if (dataRowComboBox.Items.Count > 0) dataRowComboBox.SelectedItem = dataRowComboBox.Items[0];
    234     }
    235 
    236     private void dataTableComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
    237       UpdateDataRowComboBox();
    238     }
    239     private void dataRowComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
     253      if (selectedItem != null && dataRowComboBox.Items.Contains(selectedItem)) {
     254        dataRowComboBox.SelectedItem = selectedItem;
     255      } else if (dataRowComboBox.Items.Count > 0) {
     256        dataRowComboBox.SelectedItem = dataRowComboBox.Items[0];
     257      }
     258    }
     259
     260    private void dataTableComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     261      UpdateDataRowComboBox();
     262    }
     263    private void dataRowComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     264      if (suppressUpdates) return;
    240265      RebuildCombinedDataTable();
    241266    }
Note: See TracChangeset for help on using the changeset viewer.