Changeset 9657
- Timestamp:
- 06/25/13 10:43:27 (12 years ago)
- Location:
- trunk/sources
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleArrayView.cs
r9456 r9657 23 23 using System.ComponentModel; 24 24 using System.Drawing; 25 using System.Linq; 25 26 using System.Text; 26 27 using System.Windows.Forms; … … 53 54 54 55 protected override void DeregisterContentEvents() { 56 Content.ElementNamesChanged -= new EventHandler(Content_ElementNamesChanged); 55 57 Content.ItemChanged -= new EventHandler<EventArgs<int>>(Content_ItemChanged); 56 58 Content.Reset -= new EventHandler(Content_Reset); … … 62 64 Content.ItemChanged += new EventHandler<EventArgs<int>>(Content_ItemChanged); 63 65 Content.Reset += new EventHandler(Content_Reset); 66 Content.ElementNamesChanged += new EventHandler(Content_ElementNamesChanged); 64 67 } 65 68 … … 96 99 dataGridView.Columns[0].Width = dataGridView.Columns[0].GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true); 97 100 } 101 UpdateRowHeaders(); 102 dataGridView.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders); 98 103 dataGridView.Enabled = true; 104 } 105 106 protected virtual void UpdateRowHeaders() { 107 for (int i = 0; i < dataGridView.RowCount; i++) { 108 if (i < Content.ElementNames.Count()) 109 dataGridView.Rows[i].HeaderCell.Value = Content.ElementNames.ElementAt(i); 110 else 111 dataGridView.Rows[i].HeaderCell.Value = string.Empty; 112 } 113 } 114 115 private void Content_ElementNamesChanged(object sender, EventArgs e) { 116 if (InvokeRequired) 117 Invoke(new EventHandler(Content_ElementNamesChanged), sender, e); 118 else 119 UpdateRowHeaders(); 99 120 } 100 121 -
trunk/sources/HeuristicLab.Data/3.3/Interfaces/IStringConvertibleArray.cs
r9456 r9657 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; 24 25 … … 26 27 public interface IStringConvertibleArray : IContent { 27 28 int Length { get; set; } 29 IEnumerable<string> ElementNames { get; set; } 28 30 29 31 bool ReadOnly { get; } … … 33 35 bool SetValue(string value, int index); 34 36 37 event EventHandler ElementNamesChanged; 35 38 event EventHandler<EventArgs<int>> ItemChanged; 36 39 event EventHandler Reset; -
trunk/sources/HeuristicLab.Data/3.3/StringArray.cs
r9456 r9657 43 43 protected string[] array; 44 44 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("An element name must be specified for each element."); 55 else 56 elementNames = new List<string>(value); 57 OnElementNamesChanged(); 58 } 59 } 60 45 61 public virtual int Length { 46 62 get { return array.Length; } … … 49 65 if (value != Length) { 50 66 Array.Resize<string>(ref array, value); 67 while (elementNames.Count > value) 68 elementNames.RemoveAt(elementNames.Count - 1); 69 while (elementNames.Count < value) 70 elementNames.Add("Element " + elementNames.Count); 71 OnElementNamesChanged(); 51 72 OnReset(); 52 73 } … … 72 93 } 73 94 95 [StorableHook(HookType.AfterDeserialization)] 96 private void AfterDeserialization() { 97 if (elementNames == null) { elementNames = new List<string>(); } 98 } 99 74 100 [StorableConstructor] 75 101 protected StringArray(bool deserializing) : base(deserializing) { } … … 78 104 this.array = (string[])original.array.Clone(); 79 105 this.readOnly = original.readOnly; 106 this.elementNames = new List<string>(original.elementNames); 80 107 } 81 108 public StringArray() { 82 109 array = new string[0]; 83 110 readOnly = false; 111 elementNames = new List<string>(); 84 112 } 85 113 public StringArray(int length) { … … 88 116 array[i] = string.Empty; 89 117 readOnly = false; 118 elementNames = new List<string>(); 90 119 } 91 120 public StringArray(string[] elements) { … … 95 124 array[i] = elements[i] == null ? string.Empty : elements[i]; 96 125 readOnly = false; 126 elementNames = new List<string>(); 97 127 } 98 128 … … 153 183 } 154 184 185 public event EventHandler ElementNamesChanged; 186 protected virtual void OnElementNamesChanged() { 187 EventHandler handler = ElementNamesChanged; 188 if (handler != null) 189 handler(this, EventArgs.Empty); 190 } 191 155 192 public event EventHandler<EventArgs<int>> ItemChanged; 156 193 protected virtual void OnItemChanged(int index) { -
trunk/sources/HeuristicLab.Data/3.3/ValueTypeArray.cs
r9456 r9657 43 43 protected T[] array; 44 44 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("An element name must be specified for each element."); 55 else 56 elementNames = new List<string>(value); 57 OnElementNamesChanged(); 58 } 59 } 60 45 61 public virtual int Length { 46 62 get { return array.Length; } … … 51 67 if (value != Length) { 52 68 Array.Resize<T>(ref array, value); 69 while (elementNames.Count > value) 70 elementNames.RemoveAt(elementNames.Count - 1); 71 while (elementNames.Count < value) 72 elementNames.Add("Element " + elementNames.Count); 73 OnElementNamesChanged(); 53 74 OnReset(); 54 75 } … … 73 94 } 74 95 96 [StorableHook(HookType.AfterDeserialization)] 97 private void AfterDeserialization() { 98 if (elementNames == null) { elementNames = new List<string>(); } 99 } 100 75 101 [StorableConstructor] 76 102 protected ValueTypeArray(bool deserializing) : base(deserializing) { } … … 79 105 this.array = (T[])original.array.Clone(); 80 106 this.readOnly = original.readOnly; 107 this.elementNames = new List<string>(original.elementNames); 81 108 } 82 109 protected ValueTypeArray() { 83 110 array = new T[0]; 84 111 readOnly = false; 112 elementNames = new List<string>(); 85 113 } 86 114 protected ValueTypeArray(int length) { 87 115 array = new T[length]; 88 116 readOnly = false; 117 elementNames = new List<string>(); 89 118 } 90 119 protected ValueTypeArray(T[] elements) { … … 92 121 array = (T[])elements.Clone(); 93 122 readOnly = false; 123 elementNames = new List<string>(); 94 124 } 95 125 … … 125 155 } 126 156 157 public event EventHandler ElementNamesChanged; 158 protected virtual void OnElementNamesChanged() { 159 EventHandler handler = ElementNamesChanged; 160 if (handler != null) 161 handler(this, EventArgs.Empty); 162 } 163 127 164 public event EventHandler<EventArgs<int>> ItemChanged; 128 165 protected virtual void OnItemChanged(int index) {
Note: See TracChangeset
for help on using the changeset viewer.