[1106] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.ComponentModel;
|
---|
| 4 | using System.Drawing;
|
---|
| 5 | using System.Data;
|
---|
| 6 | using System.Linq;
|
---|
| 7 | using System.Text;
|
---|
| 8 | using System.Windows.Forms;
|
---|
| 9 | using HeuristicLab.Core;
|
---|
| 10 | using HeuristicLab.CEDMA.Core;
|
---|
[1109] | 11 | using HeuristicLab.PluginInfrastructure;
|
---|
[1106] | 12 |
|
---|
| 13 | namespace HeuristicLab.CEDMA.Core {
|
---|
| 14 |
|
---|
[1109] | 15 | public partial class TableResultsView : ViewBase {
|
---|
| 16 | private Results Results {
|
---|
| 17 | get { return (Results)Item; }
|
---|
| 18 | set { Item = value; }
|
---|
[1106] | 19 | }
|
---|
[1109] | 20 | private bool suppressEvents;
|
---|
| 21 | public TableResultsView(Results results) {
|
---|
| 22 | suppressEvents = false;
|
---|
| 23 | InitializeComponent();
|
---|
| 24 | Results = results;
|
---|
| 25 | results.Changed += new EventHandler(results_Changed);
|
---|
[1108] | 26 | }
|
---|
| 27 |
|
---|
[1109] | 28 | void results_Changed(object sender, EventArgs e) {
|
---|
| 29 | if (suppressEvents) return;
|
---|
[1106] | 30 | UpdateControls();
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | protected override void UpdateControls() {
|
---|
[1109] | 34 | suppressEvents = true;
|
---|
[1106] | 35 | dataGridView.Rows.Clear();
|
---|
| 36 | dataGridView.Columns.Clear();
|
---|
[1109] | 37 | List<string> attributeNames = Results.SelectModelAttributes().ToList();
|
---|
[1108] | 38 | foreach (var attribute in attributeNames) {
|
---|
| 39 | dataGridView.Columns.Add(attribute, attribute);
|
---|
[1106] | 40 | }
|
---|
| 41 |
|
---|
[1109] | 42 | var entries = Results.GetEntries();
|
---|
[1108] | 43 | foreach (var entry in entries) {
|
---|
| 44 | int rowIndex = dataGridView.Rows.Add();
|
---|
[1109] | 45 | dataGridView.Rows[rowIndex].Tag = entry;
|
---|
[1108] | 46 | foreach (string attrName in attributeNames) {
|
---|
| 47 | dataGridView.Rows[rowIndex].Cells[attrName].Value = entry.Get(attrName);
|
---|
| 48 | }
|
---|
[1109] | 49 | if (entry.Selected) dataGridView.Rows[rowIndex].Selected = true;
|
---|
[1106] | 50 | }
|
---|
| 51 | dataGridView.Update();
|
---|
[1109] | 52 | suppressEvents = false;
|
---|
[1106] | 53 | }
|
---|
[1109] | 54 |
|
---|
| 55 | private void dataGridView_SelectionChanged(object sender, EventArgs e) {
|
---|
| 56 | if (suppressEvents) return;
|
---|
| 57 | foreach (DataGridViewRow row in dataGridView.Rows) {
|
---|
| 58 | ((ResultsEntry)row.Tag).Selected = row.Selected;
|
---|
| 59 | }
|
---|
| 60 | suppressEvents = true;
|
---|
| 61 | Results.FireChanged();
|
---|
| 62 | suppressEvents = false;
|
---|
| 63 | }
|
---|
[1106] | 64 | }
|
---|
[1109] | 65 |
|
---|
| 66 | public class TablesResultsViewFactory : IResultsViewFactory {
|
---|
| 67 | #region IResultsViewFactory Members
|
---|
| 68 |
|
---|
| 69 | public string Name {
|
---|
| 70 | get { return "Table"; }
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | public IControl CreateView(Results results) {
|
---|
| 74 | return new TableResultsView(results);
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | #endregion
|
---|
| 78 | }
|
---|
[1106] | 79 | }
|
---|