[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;
|
---|
[1287] | 11 | using HeuristicLab.PluginInfrastructure;
|
---|
| 12 | using HeuristicLab.CEDMA.DB.Interfaces;
|
---|
[1106] | 13 |
|
---|
| 14 | namespace HeuristicLab.CEDMA.Core {
|
---|
[1287] | 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;
|
---|
[1106] | 24 | InitializeComponent();
|
---|
[1287] | 25 | Results = results;
|
---|
| 26 | results.Changed += new EventHandler(results_Changed);
|
---|
[1106] | 27 | }
|
---|
| 28 |
|
---|
[1287] | 29 | void results_Changed(object sender, EventArgs e) {
|
---|
| 30 | if (suppressEvents) return;
|
---|
[1106] | 31 | UpdateControls();
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | protected override void UpdateControls() {
|
---|
[1287] | 35 | suppressEvents = true;
|
---|
[1106] | 36 | dataGridView.Rows.Clear();
|
---|
| 37 | dataGridView.Columns.Clear();
|
---|
[1287] | 38 | List<string> attributeNames = Results.SelectModelAttributes().ToList();
|
---|
| 39 | foreach (var attribute in attributeNames) {
|
---|
| 40 | dataGridView.Columns.Add(attribute, attribute);
|
---|
[1106] | 41 | }
|
---|
| 42 |
|
---|
[1287] | 43 | var entries = Results.GetEntries();
|
---|
| 44 | foreach (var entry in entries) {
|
---|
[2139] | 45 | if (entry.Visible) {
|
---|
| 46 | int rowIndex = dataGridView.Rows.Add();
|
---|
| 47 | dataGridView.Rows[rowIndex].Tag = entry;
|
---|
| 48 | foreach (string attrName in attributeNames) {
|
---|
| 49 | dataGridView.Rows[rowIndex].Cells[attrName].Value = entry.Get(attrName);
|
---|
| 50 | }
|
---|
| 51 | if (entry.Selected) dataGridView.Rows[rowIndex].Selected = true;
|
---|
[1287] | 52 | }
|
---|
[1106] | 53 | }
|
---|
| 54 | dataGridView.Update();
|
---|
[1287] | 55 | suppressEvents = false;
|
---|
[1106] | 56 | }
|
---|
[1287] | 57 |
|
---|
| 58 | private void dataGridView_SelectionChanged(object sender, EventArgs e) {
|
---|
| 59 | if (suppressEvents) return;
|
---|
| 60 | foreach (DataGridViewRow row in dataGridView.Rows) {
|
---|
| 61 | ((ResultsEntry)row.Tag).Selected = row.Selected;
|
---|
| 62 | }
|
---|
| 63 | suppressEvents = true;
|
---|
| 64 | Results.FireChanged();
|
---|
| 65 | suppressEvents = false;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | private void dataGridView_MouseDoubleClick(object sender, MouseEventArgs e) {
|
---|
| 69 | if (e.Button == MouseButtons.Left && e.Clicks == 2) {
|
---|
| 70 | DataGridView.HitTestInfo hitInfo = dataGridView.HitTest(e.X, e.Y);
|
---|
| 71 | ResultsEntry entry = (ResultsEntry)dataGridView.Rows[hitInfo.RowIndex].Tag;
|
---|
[2047] | 72 | string serializedData = (string)entry.Get(Ontology.SerializedData.Uri.Replace(Ontology.CedmaNameSpace, ""));
|
---|
[1287] | 73 | var model = (IItem)PersistenceManager.RestoreFromGZip(Convert.FromBase64String(serializedData));
|
---|
| 74 | PluginManager.ControlManager.ShowControl(model.CreateView());
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
[1106] | 77 | }
|
---|
[1287] | 78 |
|
---|
| 79 | public class TablesResultsViewFactory : IResultsViewFactory {
|
---|
| 80 | #region IResultsViewFactory Members
|
---|
| 81 |
|
---|
| 82 | public string Name {
|
---|
| 83 | get { return "Table"; }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | public IControl CreateView(Results results) {
|
---|
| 87 | return new TableResultsView(results);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | #endregion
|
---|
| 91 | }
|
---|
[1106] | 92 | }
|
---|