source: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/TableResultsView.cs @ 1109

Last change on this file since 1109 was 1109, checked in by gkronber, 12 years ago

worked on presentation layer for CEDMA (brushing) (#419)

File size: 2.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9using HeuristicLab.Core;
10using HeuristicLab.CEDMA.Core;
11using HeuristicLab.PluginInfrastructure;
12
13namespace HeuristicLab.CEDMA.Core {
14
15  public partial class TableResultsView : ViewBase {
16    private Results Results {
17      get { return (Results)Item; }
18      set { Item = value; }
19    }
20    private bool suppressEvents;
21    public TableResultsView(Results results) {
22      suppressEvents = false;
23      InitializeComponent();
24      Results = results;
25      results.Changed += new EventHandler(results_Changed);
26    }
27
28    void results_Changed(object sender, EventArgs e) {
29      if (suppressEvents) return;
30      UpdateControls();
31    }
32
33    protected override void UpdateControls() {
34      suppressEvents = true;
35      dataGridView.Rows.Clear();
36      dataGridView.Columns.Clear();
37      List<string> attributeNames = Results.SelectModelAttributes().ToList();
38      foreach (var attribute in attributeNames) {
39        dataGridView.Columns.Add(attribute, attribute);
40      }
41
42      var entries = Results.GetEntries();
43      foreach (var entry in entries) {
44        int rowIndex = dataGridView.Rows.Add();
45        dataGridView.Rows[rowIndex].Tag = entry;
46        foreach (string attrName in attributeNames) {
47          dataGridView.Rows[rowIndex].Cells[attrName].Value = entry.Get(attrName);
48        }
49        if (entry.Selected) dataGridView.Rows[rowIndex].Selected = true;
50      }
51      dataGridView.Update();
52      suppressEvents = false;
53    }
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    }
64  }
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  }
79}
Note: See TracBrowser for help on using the repository browser.