Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.CEDMA.Core/TableResultsView.cs @ 1287

Last change on this file since 1287 was 1287, checked in by gkronber, 16 years ago

Merged change sets from CEDMA branch to trunk:

File size: 2.9 KB
RevLine 
[1106]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;
[1287]11using HeuristicLab.PluginInfrastructure;
12using HeuristicLab.CEDMA.DB.Interfaces;
[1106]13
14namespace 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) {
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;
[1106]51      }
52      dataGridView.Update();
[1287]53      suppressEvents = false;
[1106]54    }
[1287]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    }
[1106]75  }
[1287]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  }
[1106]90}
Note: See TracBrowser for help on using the repository browser.