Changeset 9308


Ignore:
Timestamp:
03/12/13 12:20:25 (9 years ago)
Author:
sforsten
Message:

#2018:

  • added column names to the ValueTypeArray and StringArray
  • added batch update methods to IStringConvertibleArray similar to methods in IStringConvertibleMatrix
Location:
branches/ImprovingStringConvertibleMatrix
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • branches/ImprovingStringConvertibleMatrix/HeuristicLab.Data.Views/3.3/StringConvertibleArrayView.cs

    r7984 r9308  
    2323using System.ComponentModel;
    2424using System.Drawing;
     25using System.Linq;
    2526using System.Text;
    2627using System.Windows.Forms;
    27 using HeuristicLab.Common;
    2828using HeuristicLab.MainForm;
    2929using HeuristicLab.MainForm.WindowsForms;
     
    5353
    5454    protected override void DeregisterContentEvents() {
    55       Content.ItemChanged -= new EventHandler<EventArgs<int>>(Content_ItemChanged);
     55      Content.ColumnNamesChanged -= new EventHandler(Content_ColumnNamesChanged);
    5656      Content.Reset -= new EventHandler(Content_Reset);
     57      Content.ItemsChanged -= new EventHandler<ArrayValuesChangedEventArgs>(Content_ItemsChanged);
    5758      base.DeregisterContentEvents();
    5859    }
     
    6061    protected override void RegisterContentEvents() {
    6162      base.RegisterContentEvents();
    62       Content.ItemChanged += new EventHandler<EventArgs<int>>(Content_ItemChanged);
     63      Content.ItemsChanged += new EventHandler<ArrayValuesChangedEventArgs>(Content_ItemsChanged);
    6364      Content.Reset += new EventHandler(Content_Reset);
     65      Content.ColumnNamesChanged -= new EventHandler(Content_ColumnNamesChanged);
    6466    }
    6567
     
    9496          dataGridView.Rows[i].Cells[0].Value = Content.GetValue(i);
    9597        }
     98
    9699        dataGridView.Columns[0].Width = dataGridView.Columns[0].GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true);
    97100      }
     101      UpdateRowHeaders();
     102      dataGridView.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders);
    98103      dataGridView.Enabled = true;
    99104    }
    100105
    101     private void Content_ItemChanged(object sender, EventArgs<int> e) {
     106    protected virtual void UpdateRowHeaders() {
     107      for (int i = 0; i < dataGridView.RowCount; i++) {
     108        if (i < Content.ColumnNames.Count())
     109          dataGridView.Rows[i].HeaderCell.Value = Content.ColumnNames.ElementAt(i);
     110        else
     111          dataGridView.Rows[i].HeaderCell.Value = "Column " + (i + 1);
     112      }
     113    }
     114
     115    private void Content_ItemsChanged(object sender, ArrayValuesChangedEventArgs e) {
    102116      if (InvokeRequired)
    103         Invoke(new EventHandler<EventArgs<int>>(Content_ItemChanged), sender, e);
     117        Invoke(new EventHandler<ArrayValuesChangedEventArgs>(Content_ItemsChanged), sender, e);
    104118      else {
    105         dataGridView.Rows[e.Value].Cells[0].Value = Content.GetValue(e.Value);
    106         Size size = dataGridView.Rows[e.Value].Cells[0].PreferredSize;
    107         dataGridView.Columns[0].Width = Math.Max(dataGridView.Columns[0].Width, size.Width);
    108       }
     119        foreach (var index in e.Value) {
     120          dataGridView.Rows[index].Cells[0].Value = Content.GetValue(index);
     121          Size size = dataGridView.Rows[index].Cells[0].PreferredSize;
     122          dataGridView.Columns[0].Width = Math.Max(dataGridView.Columns[0].Width, size.Width);
     123        }
     124      }
     125    }
     126    private void Content_ColumnNamesChanged(object sender, EventArgs e) {
     127      if (InvokeRequired)
     128        Invoke(new EventHandler(Content_ColumnNamesChanged), sender, e);
     129      else
     130        UpdateRowHeaders();
    109131    }
    110132    private void Content_Reset(object sender, EventArgs e) {
  • branches/ImprovingStringConvertibleMatrix/HeuristicLab.Data/3.3/BoolArray.cs

    r7259 r9308  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using System.Text;
    2326using HeuristicLab.Common;
     
    2831  [Item("BoolArray", "Represents an array of boolean values.")]
    2932  [StorableClass]
    30   public class BoolArray : ValueTypeArray<bool>, IStringConvertibleArray {
     33  public class BoolArray : ValueTypeArray<bool> {
    3134    [StorableConstructor]
    3235    protected BoolArray(bool deserializing) : base(deserializing) { }
     
    4245    }
    4346
    44     protected virtual bool Validate(string value, out string errorMessage) {
     47    protected override bool Validate(string value, out string errorMessage) {
    4548      bool val;
    4649      bool valid = bool.TryParse(value, out val);
     
    5558      return valid;
    5659    }
    57     protected virtual string GetValue(int index) {
     60    protected override string GetValue(int index) {
    5861      return this[index].ToString();
    5962    }
    60     protected virtual bool SetValue(string value, int index) {
     63    protected override bool SetValue(string value, int index) {
     64      if (ReadOnly) throw new NotSupportedException("Item cannot be set. ValueTypeArray is read-only.");
    6165      bool val;
    6266      if (bool.TryParse(value, out val)) {
     
    6872    }
    6973
    70     #region IStringConvertibleArray Members
    71     int IStringConvertibleArray.Length {
    72       get { return Length; }
    73       set { Length = value; }
     74    protected override bool SetValues(IEnumerable<ArrayValue<string>> arrayValues) {
     75      if (ReadOnly) throw new NotSupportedException("Item cannot be set. ValueTypeArray is read-only.");
     76      bool parsed;
     77      if (!arrayValues.All(v => bool.TryParse(v.Value, out parsed))) return false;
     78      List<int> positions = new List<int>();
     79      foreach (var v in arrayValues) {
     80        parsed = bool.Parse(v.Value);
     81        if (array[v.Index] != parsed) {
     82          array[v.Index] = parsed;
     83          positions.Add(v.Index);
     84        }
     85      }
     86      OnItemsChanged(positions);
     87      return true;
    7488    }
    75     bool IStringConvertibleArray.Validate(string value, out string errorMessage) {
    76       return Validate(value, out errorMessage);
    77     }
    78     string IStringConvertibleArray.GetValue(int index) {
    79       return GetValue(index);
    80     }
    81     bool IStringConvertibleArray.SetValue(string value, int index) {
    82       return SetValue(value, index);
    83     }
    84     #endregion
    8589  }
    8690}
  • branches/ImprovingStringConvertibleMatrix/HeuristicLab.Data/3.3/BoolMatrix.cs

    r9306 r9308  
    6666    }
    6767    protected override bool SetValue(string value, int rowIndex, int columnIndex) {
     68      if (ReadOnly) throw new NotSupportedException("Item cannot be set. BoolMatrix is read-only.");
    6869      bool val;
    6970      if (bool.TryParse(value, out val)) {
     
    8687        }
    8788      }
     89      OnItemsChanged(positions);
    8890      return true;
    8991    }
  • branches/ImprovingStringConvertibleMatrix/HeuristicLab.Data/3.3/DoubleArray.cs

    r7259 r9308  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using System.Text;
    2326using HeuristicLab.Common;
     
    2831  [Item("DoubleArray", "Represents an array of double values.")]
    2932  [StorableClass]
    30   public class DoubleArray : ValueTypeArray<double>, IStringConvertibleArray {
     33  public class DoubleArray : ValueTypeArray<double> {
    3134    [StorableConstructor]
    3235    protected DoubleArray(bool deserializing) : base(deserializing) { }
     
    4245    }
    4346
    44     protected virtual bool Validate(string value, out string errorMessage) {
     47    protected override bool Validate(string value, out string errorMessage) {
    4548      double val;
    4649      bool valid = double.TryParse(value, out val);
     
    5558      return valid;
    5659    }
    57     protected virtual string GetValue(int index) {
     60    protected override string GetValue(int index) {
    5861      return this[index].ToString();
    5962    }
    60     protected virtual bool SetValue(string value, int index) {
     63    protected override bool SetValue(string value, int index) {
     64      if (ReadOnly) throw new NotSupportedException("Item cannot be set. ValueTypeArray is read-only.");
    6165      double val;
    6266      if (double.TryParse(value, out val)) {
     
    6872    }
    6973
    70     #region IStringConvertibleArray Members
    71     int IStringConvertibleArray.Length {
    72       get { return Length; }
    73       set { Length = value; }
     74    protected override bool SetValues(IEnumerable<ArrayValue<string>> arrayValues) {
     75      if (ReadOnly) throw new NotSupportedException("Item cannot be set. ValueTypeArray is read-only.");
     76      double parsed;
     77      if (!arrayValues.All(v => double.TryParse(v.Value, out parsed))) return false;
     78      List<int> positions = new List<int>();
     79      foreach (var v in arrayValues) {
     80        parsed = double.Parse(v.Value);
     81        if (array[v.Index] != parsed) {
     82          array[v.Index] = parsed;
     83          positions.Add(v.Index);
     84        }
     85      }
     86      OnItemsChanged(positions);
     87      return true;
    7488    }
    75     bool IStringConvertibleArray.Validate(string value, out string errorMessage) {
    76       return Validate(value, out errorMessage);
    77     }
    78     string IStringConvertibleArray.GetValue(int index) {
    79       return GetValue(index);
    80     }
    81     bool IStringConvertibleArray.SetValue(string value, int index) {
    82       return SetValue(value, index);
    83     }
    84     #endregion
    8589  }
    8690}
  • branches/ImprovingStringConvertibleMatrix/HeuristicLab.Data/3.3/DoubleMatrix.cs

    r9306 r9308  
    6666    }
    6767    protected override bool SetValue(string value, int rowIndex, int columnIndex) {
     68      if (ReadOnly) throw new NotSupportedException("Item cannot be set. DoubleMatrix is read-only.");
    6869      double val;
    6970      if (double.TryParse(value, out val)) {
     
    7677    protected override bool SetValues(IEnumerable<MatrixValue<string>> matrixValues) {
    7778      if (ReadOnly) throw new NotSupportedException("Item cannot be set. DoubleMatrix is read-only.");
    78 
    7979      double parsed;
    8080      if (!matrixValues.All(v => double.TryParse(v.Value, out parsed))) return false;
     
    8787        }
    8888      }
     89      OnItemsChanged(positions);
    8990      return true;
    9091    }
  • branches/ImprovingStringConvertibleMatrix/HeuristicLab.Data/3.3/IntArray.cs

    r7259 r9308  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using System.Text;
    2326using HeuristicLab.Common;
     
    2831  [Item("IntArray", "Represents an array of integer values.")]
    2932  [StorableClass]
    30   public class IntArray : ValueTypeArray<int>, IStringConvertibleArray {
     33  public class IntArray : ValueTypeArray<int> {
    3134    [StorableConstructor]
    3235    protected IntArray(bool deserializing) : base(deserializing) { }
     
    4245    }
    4346
    44     protected virtual bool Validate(string value, out string errorMessage) {
     47    protected override bool Validate(string value, out string errorMessage) {
    4548      int val;
    4649      bool valid = int.TryParse(value, out val);
     
    5558      return valid;
    5659    }
    57     protected virtual string GetValue(int index) {
     60    protected override string GetValue(int index) {
    5861      return this[index].ToString();
    5962    }
    60     protected virtual bool SetValue(string value, int index) {
     63    protected override bool SetValue(string value, int index) {
     64      if (ReadOnly) throw new NotSupportedException("Item cannot be set. ValueTypeArray is read-only.");
    6165      int val;
    6266      if (int.TryParse(value, out val)) {
     
    6771      }
    6872    }
    69 
    70     #region IStringConvertibleArray Members
    71     int IStringConvertibleArray.Length {
    72       get { return Length; }
    73       set { Length = value; }
     73    protected override bool SetValues(IEnumerable<ArrayValue<string>> arrayValues) {
     74      if (ReadOnly) throw new NotSupportedException("Item cannot be set. ValueTypeArray is read-only.");
     75      int parsed;
     76      if (!arrayValues.All(v => int.TryParse(v.Value, out parsed))) return false;
     77      List<int> positions = new List<int>();
     78      foreach (var v in arrayValues) {
     79        parsed = int.Parse(v.Value);
     80        if (array[v.Index] != parsed) {
     81          array[v.Index] = parsed;
     82          positions.Add(v.Index);
     83        }
     84      }
     85      OnItemsChanged(positions);
     86      return true;
    7487    }
    75     bool IStringConvertibleArray.Validate(string value, out string errorMessage) {
    76       return Validate(value, out errorMessage);
    77     }
    78     string IStringConvertibleArray.GetValue(int index) {
    79       return GetValue(index);
    80     }
    81     bool IStringConvertibleArray.SetValue(string value, int index) {
    82       return SetValue(value, index);
    83     }
    84     #endregion
    8588  }
    8689}
  • branches/ImprovingStringConvertibleMatrix/HeuristicLab.Data/3.3/IntMatrix.cs

    r9306 r9308  
    6666    }
    6767    protected override bool SetValue(string value, int rowIndex, int columnIndex) {
     68      if (ReadOnly) throw new NotSupportedException("Item cannot be set. IntMatrix is read-only.");
    6869      int val;
    6970      if (int.TryParse(value, out val)) {
     
    8687        }
    8788      }
     89      OnItemsChanged(positions);
    8890      return true;
    8991    }
  • branches/ImprovingStringConvertibleMatrix/HeuristicLab.Data/3.3/Interfaces/IStringConvertibleArray.cs

    r7259 r9308  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using HeuristicLab.Common;
    2425
     
    2627  public interface IStringConvertibleArray : IContent {
    2728    int Length { get; set; }
     29    IEnumerable<string> ColumnNames { get; set; }
    2830
    2931    bool ReadOnly { get; }
     
    3234    string GetValue(int index);
    3335    bool SetValue(string value, int index);
     36    bool SetValue(ArrayValue<string> arrayValue);
     37    bool SetValues(IEnumerable<ArrayValue<string>> arrayValues);
    3438
    35     event EventHandler<EventArgs<int>> ItemChanged;
     39    event EventHandler ColumnNamesChanged;
     40    event EventHandler<ArrayValuesChangedEventArgs> ItemsChanged;
    3641    event EventHandler Reset;
    3742  }
     43  public class ArrayValuesChangedEventArgs : EventArgs<IEnumerable<int>> {
     44    public ArrayValuesChangedEventArgs(IEnumerable<int> indices) : base(indices) { }
     45  }
     46  public struct ArrayValue<T> {
     47    public int Index { get; private set; }
     48    public T Value { get; private set; }
     49
     50    public ArrayValue(int index, T value)
     51      : this() {
     52      Index = index;
     53      Value = value;
     54    }
     55  }
    3856}
  • branches/ImprovingStringConvertibleMatrix/HeuristicLab.Data/3.3/StringArray.cs

    r7259 r9308  
    4141    protected string[] array;
    4242
     43    [Storable]
     44    protected List<string> columnNames;
     45    public virtual IEnumerable<string> ColumnNames {
     46      get { return this.columnNames; }
     47      set {
     48        if (ReadOnly) throw new NotSupportedException("ColumnNames cannot be set. ValueTypeArray is read-only.");
     49        if (value == null || value.Count() == 0)
     50          columnNames = new List<string>();
     51        else if (value.Count() != Length)
     52          throw new ArgumentException("A column name must be specified for each column.");
     53        else
     54          columnNames = new List<string>(value);
     55        OnColumnNamesChanged();
     56      }
     57    }
     58
    4359    public virtual int Length {
    4460      get { return array.Length; }
     
    4763        if (value != Length) {
    4864          Array.Resize<string>(ref array, value);
     65          while (columnNames.Count > value)
     66            columnNames.RemoveAt(columnNames.Count - 1);
     67          while (columnNames.Count < value)
     68            columnNames.Add("Column " + columnNames.Count);
     69          OnColumnNamesChanged();
    4970          OnReset();
    5071        }
     
    5879          if ((value != null) || (array[index] != string.Empty)) {
    5980            array[index] = value != null ? value : string.Empty;
    60             OnItemChanged(index);
     81            OnItemsChanged(new List<int>(1) { index });
    6182          }
    6283        }
     
    6889    public virtual bool ReadOnly {
    6990      get { return readOnly; }
     91    }
     92
     93    [StorableHook(HookType.AfterDeserialization)]
     94    private void AfterDeserialization() {
     95      if (columnNames == null) {
     96        columnNames = new List<string>(array.Length);
     97        while (columnNames.Count < array.Length)
     98          columnNames.Add("Column " + columnNames.Count);
     99      }
    70100    }
    71101
     
    75105      : base(original, cloner) {
    76106      this.array = (string[])original.array.Clone();
     107      this.columnNames = new List<string>(original.columnNames);
    77108      this.readOnly = original.readOnly;
    78109    }
    79110    public StringArray() {
    80111      array = new string[0];
     112      columnNames = new List<string>();
    81113      readOnly = false;
    82114    }
     
    85117      for (int i = 0; i < array.Length; i++)
    86118        array[i] = string.Empty;
     119      columnNames = new List<string>();
    87120      readOnly = false;
    88121    }
     
    92125      for (int i = 0; i < array.Length; i++)
    93126        array[i] = elements[i] == null ? string.Empty : elements[i];
     127      columnNames = new List<string>();
    94128      readOnly = false;
    95129    }
     
    138172    }
    139173    protected virtual bool SetValue(string value, int index) {
     174      if (ReadOnly) throw new NotSupportedException("Item cannot be set. StringArray is read-only.");
    140175      if (value != null) {
    141176        this[index] = value;
     
    145180      }
    146181    }
    147 
    148     public event EventHandler<EventArgs<int>> ItemChanged;
    149     protected virtual void OnItemChanged(int index) {
    150       if (ItemChanged != null)
    151         ItemChanged(this, new EventArgs<int>(index));
     182    public virtual bool SetValues(IEnumerable<ArrayValue<string>> arrayValues) {
     183      if (ReadOnly) throw new NotSupportedException("Item cannot be set. StringArray is read-only.");
     184      if (!arrayValues.All(v => v.Value != null)) return false;
     185      List<int> positions = new List<int>();
     186      foreach (var v in arrayValues) {
     187        if (array[v.Index] != v.Value) {
     188          array[v.Index] = v.Value;
     189          positions.Add(v.Index);
     190        }
     191      }
     192      OnItemsChanged(positions);
     193      return true;
     194    }
     195
     196    public event EventHandler ColumnNamesChanged;
     197    protected virtual void OnColumnNamesChanged() {
     198      EventHandler handler = ColumnNamesChanged;
     199      if (handler != null)
     200        handler(this, EventArgs.Empty);
     201    }
     202    public event EventHandler<ArrayValuesChangedEventArgs> ItemsChanged;
     203    protected virtual void OnItemsChanged(IEnumerable<int> indices) {
     204      if (ItemsChanged != null)
     205        ItemsChanged(this, new ArrayValuesChangedEventArgs(indices));
    152206      OnToStringChanged();
    153207    }
     
    173227      return SetValue(value, index);
    174228    }
     229    bool IStringConvertibleArray.SetValue(ArrayValue<string> arrayValue) {
     230      return SetValue(arrayValue.Value, arrayValue.Index);
     231    }
     232    bool IStringConvertibleArray.SetValues(IEnumerable<ArrayValue<string>> arrayValues) {
     233      return SetValues(arrayValues);
     234    }
    175235    #endregion
    176236  }
  • branches/ImprovingStringConvertibleMatrix/HeuristicLab.Data/3.3/StringMatrix.cs

    r9306 r9308  
    243243    }
    244244    protected virtual bool SetValue(string value, int rowIndex, int columnIndex) {
     245      if (ReadOnly) throw new NotSupportedException("Item cannot be set. StringMatrix is read-only.");
    245246      if (value != null) {
    246247        this[rowIndex, columnIndex] = value;
  • branches/ImprovingStringConvertibleMatrix/HeuristicLab.Data/3.3/ValueTypeArray.cs

    r8587 r9308  
    3333  [Item("ValueTypeArray", "An abstract base class for representing arrays of value types.")]
    3434  [StorableClass]
    35   public abstract class ValueTypeArray<T> : Item, IEnumerable<T> where T : struct {
     35  public abstract class ValueTypeArray<T> : Item, IEnumerable<T>, IStringConvertibleArray where T : struct {
    3636    public static new Image StaticItemImage {
    3737      get { return HeuristicLab.Common.Resources.VSImageLibrary.Class; }
     
    4040    [Storable]
    4141    protected T[] array;
     42
     43    [Storable]
     44    protected List<string> columnNames;
     45    public virtual IEnumerable<string> ColumnNames {
     46      get { return this.columnNames; }
     47      set {
     48        if (ReadOnly) throw new NotSupportedException("ColumnNames cannot be set. ValueTypeArray is read-only.");
     49        if (value == null || value.Count() == 0)
     50          columnNames = new List<string>();
     51        else if (value.Count() != Length)
     52          throw new ArgumentException("A column name must be specified for each column.");
     53        else
     54          columnNames = new List<string>(value);
     55        OnColumnNamesChanged();
     56      }
     57    }
    4258
    4359    public virtual int Length {
     
    4965        if (value != Length) {
    5066          Array.Resize<T>(ref array, value);
     67          while (columnNames.Count > value)
     68            columnNames.RemoveAt(columnNames.Count - 1);
     69          while (columnNames.Count < value)
     70            columnNames.Add("Column " + columnNames.Count);
     71          OnColumnNamesChanged();
    5172          OnReset();
    5273        }
     
    6081        if (!value.Equals(array[index])) {
    6182          array[index] = value;
    62           OnItemChanged(index);
     83          OnItemsChanged(new List<int>(1) { index });
    6384        }
    6485      }
     86    }
     87
     88    public virtual void SetValues(IEnumerable<ArrayValue<T>> arrayValues) {
     89      if (ReadOnly) throw new NotSupportedException("Item cannot be set. ValueTypeMatrix is read-only.");
     90      List<int> positions = new List<int>();
     91      foreach (var arrayValue in arrayValues) {
     92        if (!arrayValue.Value.Equals(array[arrayValue.Index])) {
     93          array[arrayValue.Index] = arrayValue.Value;
     94          positions.Add(arrayValue.Index);
     95        }
     96      }
     97      OnItemsChanged(positions);
    6598    }
    6699
     
    69102    public virtual bool ReadOnly {
    70103      get { return readOnly; }
     104    }
     105
     106    [StorableHook(HookType.AfterDeserialization)]
     107    private void AfterDeserialization() {
     108      if (columnNames == null) {
     109        columnNames = new List<string>(array.Length);
     110        while (columnNames.Count < array.Length)
     111          columnNames.Add("Column " + columnNames.Count);
     112      }
    71113    }
    72114
     
    76118      : base(original, cloner) {
    77119      this.array = (T[])original.array.Clone();
     120      this.columnNames = new List<string>(original.columnNames);
    78121      this.readOnly = original.readOnly;
    79122    }
    80123    protected ValueTypeArray() {
    81124      array = new T[0];
     125      columnNames = new List<string>();
    82126      readOnly = false;
    83127    }
    84128    protected ValueTypeArray(int length) {
    85129      array = new T[length];
     130      columnNames = new List<string>(length);
    86131      readOnly = false;
    87132    }
     
    89134      if (elements == null) throw new ArgumentNullException();
    90135      array = (T[])elements.Clone();
     136      columnNames = new List<string>(elements.Length);
    91137      readOnly = false;
    92138    }
     
    118164    }
    119165
    120     public event EventHandler<EventArgs<int>> ItemChanged;
    121     protected virtual void OnItemChanged(int index) {
    122       if (ItemChanged != null)
    123         ItemChanged(this, new EventArgs<int>(index));
     166    public event EventHandler ColumnNamesChanged;
     167    protected virtual void OnColumnNamesChanged() {
     168      EventHandler handler = ColumnNamesChanged;
     169      if (handler != null)
     170        handler(this, EventArgs.Empty);
     171    }
     172    public event EventHandler<ArrayValuesChangedEventArgs> ItemsChanged;
     173    protected virtual void OnItemsChanged(IEnumerable<int> indices) {
     174      if (ItemsChanged != null)
     175        ItemsChanged(this, new ArrayValuesChangedEventArgs(indices));
    124176      OnToStringChanged();
    125177    }
     
    130182      OnToStringChanged();
    131183    }
     184
     185    protected abstract bool Validate(string value, out string errorMessage);
     186    protected abstract string GetValue(int index);
     187    protected abstract bool SetValue(string value, int index);
     188    protected abstract bool SetValues(IEnumerable<ArrayValue<string>> arrayValues);
     189
     190    #region IStringConvertibleArray Members
     191    int IStringConvertibleArray.Length {
     192      get { return Length; }
     193      set { Length = value; }
     194    }
     195    bool IStringConvertibleArray.Validate(string value, out string errorMessage) {
     196      return Validate(value, out errorMessage);
     197    }
     198    string IStringConvertibleArray.GetValue(int index) {
     199      return GetValue(index);
     200    }
     201    bool IStringConvertibleArray.SetValue(string value, int index) {
     202      return SetValue(value, index);
     203    }
     204    bool IStringConvertibleArray.SetValue(ArrayValue<string> arrayValue) {
     205      return SetValue(arrayValue.Value, arrayValue.Index);
     206    }
     207    bool IStringConvertibleArray.SetValues(IEnumerable<ArrayValue<string>> arrayValues) {
     208      return SetValues(arrayValues);
     209    }
     210    #endregion
    132211  }
    133212}
  • branches/ImprovingStringConvertibleMatrix/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionSolution.cs

    r9306 r9308  
    204204
    205205    private void RegisterBestKnownRealVectorEvents() {
    206       BestKnownRealVector.ItemChanged += new EventHandler<EventArgs<int>>(BestKnownRealVector_ItemChanged);
     206      BestKnownRealVector.ItemsChanged += new EventHandler<ArrayValuesChangedEventArgs>(BestKnownRealVector_ItemChanged);
    207207      BestKnownRealVector.Reset += new EventHandler(BestKnownRealVector_Reset);
    208208    }
    209209    private void DeregisterBestKnownRealVectorEvents() {
    210       BestKnownRealVector.ItemChanged -= new EventHandler<EventArgs<int>>(BestKnownRealVector_ItemChanged);
     210      BestKnownRealVector.ItemsChanged -= new EventHandler<ArrayValuesChangedEventArgs>(BestKnownRealVector_ItemChanged);
    211211      BestKnownRealVector.Reset -= new EventHandler(BestKnownRealVector_Reset);
    212212    }
    213213    private void RegisterBestRealVectorEvents() {
    214       BestRealVector.ItemChanged += new EventHandler<EventArgs<int>>(BestRealVector_ItemChanged);
     214      BestRealVector.ItemsChanged += new EventHandler<ArrayValuesChangedEventArgs>(BestRealVector_ItemChanged);
    215215      BestRealVector.Reset += new EventHandler(BestRealVector_Reset);
    216216    }
    217217    private void DeregisterBestRealVectorEvents() {
    218       BestRealVector.ItemChanged -= new EventHandler<EventArgs<int>>(BestRealVector_ItemChanged);
     218      BestRealVector.ItemsChanged -= new EventHandler<ArrayValuesChangedEventArgs>(BestRealVector_ItemChanged);
    219219      BestRealVector.Reset -= new EventHandler(BestRealVector_Reset);
    220220    }
     
    244244    }
    245245
    246     private void BestKnownRealVector_ItemChanged(object sender, EventArgs<int> e) {
     246    private void BestKnownRealVector_ItemChanged(object sender, ArrayValuesChangedEventArgs e) {
    247247      OnBestKnownRealVectorChanged();
    248248    }
     
    250250      OnBestKnownRealVectorChanged();
    251251    }
    252     private void BestRealVector_ItemChanged(object sender, EventArgs<int> e) {
     252    private void BestRealVector_ItemChanged(object sender, ArrayValuesChangedEventArgs e) {
    253253      OnBestRealVectorChanged();
    254254    }
  • branches/ImprovingStringConvertibleMatrix/HeuristicLab.Problems.TravelingSalesman/3.3/PathTSPTour.cs

    r9306 r9308  
    152152    }
    153153    private void RegisterPermutationEvents() {
    154       Permutation.ItemChanged += new EventHandler<EventArgs<int>>(Permutation_ItemChanged);
     154      Permutation.ItemsChanged += new EventHandler<ArrayValuesChangedEventArgs>(Permutation_ItemChanged);
    155155      Permutation.Reset += new EventHandler(Permutation_Reset);
    156156    }
    157157    private void DeregisterPermutationEvents() {
    158       Permutation.ItemChanged -= new EventHandler<EventArgs<int>>(Permutation_ItemChanged);
     158      Permutation.ItemsChanged -= new EventHandler<ArrayValuesChangedEventArgs>(Permutation_ItemChanged);
    159159      Permutation.Reset -= new EventHandler(Permutation_Reset);
    160160    }
     
    172172      OnCoordinatesChanged();
    173173    }
    174     private void Permutation_ItemChanged(object sender, EventArgs<int> e) {
     174    private void Permutation_ItemChanged(object sender, ArrayValuesChangedEventArgs e) {
    175175      OnPermutationChanged();
    176176    }
  • branches/ImprovingStringConvertibleMatrix/HeuristicLab.Problems.VehicleRouting/3.3/VehicleRoutingProblem.cs

    r9306 r9308  
    297297    }
    298298    void DemandParameter_ValueChanged(object sender, EventArgs e) {
    299       Demand.ItemChanged += new EventHandler<EventArgs<int>>(Demand_ItemChanged);
     299      Demand.ItemsChanged += new EventHandler<ArrayValuesChangedEventArgs>(Demand_ItemChanged);
    300300      Demand.Reset += new EventHandler(Demand_Reset);
    301301      BestKnownSolution = null;
     
    304304      BestKnownSolution = null;
    305305    }
    306     void Demand_ItemChanged(object sender, EventArgs<int> e) {
     306    void Demand_ItemChanged(object sender, ArrayValuesChangedEventArgs e) {
    307307      BestKnownSolution = null;
    308308    }
    309309    void DueTimeParameter_ValueChanged(object sender, EventArgs e) {
    310       DueTime.ItemChanged += new EventHandler<EventArgs<int>>(DueTime_ItemChanged);
     310      DueTime.ItemsChanged += new EventHandler<ArrayValuesChangedEventArgs>(DueTime_ItemChanged);
    311311      DueTime.Reset += new EventHandler(DueTime_Reset);
    312312      BestKnownSolution = null;
     
    315315      BestKnownSolution = null;
    316316    }
    317     void DueTime_ItemChanged(object sender, EventArgs<int> e) {
     317    void DueTime_ItemChanged(object sender, ArrayValuesChangedEventArgs e) {
    318318      BestKnownSolution = null;
    319319    }
    320320    void ReadyTimeParameter_ValueChanged(object sender, EventArgs e) {
    321       ReadyTime.ItemChanged += new EventHandler<EventArgs<int>>(ReadyTime_ItemChanged);
     321      ReadyTime.ItemsChanged += new EventHandler<ArrayValuesChangedEventArgs>(ReadyTime_ItemChanged);
    322322      ReadyTime.Reset += new EventHandler(ReadyTime_Reset);
    323323      BestKnownSolution = null;
     
    326326      BestKnownSolution = null;
    327327    }
    328     void ReadyTime_ItemChanged(object sender, EventArgs<int> e) {
     328    void ReadyTime_ItemChanged(object sender, ArrayValuesChangedEventArgs e) {
    329329      BestKnownSolution = null;
    330330    }
    331331    void ServiceTimeParameter_ValueChanged(object sender, EventArgs e) {
    332       ServiceTime.ItemChanged += new EventHandler<EventArgs<int>>(ServiceTime_ItemChanged);
     332      ServiceTime.ItemsChanged += new EventHandler<ArrayValuesChangedEventArgs>(ServiceTime_ItemChanged);
    333333      ServiceTime.Reset += new EventHandler(ServiceTime_Reset);
    334334      BestKnownSolution = null;
     
    337337      BestKnownSolution = null;
    338338    }
    339     void ServiceTime_ItemChanged(object sender, EventArgs<int> e) {
     339    void ServiceTime_ItemChanged(object sender, ArrayValuesChangedEventArgs e) {
    340340      BestKnownSolution = null;
    341341    }
     
    392392      Capacity.ValueChanged += new EventHandler(Capacity_ValueChanged);
    393393      DemandParameter.ValueChanged += new EventHandler(DemandParameter_ValueChanged);
    394       Demand.ItemChanged += new EventHandler<EventArgs<int>>(Demand_ItemChanged);
     394      Demand.ItemsChanged += new EventHandler<ArrayValuesChangedEventArgs>(Demand_ItemChanged);
    395395      Demand.Reset += new EventHandler(Demand_Reset);
    396396      DueTimeParameter.ValueChanged += new EventHandler(DueTimeParameter_ValueChanged);
    397       DueTime.ItemChanged += new EventHandler<EventArgs<int>>(DueTime_ItemChanged);
     397      DueTime.ItemsChanged += new EventHandler<ArrayValuesChangedEventArgs>(DueTime_ItemChanged);
    398398      DueTime.Reset += new EventHandler(DueTime_Reset);
    399399      ReadyTimeParameter.ValueChanged += new EventHandler(ReadyTimeParameter_ValueChanged);
    400       ReadyTime.ItemChanged += new EventHandler<EventArgs<int>>(ReadyTime_ItemChanged);
     400      ReadyTime.ItemsChanged += new EventHandler<ArrayValuesChangedEventArgs>(ReadyTime_ItemChanged);
    401401      ReadyTime.Reset += new EventHandler(ReadyTime_Reset);
    402402      ServiceTimeParameter.ValueChanged += new EventHandler(ServiceTimeParameter_ValueChanged);
    403       ServiceTime.ItemChanged += new EventHandler<EventArgs<int>>(ServiceTime_ItemChanged);
     403      ServiceTime.ItemsChanged += new EventHandler<ArrayValuesChangedEventArgs>(ServiceTime_ItemChanged);
    404404      ServiceTime.Reset += new EventHandler(ServiceTime_Reset);
    405405      VehiclesParameter.ValueChanged += new EventHandler(VehiclesParameter_ValueChanged);
  • branches/ImprovingStringConvertibleMatrix/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPTW/MDCVRPPDTW/MDCVRPPDTWProblemInstance.cs

    r8053 r9308  
    125125    #region Event handlers
    126126    void PickupDeliveryLocationParameter_ValueChanged(object sender, EventArgs e) {
    127       PickupDeliveryLocationParameter.Value.ItemChanged += new EventHandler<EventArgs<int>>(Value_ItemChanged);
     127      PickupDeliveryLocationParameter.Value.ItemsChanged += new EventHandler<ArrayValuesChangedEventArgs>(Value_ItemChanged);
    128128      EvalBestKnownSolution();
    129129    }
    130130
    131     void Value_ItemChanged(object sender, EventArgs<int> e) {
     131    void Value_ItemChanged(object sender, ArrayValuesChangedEventArgs e) {
    132132      EvalBestKnownSolution();
    133133    }
  • branches/ImprovingStringConvertibleMatrix/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWProblemInstance.cs

    r8053 r9308  
    125125    #region Event handlers
    126126    void PickupDeliveryLocationParameter_ValueChanged(object sender, EventArgs e) {
    127       PickupDeliveryLocationParameter.Value.ItemChanged += new EventHandler<EventArgs<int>>(Value_ItemChanged);
     127      PickupDeliveryLocationParameter.Value.ItemsChanged += new EventHandler<ArrayValuesChangedEventArgs>(Value_ItemChanged);
    128128      EvalBestKnownSolution();
    129129    }
    130130
    131     void Value_ItemChanged(object sender, EventArgs<int> e) {
     131    void Value_ItemChanged(object sender, ArrayValuesChangedEventArgs e) {
    132132      EvalBestKnownSolution();
    133133    }
Note: See TracChangeset for help on using the changeset viewer.