Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/11/10 17:40:00 (14 years ago)
Author:
mkommend
Message:

improved the performance of RunCollections by caching some properties and corrected some bugs in the RunCollectionTabularView (ticket #1144)

File:
1 edited

Legend:

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

    r4068 r4200  
    3131  [View("RunCollection Tabular View")]
    3232  [Content(typeof(RunCollection), false)]
    33   public partial class RunCollectionTabularView : StringConvertibleMatrixView {
     33  public sealed partial class RunCollectionTabularView : StringConvertibleMatrixView {
     34    private int[] runToRowMapping;
    3435    public RunCollectionTabularView() {
    3536      InitializeComponent();
    36       this.dataGridView.RowHeaderMouseDoubleClick += new DataGridViewCellMouseEventHandler(dataGridView_RowHeaderMouseDoubleClick);
    3737      base.ReadOnly = true;
    3838    }
     
    5151      base.OnContentChanged();
    5252      if (Content != null) {
    53         foreach (IRun run in Content)
    54           UpdateRun(run);
    55       }
    56     }
    57 
     53        runToRowMapping = Enumerable.Range(0, Content.Count).ToArray();
     54        UpdateRowAttributes();
     55      }
     56    }
     57
     58    #region events
    5859    protected override void RegisterContentEvents() {
    5960      base.RegisterContentEvents();
     
    6364      RegisterRunEvents(Content);
    6465    }
    65     protected virtual void RegisterRunEvents(IEnumerable<IRun> runs) {
     66    private void RegisterRunEvents(IEnumerable<IRun> runs) {
    6667      foreach (IRun run in runs)
    6768        run.Changed += new EventHandler(run_Changed);
     
    7475      DeregisterRunEvents(Content);
    7576    }
    76     protected virtual void DeregisterRunEvents(IEnumerable<IRun> runs) {
     77    private void DeregisterRunEvents(IEnumerable<IRun> runs) {
    7778      foreach (IRun run in runs)
    7879        run.Changed -= new EventHandler(run_Changed);
     
    8182      DeregisterRunEvents(e.OldItems);
    8283      RegisterRunEvents(e.Items);
     84      OnContentChanged();
    8385    }
    8486    private void Content_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
     
    9698      }
    9799    }
     100    #endregion
    98101
    99102    private void UpdateRun(IRun run) {
    100       int rowIndex = Content.ToList().IndexOf(run);
    101       rowIndex = virtualRowIndizes[rowIndex];
     103      int runIndex = GetIndexOfRun(run);
     104      int rowIndex = runToRowMapping[runIndex];
    102105      this.dataGridView.Rows[rowIndex].Visible = run.Visible;
    103106      this.dataGridView.Rows[rowIndex].DefaultCellStyle.ForeColor = run.Color;
    104       this.rowsTextBox.Text = this.Content.Count(r => r.Visible).ToString();
     107      this.UpdateRowHeaders();
     108    }
     109
     110    private int GetIndexOfRun(IRun run) {
     111      int i = 0;
     112      foreach (IRun actualRun in Content) {
     113        if (actualRun == run)
     114          return i;
     115        i++;
     116      }
     117      throw new ArgumentException("Run " + run.Name + "could not be found in the RunCollection.");
    105118    }
    106119
    107120    private void dataGridView_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) {
    108121      if (e.RowIndex >= 0) {
    109         IRun run = Content.ElementAt(virtualRowIndizes[e.RowIndex]);
     122        IRun run = Content.ElementAt(runToRowMapping.ToList().IndexOf(e.RowIndex));
    110123        IContentView view = MainFormManager.MainForm.ShowContent(run);
    111124        if (view != null) {
     
    124137        Array.Sort(newSortedIndex, rowComparer);
    125138      }
     139
     140      runToRowMapping = new int[newSortedIndex.Length];
     141      int i = 0;
     142      foreach (int runIndex in newSortedIndex) {
     143        runToRowMapping[runIndex] = i;
     144        i++;
     145      }
     146      UpdateRowAttributes();
    126147      return newSortedIndex;
     148    }
     149
     150    private void UpdateRowAttributes() {
     151      int runIndex = 0;
     152      foreach (IRun run in Content) {
     153        int rowIndex = this.runToRowMapping[runIndex];
     154        this.dataGridView.Rows[rowIndex].Visible = run.Visible;
     155        this.dataGridView.Rows[rowIndex].DefaultCellStyle.ForeColor = run.Color;
     156        runIndex++;
     157      }
    127158    }
    128159
Note: See TracChangeset for help on using the changeset viewer.