Free cookie consent management tool by TermsFeed Policy Generator

source: branches/plugins/HeuristicLab.CEDMA.Core/3.2/TableResultsView.cs @ 1875

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

worked on #419

  • added function to open and display any model
  • added 'hard-coded' implementation of offspring selection GP (work in progress)
  • added properties for max. size and max. height in StandardGP
File size: 2.9 KB
Line 
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;
11using HeuristicLab.PluginInfrastructure;
12using HeuristicLab.CEDMA.DB.Interfaces;
13
14namespace 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}
Note: See TracBrowser for help on using the repository browser.