Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/21/10 18:19:39 (13 years ago)
Author:
mkommend
Message:

Improved performance of all RunCollectionViews (ticket #1284).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionTabularView.cs

    r4819 r4883  
    2424using System.Linq;
    2525using System.Windows.Forms;
    26 using HeuristicLab.Core;
     26using HeuristicLab.Common;
    2727using HeuristicLab.Data.Views;
    2828using HeuristicLab.MainForm;
     29using HeuristicLab.Core;
    2930
    3031namespace HeuristicLab.Optimization.Views {
     
    3334  public sealed partial class RunCollectionTabularView : StringConvertibleMatrixView {
    3435    private int[] runToRowMapping;
     36    private bool suppressUpdates = false;
    3537    public RunCollectionTabularView() {
    3638      InitializeComponent();
     
    6264      Content.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
    6365      Content.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
     66      Content.UpdateOfRunsInProgress += new EventHandler<EventArgs<bool>>(Content_UpdateOfRunsInProgress);
    6467      RegisterRunEvents(Content);
    6568    }
     
    7376      Content.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
    7477      Content.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
     78      Content.UpdateOfRunsInProgress -= new EventHandler<EventArgs<bool>>(Content_UpdateOfRunsInProgress);
    7579      DeregisterRunEvents(Content);
    7680    }
     
    113117
    114118    private void UpdateRun(IRun run) {
    115       int runIndex = GetIndexOfRun(run);
    116       int rowIndex = runToRowMapping[runIndex];
    117       this.dataGridView.Rows[rowIndex].Visible = run.Visible;
    118       this.dataGridView.Rows[rowIndex].DefaultCellStyle.ForeColor = run.Color;
     119      foreach (int runIndex in GetIndexOfRun(run)) {
     120        int rowIndex = runToRowMapping[runIndex];
     121        this.dataGridView.Rows[rowIndex].Visible = run.Visible;
     122        this.dataGridView.Rows[rowIndex].DefaultCellStyle.ForeColor = run.Color;
     123      }
    119124      this.UpdateRowHeaders();
    120125    }
    121126
    122     private int GetIndexOfRun(IRun run) {
     127
     128    private void Content_UpdateOfRunsInProgress(object sender, Common.EventArgs<bool> e) {
     129      if (InvokeRequired)
     130        Invoke(new EventHandler<EventArgs<bool>>(Content_UpdateOfRunsInProgress), sender, e);
     131      else {
     132        suppressUpdates = e.Value;
     133        if (!suppressUpdates) UpdateRowAttributes();
     134      }
     135    }
     136
     137    private IEnumerable<int> GetIndexOfRun(IRun run) {
    123138      int i = 0;
    124139      foreach (IRun actualRun in Content) {
    125140        if (actualRun == run)
    126           return i;
     141          yield return i;
    127142        i++;
    128143      }
    129       throw new ArgumentException("Run " + run.Name + "could not be found in the RunCollection.");
    130144    }
    131145
     
    143157    protected override void ClearSorting() {
    144158      base.ClearSorting();
    145       runToRowMapping = new int[Content.Count];
    146       for (int i = 0; i < runToRowMapping.Length; i++)
    147         runToRowMapping[i] = i;
     159      runToRowMapping = Enumerable.Range(0, Content.Count).ToArray();
    148160      UpdateRowAttributes();
    149161    }
     
    176188        runIndex++;
    177189      }
     190      UpdateRowHeaders();
    178191    }
    179192
Note: See TracChangeset for help on using the changeset viewer.