Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9737 for stable


Ignore:
Timestamp:
07/23/13 15:12:10 (11 years ago)
Author:
mkommend
Message:

#2075: Integrated the performed changes in the stable branch.

Location:
stable
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Data.Views/3.3/StringConvertibleArrayView.cs

    r9456 r9737  
    5353
    5454    protected override void DeregisterContentEvents() {
     55      Content.ElementNamesChanged -= new EventHandler(Content_ElementNamesChanged);
    5556      Content.ItemChanged -= new EventHandler<EventArgs<int>>(Content_ItemChanged);
    5657      Content.Reset -= new EventHandler(Content_Reset);
     
    6263      Content.ItemChanged += new EventHandler<EventArgs<int>>(Content_ItemChanged);
    6364      Content.Reset += new EventHandler(Content_Reset);
     65      Content.ElementNamesChanged += new EventHandler(Content_ElementNamesChanged);
    6466    }
    6567
     
    9698        dataGridView.Columns[0].Width = dataGridView.Columns[0].GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true);
    9799      }
     100      UpdateRowHeaders();
     101      dataGridView.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders);
    98102      dataGridView.Enabled = true;
     103    }
     104
     105    protected virtual void UpdateRowHeaders() {
     106      int i = 0;
     107      foreach (string elementName in Content.ElementNames) {
     108        dataGridView.Rows[i].HeaderCell.Value = elementName;
     109        i++;
     110      }
     111      for (; i < dataGridView.RowCount; i++) {
     112        dataGridView.Rows[i].HeaderCell.Value = string.Empty;
     113      }
     114    }
     115
     116    private void Content_ElementNamesChanged(object sender, EventArgs e) {
     117      if (InvokeRequired)
     118        Invoke(new EventHandler(Content_ElementNamesChanged), sender, e);
     119      else
     120        UpdateRowHeaders();
    99121    }
    100122
  • stable/HeuristicLab.Data/3.3/Interfaces/IStringConvertibleArray.cs

    r9456 r9737  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using HeuristicLab.Common;
    2425
     
    2627  public interface IStringConvertibleArray : IContent {
    2728    int Length { get; set; }
     29    IEnumerable<string> ElementNames { get; set; }
    2830
    2931    bool ReadOnly { get; }
     
    3335    bool SetValue(string value, int index);
    3436
     37    event EventHandler ElementNamesChanged;
    3538    event EventHandler<EventArgs<int>> ItemChanged;
    3639    event EventHandler Reset;
  • stable/HeuristicLab.Data/3.3/StringArray.cs

    r9456 r9737  
    4343    protected string[] array;
    4444
     45    [Storable]
     46    protected List<string> elementNames;
     47    public virtual IEnumerable<string> ElementNames {
     48      get { return this.elementNames; }
     49      set {
     50        if (ReadOnly) throw new NotSupportedException("ElementNames cannot be set. ValueTypeArray is read-only.");
     51        if (value == null || !value.Any())
     52          elementNames = new List<string>();
     53        else if (value.Count() > Length)
     54          throw new ArgumentException("The number of element names must not exceed the array length.");
     55        else
     56          elementNames = new List<string>(value);
     57        OnElementNamesChanged();
     58      }
     59    }
     60
    4561    public virtual int Length {
    4662      get { return array.Length; }
     
    4965        if (value != Length) {
    5066          Array.Resize<string>(ref array, value);
     67          while (elementNames.Count > value)
     68            elementNames.RemoveAt(elementNames.Count - 1);
     69          OnElementNamesChanged();
    5170          OnReset();
    5271        }
     
    7291    }
    7392
     93    [StorableHook(HookType.AfterDeserialization)]
     94    private void AfterDeserialization() {
     95      if (elementNames == null) { elementNames = new List<string>(); }
     96    }
     97
    7498    [StorableConstructor]
    7599    protected StringArray(bool deserializing) : base(deserializing) { }
     
    78102      this.array = (string[])original.array.Clone();
    79103      this.readOnly = original.readOnly;
     104      this.elementNames = new List<string>(original.elementNames);
    80105    }
    81106    public StringArray() {
    82107      array = new string[0];
    83108      readOnly = false;
     109      elementNames = new List<string>();
    84110    }
    85111    public StringArray(int length) {
     
    88114        array[i] = string.Empty;
    89115      readOnly = false;
     116      elementNames = new List<string>();
    90117    }
    91118    public StringArray(string[] elements) {
     
    95122        array[i] = elements[i] == null ? string.Empty : elements[i];
    96123      readOnly = false;
     124      elementNames = new List<string>();
    97125    }
    98126
     
    153181    }
    154182
     183    public event EventHandler ElementNamesChanged;
     184    protected virtual void OnElementNamesChanged() {
     185      EventHandler handler = ElementNamesChanged;
     186      if (handler != null)
     187        handler(this, EventArgs.Empty);
     188    }
     189
    155190    public event EventHandler<EventArgs<int>> ItemChanged;
    156191    protected virtual void OnItemChanged(int index) {
  • stable/HeuristicLab.Data/3.3/ValueTypeArray.cs

    r9456 r9737  
    4343    protected T[] array;
    4444
     45    [Storable]
     46    protected List<string> elementNames;
     47    public virtual IEnumerable<string> ElementNames {
     48      get { return this.elementNames; }
     49      set {
     50        if (ReadOnly) throw new NotSupportedException("ElementNames cannot be set. ValueTypeArray is read-only.");
     51        if (value == null || !value.Any())
     52          elementNames = new List<string>();
     53        else if (value.Count() > Length)
     54          throw new ArgumentException("The number of element names must not exceed the array length.");
     55        else
     56          elementNames = new List<string>(value);
     57        OnElementNamesChanged();
     58      }
     59    }
     60
    4561    public virtual int Length {
    4662      get { return array.Length; }
     
    5167        if (value != Length) {
    5268          Array.Resize<T>(ref array, value);
     69          while (elementNames.Count > value)
     70            elementNames.RemoveAt(elementNames.Count - 1);
     71          OnElementNamesChanged();
    5372          OnReset();
    5473        }
     
    7392    }
    7493
     94    [StorableHook(HookType.AfterDeserialization)]
     95    private void AfterDeserialization() {
     96      if (elementNames == null) { elementNames = new List<string>(); }
     97    }
     98
    7599    [StorableConstructor]
    76100    protected ValueTypeArray(bool deserializing) : base(deserializing) { }
     
    79103      this.array = (T[])original.array.Clone();
    80104      this.readOnly = original.readOnly;
     105      this.elementNames = new List<string>(original.elementNames);
    81106    }
    82107    protected ValueTypeArray() {
    83108      array = new T[0];
    84109      readOnly = false;
     110      elementNames = new List<string>();
    85111    }
    86112    protected ValueTypeArray(int length) {
    87113      array = new T[length];
    88114      readOnly = false;
     115      elementNames = new List<string>();
    89116    }
    90117    protected ValueTypeArray(T[] elements) {
     
    92119      array = (T[])elements.Clone();
    93120      readOnly = false;
     121      elementNames = new List<string>();
    94122    }
    95123
     
    125153    }
    126154
     155    public event EventHandler ElementNamesChanged;
     156    protected virtual void OnElementNamesChanged() {
     157      EventHandler handler = ElementNamesChanged;
     158      if (handler != null)
     159        handler(this, EventArgs.Empty);
     160    }
     161
    127162    public event EventHandler<EventArgs<int>> ItemChanged;
    128163    protected virtual void OnItemChanged(int index) {
Note: See TracChangeset for help on using the changeset viewer.