Ignore:
Timestamp:
01/11/09 23:25:59 (12 years ago)
Author:
gkronber
Message:

worked on presentation layer for CEDMA (brushing) (#419)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/TableResultsView.cs

    r1108 r1109  
    99using HeuristicLab.Core;
    1010using HeuristicLab.CEDMA.Core;
     11using HeuristicLab.PluginInfrastructure;
    1112
    1213namespace HeuristicLab.CEDMA.Core {
    13   public partial class TableResultsView : ViewBase, IResultsView {
    14     private Results results;
    15     public TableResultsView() {
     14
     15  public partial class TableResultsView : ViewBase {
     16    private Results Results {
     17      get { return (Results)Item; }
     18      set { Item = value; }
     19    }
     20    private bool suppressEvents;
     21    public TableResultsView(Results results) {
     22      suppressEvents = false;
    1623      InitializeComponent();
     24      Results = results;
     25      results.Changed += new EventHandler(results_Changed);
    1726    }
    1827
    19     public Control Control {
    20       get { return this; }
    21     }
    22 
    23     string IResultsView.Name {
    24       get { return "Table"; }
    25     }
    26 
    27     public void ShowResults(Results results) {
    28       this.results = results;
     28    void results_Changed(object sender, EventArgs e) {
     29      if (suppressEvents) return;
    2930      UpdateControls();
    3031    }
    3132
    3233    protected override void UpdateControls() {
    33       base.UpdateControls();
    34       if (results == null) return;
     34      suppressEvents = true;
    3535      dataGridView.Rows.Clear();
    3636      dataGridView.Columns.Clear();
    37       List<string> attributeNames = results.SelectModelAttributes().ToList();
     37      List<string> attributeNames = Results.SelectModelAttributes().ToList();
    3838      foreach (var attribute in attributeNames) {
    3939        dataGridView.Columns.Add(attribute, attribute);
    4040      }
    4141
    42       var entries = results.SelectRows();
     42      var entries = Results.GetEntries();
    4343      foreach (var entry in entries) {
    4444        int rowIndex = dataGridView.Rows.Add();
     45        dataGridView.Rows[rowIndex].Tag = entry;
    4546        foreach (string attrName in attributeNames) {
    4647          dataGridView.Rows[rowIndex].Cells[attrName].Value = entry.Get(attrName);
    4748        }
    48         dataGridView.Rows.Add(row);
     49        if (entry.Selected) dataGridView.Rows[rowIndex].Selected = true;
    4950      }
    5051      dataGridView.Update();
     52      suppressEvents = false;
     53    }
     54
     55    private void dataGridView_SelectionChanged(object sender, EventArgs e) {
     56      if (suppressEvents) return;
     57      foreach (DataGridViewRow row in dataGridView.Rows) {
     58        ((ResultsEntry)row.Tag).Selected = row.Selected;
     59      }
     60      suppressEvents = true;
     61      Results.FireChanged();
     62      suppressEvents = false;
    5163    }
    5264  }
     65
     66  public class TablesResultsViewFactory : IResultsViewFactory {
     67    #region IResultsViewFactory Members
     68
     69    public string Name {
     70      get { return "Table"; }
     71    }
     72
     73    public IControl CreateView(Results results) {
     74      return new TableResultsView(results);
     75    }
     76
     77    #endregion
     78  }
    5379}
Note: See TracChangeset for help on using the changeset viewer.