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;
|
---|
11 | using HeuristicLab.PluginInfrastructure;
|
---|
12 | using HeuristicLab.CEDMA.Charting;
|
---|
13 |
|
---|
14 | namespace HeuristicLab.CEDMA.Core {
|
---|
15 |
|
---|
16 | public partial class TableResultsView : ViewBase {
|
---|
17 | private VisualMatrix VisualMatrix {
|
---|
18 | get { return (VisualMatrix)Item; }
|
---|
19 | set { Item = value; }
|
---|
20 | }
|
---|
21 | private bool suppressEvents;
|
---|
22 | public TableResultsView(VisualMatrix visualMatrix) {
|
---|
23 | suppressEvents = false;
|
---|
24 | InitializeComponent();
|
---|
25 | VisualMatrix = visualMatrix;
|
---|
26 | VisualMatrix.Changed += new EventHandler(VisualMatrixChanged);
|
---|
27 | }
|
---|
28 |
|
---|
29 | private void VisualMatrixChanged(object sender, EventArgs e) {
|
---|
30 | if (suppressEvents) return;
|
---|
31 | UpdateControls();
|
---|
32 | }
|
---|
33 |
|
---|
34 | protected override void UpdateControls() {
|
---|
35 | suppressEvents = true;
|
---|
36 | dataGridView.Rows.Clear();
|
---|
37 | dataGridView.Columns.Clear();
|
---|
38 | foreach (var attribute in VisualMatrix.Attributes) {
|
---|
39 | dataGridView.Columns.Add(attribute, attribute);
|
---|
40 | }
|
---|
41 |
|
---|
42 | foreach (var row in VisualMatrix.Rows) {
|
---|
43 | if (row.Visible) {
|
---|
44 | int rowIndex = dataGridView.Rows.Add();
|
---|
45 | dataGridView.Rows[rowIndex].Tag = row;
|
---|
46 | foreach (string attrName in VisualMatrix.Attributes) {
|
---|
47 | dataGridView.Rows[rowIndex].Cells[attrName].Value = row.Get(attrName);
|
---|
48 | }
|
---|
49 | if (row.Selected) dataGridView.Rows[rowIndex].Selected = true;
|
---|
50 | }
|
---|
51 | }
|
---|
52 | dataGridView.Update();
|
---|
53 | suppressEvents = false;
|
---|
54 | }
|
---|
55 |
|
---|
56 | private void dataGridView_SelectionChanged(object sender, EventArgs e) {
|
---|
57 | if (suppressEvents) return;
|
---|
58 | foreach (DataGridViewRow row in dataGridView.Rows) {
|
---|
59 | ((VisualMatrixRow)row.Tag).Selected = row.Selected;
|
---|
60 | }
|
---|
61 | suppressEvents = true;
|
---|
62 | VisualMatrix.FireChanged();
|
---|
63 | suppressEvents = false;
|
---|
64 | }
|
---|
65 |
|
---|
66 | private void dataGridView_MouseDoubleClick(object sender, MouseEventArgs e) {
|
---|
67 | if (e.Button == MouseButtons.Left && e.Clicks == 2) {
|
---|
68 | DataGridView.HitTestInfo hitInfo = dataGridView.HitTest(e.X, e.Y);
|
---|
69 | VisualMatrixRow entry = (VisualMatrixRow)dataGridView.Rows[hitInfo.RowIndex].Tag;
|
---|
70 | var model = (IItem)PersistenceManager.RestoreFromGZip((byte[])entry.Get("PersistedData"));
|
---|
71 | PluginManager.ControlManager.ShowControl(model.CreateView());
|
---|
72 | }
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | public class TablesResultsViewFactory : IResultsViewFactory {
|
---|
77 | #region IResultsViewFactory Members
|
---|
78 |
|
---|
79 | public string Name {
|
---|
80 | get { return "Table"; }
|
---|
81 | }
|
---|
82 |
|
---|
83 | public IControl CreateView(VisualMatrix matrix) {
|
---|
84 | return new TableResultsView(matrix);
|
---|
85 | }
|
---|
86 |
|
---|
87 | #endregion
|
---|
88 | }
|
---|
89 | }
|
---|