Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2169 was 2139, checked in by gkronber, 15 years ago

Implemented filtering of result entries in bubble chart and table view. #691 (CEDMA result views should allow filtering of displayed results)

File size: 3.0 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) {
[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}
Note: See TracBrowser for help on using the repository browser.