#region License Information
/* HeuristicLab
* Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using HeuristicLab.Core;
using HeuristicLab.Data.Views;
using HeuristicLab.MainForm;
namespace HeuristicLab.Optimization.Views {
[View("Table")]
[Content(typeof(RunCollection), false)]
public sealed partial class RunCollectionTableView : StringConvertibleMatrixView {
private int[] runToRowMapping;
private bool suppressUpdates = false;
public RunCollectionTableView() {
InitializeComponent();
dataGridView.RowHeaderMouseDoubleClick += new DataGridViewCellMouseEventHandler(dataGridView_RowHeaderMouseDoubleClick);
}
public override bool ReadOnly {
get { return true; }
set { /*not needed because results are always readonly */}
}
public new RunCollection Content {
get { return (RunCollection)base.Content; }
set { base.Content = value; }
}
protected override void OnContentChanged() {
base.OnContentChanged();
if (Content != null) {
UpdateRowAttributes();
}
UpdateCaption();
}
#region events
protected override void RegisterContentEvents() {
base.RegisterContentEvents();
Content.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler(Content_ItemsAdded);
Content.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler(Content_ItemsRemoved);
Content.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler(Content_CollectionReset);
Content.UpdateOfRunsInProgressChanged += new EventHandler(Content_UpdateOfRunsInProgressChanged);
Content.OptimizerNameChanged += new EventHandler(Content_AlgorithmNameChanged);
RegisterRunEvents(Content);
}
private void RegisterRunEvents(IEnumerable runs) {
foreach (IRun run in runs)
run.PropertyChanged += run_PropertyChanged;
}
protected override void DeregisterContentEvents() {
base.DeregisterContentEvents();
Content.ItemsAdded -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler(Content_ItemsAdded);
Content.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler(Content_ItemsRemoved);
Content.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler(Content_CollectionReset);
Content.UpdateOfRunsInProgressChanged -= new EventHandler(Content_UpdateOfRunsInProgressChanged);
Content.OptimizerNameChanged -= new EventHandler(Content_AlgorithmNameChanged);
DeregisterRunEvents(Content);
}
private void DeregisterRunEvents(IEnumerable runs) {
foreach (IRun run in runs)
run.PropertyChanged -= run_PropertyChanged;
}
private void Content_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs e) {
DeregisterRunEvents(e.OldItems);
RegisterRunEvents(e.Items);
}
private void Content_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs e) {
DeregisterRunEvents(e.Items);
}
private void Content_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs e) {
RegisterRunEvents(e.Items);
}
private void Content_AlgorithmNameChanged(object sender, EventArgs e) {
if (InvokeRequired)
Invoke(new EventHandler(Content_AlgorithmNameChanged), sender, e);
else UpdateCaption();
}
private void run_PropertyChanged(object sender, PropertyChangedEventArgs e) {
if (suppressUpdates) return;
if (InvokeRequired)
this.Invoke((Action