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.DB.Interfaces;
|
---|
13 |
|
---|
14 | namespace HeuristicLab.CEDMA.Core {
|
---|
15 |
|
---|
16 | public partial class TableResultsView : ViewBase {
|
---|
17 | private Results Results {
|
---|
18 | get { return (Results)Item; }
|
---|
19 | set { Item = value; }
|
---|
20 | }
|
---|
21 | private bool suppressEvents;
|
---|
22 | public TableResultsView(Results results) {
|
---|
23 | suppressEvents = false;
|
---|
24 | InitializeComponent();
|
---|
25 | Results = results;
|
---|
26 | results.Changed += new EventHandler(results_Changed);
|
---|
27 | }
|
---|
28 |
|
---|
29 | void results_Changed(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 | List<string> attributeNames = Results.SelectModelAttributes().ToList();
|
---|
39 | foreach (var attribute in attributeNames) {
|
---|
40 | dataGridView.Columns.Add(attribute, attribute);
|
---|
41 | }
|
---|
42 |
|
---|
43 | var entries = Results.GetEntries();
|
---|
44 | foreach (var entry in entries) {
|
---|
45 | int rowIndex = dataGridView.Rows.Add();
|
---|
46 | dataGridView.Rows[rowIndex].Tag = entry;
|
---|
47 | foreach (string attrName in attributeNames) {
|
---|
48 | dataGridView.Rows[rowIndex].Cells[attrName].Value = entry.Get(attrName);
|
---|
49 | }
|
---|
50 | if (entry.Selected) dataGridView.Rows[rowIndex].Selected = true;
|
---|
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 | ((ResultsEntry)row.Tag).Selected = row.Selected;
|
---|
60 | }
|
---|
61 | suppressEvents = true;
|
---|
62 | Results.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 | ResultsEntry entry = (ResultsEntry)dataGridView.Rows[hitInfo.RowIndex].Tag;
|
---|
70 | string serializedData = (string)entry.Get(Ontology.PredicateSerializedData.Uri.Replace(Ontology.CedmaNameSpace, ""));
|
---|
71 | var model = (IItem)PersistenceManager.RestoreFromGZip(Convert.FromBase64String(serializedData));
|
---|
72 | PluginManager.ControlManager.ShowControl(model.CreateView());
|
---|
73 | }
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | public class TablesResultsViewFactory : IResultsViewFactory {
|
---|
78 | #region IResultsViewFactory Members
|
---|
79 |
|
---|
80 | public string Name {
|
---|
81 | get { return "Table"; }
|
---|
82 | }
|
---|
83 |
|
---|
84 | public IControl CreateView(Results results) {
|
---|
85 | return new TableResultsView(results);
|
---|
86 | }
|
---|
87 |
|
---|
88 | #endregion
|
---|
89 | }
|
---|
90 | }
|
---|