Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3767


Ignore:
Timestamp:
05/11/10 14:23:31 (15 years ago)
Author:
mkommend
Message:

implemented !IStringConvertibleMatrix in DataTable (ticket #893)

Location:
trunk/sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Analysis.Views/3.3/HeuristicLab.Analysis.Views-3.3.csproj

    r3437 r3767  
    121121      <Name>HeuristicLab.Core-3.3</Name>
    122122    </ProjectReference>
     123    <ProjectReference Include="..\..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj">
     124      <Project>{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}</Project>
     125      <Name>HeuristicLab.Data-3.3</Name>
     126    </ProjectReference>
    123127    <ProjectReference Include="..\..\HeuristicLab.MainForm.WindowsForms\3.3\HeuristicLab.MainForm.WindowsForms-3.3.csproj">
    124128      <Project>{AB687BBE-1BFE-476B-906D-44237135431D}</Project>
  • trunk/sources/HeuristicLab.Analysis/3.3/DataTable.cs

    r3710 r3767  
    2121
    2222using System.Drawing;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Data;
     28using System;
     29using System.Collections.Generic;
     30using HeuristicLab.Collections;
    2631
    2732namespace HeuristicLab.Analysis {
     
    3136  [Item("DataTable", "A table of data values.")]
    3237  [StorableClass]
    33   public sealed class DataTable : NamedItem {
     38  public sealed class DataTable : NamedItem, IStringConvertibleMatrix {
    3439    public override Image ItemImage {
    3540      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Performance.ToBitmap(); }
     
    4550      : base() {
    4651      rows = new NamedItemCollection<DataRow>();
     52      this.RegisterRowsEvents();
    4753    }
    4854    public DataTable(string name)
    4955      : base(name) {
    5056      rows = new NamedItemCollection<DataRow>();
     57      this.RegisterRowsEvents();
    5158    }
    5259    public DataTable(string name, string description)
    5360      : base(name, description) {
    5461      rows = new NamedItemCollection<DataRow>();
     62      this.RegisterRowsEvents();
     63    }
     64
     65    private void RegisterRowsEvents() {
     66      rows.ItemsAdded += new CollectionItemsChangedEventHandler<DataRow>(rows_ItemsAdded);
     67      rows.ItemsRemoved += new CollectionItemsChangedEventHandler<DataRow>(rows_ItemsRemoved);
     68      rows.ItemsReplaced += new CollectionItemsChangedEventHandler<DataRow>(rows_ItemsReplaced);
     69      rows.CollectionReset += new CollectionItemsChangedEventHandler<DataRow>(rows_CollectionReset);
     70    }
     71    private void rows_ItemsAdded(object sender, CollectionItemsChangedEventArgs<DataRow> e) {
     72      foreach (DataRow row in e.Items)
     73        this.RegisterRowEvents(row);
     74      this.OnColumnNamesChanged();
     75      this.OnReset();
     76    }
     77    private void rows_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<DataRow> e) {
     78      foreach (DataRow row in e.Items)
     79        this.DeregisterRowEvents(row);
     80      this.OnColumnNamesChanged();
     81      this.OnReset();
     82    }
     83    private void rows_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<DataRow> e) {
     84      foreach (DataRow row in e.OldItems)
     85        this.DeregisterRowEvents(row);
     86      foreach (DataRow row in e.Items)
     87        this.RegisterRowEvents(row);
     88      this.OnColumnNamesChanged();
     89      this.OnReset();
     90    }
     91    private void rows_CollectionReset(object sender, CollectionItemsChangedEventArgs<DataRow> e) {
     92      foreach (DataRow row in e.OldItems)
     93        this.DeregisterRowEvents(row);
     94      foreach (DataRow row in e.Items)
     95        this.RegisterRowEvents(row);
     96      this.OnColumnNamesChanged();
     97      this.OnReset();
     98    }
     99
     100    private void RegisterRowEvents(DataRow row) {
     101      row.Values.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsAdded);
     102      row.Values.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsMoved);
     103      row.Values.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsRemoved);
     104      row.Values.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsReplaced);
     105      row.Values.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_CollectionReset);
     106    }
     107    private void DeregisterRowEvents(DataRow row) {
     108      row.Values.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsAdded);
     109      row.Values.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsMoved);
     110      row.Values.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsRemoved);
     111      row.Values.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsReplaced);
     112      row.Values.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_CollectionReset);
     113    }
     114
     115    private void Values_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) {
     116      this.OnReset();
     117    }
     118    private void Values_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) {
     119      this.OnReset();
     120    }
     121    private void Values_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) {
     122      this.OnReset();
     123    }
     124    private void Values_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) {
     125      this.OnReset();
     126    }
     127    private void Values_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) {
     128      this.OnReset();
    55129    }
    56130
     
    61135      return clone;
    62136    }
     137
     138    #region IStringConvertibleMatrix Members
     139
     140    int IStringConvertibleMatrix.Rows {
     141      get { return rows.Max(r => r.Values.Count); }
     142      set { throw new NotSupportedException(); }
     143    }
     144    int IStringConvertibleMatrix.Columns {
     145      get { return rows.Count; }
     146      set { throw new NotSupportedException(); }
     147    }
     148    IEnumerable<string> IStringConvertibleMatrix.ColumnNames {
     149      get { return rows.Select(r => r.Name); }
     150      set { throw new NotSupportedException(); }
     151    }
     152    IEnumerable<string> IStringConvertibleMatrix.RowNames {
     153      get { return new List<string>(); }
     154      set { throw new NotSupportedException(); }
     155    }
     156
     157    bool IStringConvertibleMatrix.SortableView {
     158      get { return true; }
     159      set { throw new NotSupportedException(); }
     160    }
     161    bool IStringConvertibleMatrix.ReadOnly {
     162      get { return true; }
     163    }
     164
     165    string IStringConvertibleMatrix.GetValue(int rowIndex, int columnIndex) {
     166      if (columnIndex < rows.Count) {
     167        string columnName = ((IStringConvertibleMatrix)this).ColumnNames.ElementAt(columnIndex);
     168        if (rows.ContainsKey(columnName) && rowIndex < rows[columnName].Values.Count)
     169          return rows[columnName].Values[rowIndex].ToString();
     170      }
     171      return string.Empty;
     172    }
     173
     174    bool IStringConvertibleMatrix.Validate(string value, out string errorMessage) {
     175      throw new NotSupportedException();
     176    }
     177    bool IStringConvertibleMatrix.SetValue(string value, int rowIndex, int columnIndex) {
     178      throw new NotSupportedException();
     179    }
     180
     181    public event EventHandler<EventArgs<int, int>> ItemChanged;
     182    private void OnItemChanged(int rowIndex, int columnIndex) {
     183      if (ItemChanged != null)
     184        ItemChanged(this, new EventArgs<int, int>(rowIndex, columnIndex));
     185      OnToStringChanged();
     186    }
     187    public event EventHandler Reset;
     188    private void OnReset() {
     189      if (Reset != null)
     190        Reset(this, EventArgs.Empty);
     191      OnToStringChanged();
     192    }
     193    public event EventHandler ColumnNamesChanged;
     194    private void OnColumnNamesChanged() {
     195      EventHandler handler = ColumnNamesChanged;
     196      if (handler != null)
     197        handler(this, EventArgs.Empty);
     198    }
     199    public event EventHandler RowNamesChanged;
     200    private void OnRowNamesChanged() {
     201      EventHandler handler = RowNamesChanged;
     202      if (handler != null)
     203        handler(this, EventArgs.Empty);
     204    }
     205    public event EventHandler SortableViewChanged;
     206    private void OnSortableViewChanged() {
     207      EventHandler handler = SortableViewChanged;
     208      if (handler != null)
     209        handler(this, EventArgs.Empty);
     210    }
     211
     212    #endregion
    63213  }
    64214}
  • trunk/sources/HeuristicLab.Optimization/3.3/RunCollection.cs

    r3717 r3767  
    153153    public IItem GetValue(IRun run, string columnName) {
    154154      IItem value = null;
    155        if (run.Parameters.ContainsKey(columnName))
    156          value = run.Parameters[columnName];
    157        else if (run.Results.ContainsKey(columnName))
    158          value = run.Results[columnName];
     155      if (run.Parameters.ContainsKey(columnName))
     156        value = run.Parameters[columnName];
     157      else if (run.Results.ContainsKey(columnName))
     158        value = run.Results[columnName];
    159159      return value;
    160160    }
     
    242242        handler(this, EventArgs.Empty);
    243243    }
    244 
    245244    public event EventHandler SortableViewChanged;
    246245    protected virtual void OnSortableViewChanged() {
Note: See TracChangeset for help on using the changeset viewer.