Changeset 11344
- Timestamp:
- 09/04/14 19:40:22 (10 years ago)
- Location:
- trunk/sources
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBRunView.cs
r11171 r11344 21 21 22 22 using System; 23 using System.ComponentModel; 23 24 using System.Windows.Forms; 24 25 using HeuristicLab.Core.Views; … … 40 41 41 42 protected override void DeregisterContentEvents() { 42 Content. StoredChanged -= new System.EventHandler(Content_StoredChanged);43 Content.PropertyChanged -= Content_PropertyChanged; 43 44 base.DeregisterContentEvents(); 44 45 } 45 46 protected override void RegisterContentEvents() { 46 47 base.RegisterContentEvents(); 47 Content. StoredChanged += new System.EventHandler(Content_StoredChanged);48 Content.PropertyChanged += Content_PropertyChanged; 48 49 } 49 50 … … 59 60 60 61 #region Content Events 61 private void Content_StoredChanged(object sender, System.EventArgs e) { 62 storeButton.Enabled = !Content.Stored; 62 private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) { 63 if (e.PropertyName == "Stored") 64 storeButton.Enabled = !Content.Stored; 63 65 } 64 66 #endregion … … 68 70 try { 69 71 Content.Store(); 70 } 71 catch (MissingClientRegistrationException) { 72 } catch (MissingClientRegistrationException) { 72 73 MessageBox.Show("You have to register your client to be able to store OKB runs." + Environment.NewLine 73 74 + " Please click in the menu bar on Services -> Access -> Client Information and register your client. ", "Missing client registration", MessageBoxButtons.OK, MessageBoxIcon.Information); 74 } 75 catch (Exception ex) { 75 } catch (Exception ex) { 76 76 ErrorHandling.ShowErrorDialog(this, "Store failed.", ex); 77 77 } -
trunk/sources/HeuristicLab.Clients.OKB/3.3/RunCreation/OKBRun.cs
r11171 r11344 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.ComponentModel; 24 25 using System.Drawing; 25 26 using System.IO; 26 27 using HeuristicLab.Clients.Access; 28 using HeuristicLab.Collections; 27 29 using HeuristicLab.Common; 28 30 using HeuristicLab.Core; … … 51 53 if (value != stored) { 52 54 stored = value; 53 On StoredChanged();55 OnPropertyChanged("Stored"); 54 56 OnItemImageChanged(); 55 57 } … … 60 62 get { return WrappedItem.Algorithm; } 61 63 } 62 public I Dictionary<string, IItem> Parameters {64 public IObservableDictionary<string, IItem> Parameters { 63 65 get { return WrappedItem.Parameters; } 64 66 } 65 public I Dictionary<string, IItem> Results {67 public IObservableDictionary<string, IItem> Results { 66 68 get { return WrappedItem.Results; } 67 69 } … … 162 164 163 165 #region Events 164 public event EventHandler Changed; 165 private void OnChanged() { 166 var handler = Changed; 167 if (handler != null) handler(this, EventArgs.Empty); 168 } 169 public event EventHandler StoredChanged; 170 private void OnStoredChanged() { 171 var handler = StoredChanged; 172 if (handler != null) handler(this, EventArgs.Empty); 166 public event PropertyChangedEventHandler PropertyChanged; 167 private void OnPropertyChanged(string property) { 168 var handler = PropertyChanged; 169 if (handler != null) handler(this, new PropertyChangedEventArgs(property)); 173 170 } 174 171 175 172 protected override void RegisterWrappedItemEvents() { 176 173 base.RegisterWrappedItemEvents(); 177 WrappedItem. Changed += new EventHandler(WrappedItem_Changed);174 WrappedItem.PropertyChanged += WrappedItem_PropertyChanged; 178 175 } 179 176 protected override void DeregisterWrappedItemEvents() { 180 WrappedItem. Changed -= new EventHandler(WrappedItem_Changed);177 WrappedItem.PropertyChanged -= WrappedItem_PropertyChanged; 181 178 base.DeregisterWrappedItemEvents(); 182 179 } 183 180 184 private void WrappedItem_ Changed(object sender,EventArgs e) {185 On Changed();181 private void WrappedItem_PropertyChanged(object sender, PropertyChangedEventArgs e) { 182 OnPropertyChanged(e.PropertyName); 186 183 } 187 184 #endregion -
trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionBoxPlotView.cs
r11171 r11344 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.ComponentModel; 24 25 using System.Linq; 25 26 using System.Windows.Forms; … … 92 93 protected virtual void RegisterRunEvents(IEnumerable<IRun> runs) { 93 94 foreach (IRun run in runs) 94 run. Changed += new EventHandler(run_Changed);95 run.PropertyChanged += run_PropertyChanged; 95 96 } 96 97 protected virtual void DeregisterRunEvents(IEnumerable<IRun> runs) { 97 98 foreach (IRun run in runs) 98 run. Changed -= new EventHandler(run_Changed);99 run.PropertyChanged -= run_PropertyChanged; 99 100 } 100 101 … … 133 134 } 134 135 } 135 private void run_ Changed(object sender,EventArgs e) {136 private void run_PropertyChanged(object sender, PropertyChangedEventArgs e) { 136 137 if (InvokeRequired) 137 this.Invoke( new EventHandler(run_Changed), sender, e);138 this.Invoke((Action<object, PropertyChangedEventArgs>)run_PropertyChanged, sender, e); 138 139 else if (!suppressUpdates) { 139 UpdateDataPoints(); 140 if (e.PropertyName == "Visible") 141 UpdateDataPoints(); 140 142 } 141 143 } -
trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionBubbleChartView.cs
r11171 r11344 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.ComponentModel; 24 25 using System.Drawing; 25 26 using System.Linq; … … 116 117 protected virtual void RegisterRunEvents(IEnumerable<IRun> runs) { 117 118 foreach (IRun run in runs) 118 run. Changed += new EventHandler(run_Changed);119 run.PropertyChanged += run_PropertyChanged; 119 120 } 120 121 protected virtual void DeregisterRunEvents(IEnumerable<IRun> runs) { 121 122 foreach (IRun run in runs) 122 run. Changed -= new EventHandler(run_Changed);123 run.PropertyChanged -= run_PropertyChanged; 123 124 } 124 125 … … 133 134 RegisterRunEvents(e.Items); 134 135 } 135 private void run_ Changed(object sender,EventArgs e) {136 private void run_PropertyChanged(object sender, PropertyChangedEventArgs e) { 136 137 if (suppressUpdates) return; 137 138 if (InvokeRequired) 138 this.Invoke( new EventHandler(run_Changed), sender, e);139 this.Invoke((Action<object, PropertyChangedEventArgs>)run_PropertyChanged, sender, e); 139 140 else { 140 IRun run = (IRun)sender; 141 UpdateRun(run); 142 UpdateCursorInterval(); 143 chart.ChartAreas[0].RecalculateAxesScale(); 144 UpdateAxisLabels(); 141 if (e.PropertyName == "Color" || e.PropertyName == "Visible") { 142 IRun run = (IRun)sender; 143 UpdateRun(run); 144 UpdateCursorInterval(); 145 chart.ChartAreas[0].RecalculateAxesScale(); 146 UpdateAxisLabels(); 147 } 145 148 } 146 149 } … … 670 673 if (xAxisValue != null) 671 674 xAxis.Title = xAxisValue; 672 if (yAxisValue != null)673 yAxis.Title = yAxisValue;675 if (yAxisValue != null) 676 yAxis.Title = yAxisValue; 674 677 } 675 678 -
trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionChartAggregationView.cs
r11171 r11344 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.ComponentModel; 24 25 using System.Linq; 25 26 using System.Windows.Forms; … … 111 112 112 113 private void RegisterRunEvents(IRun run) { 113 run. Changed += new System.EventHandler(run_Changed);114 run.PropertyChanged += run_PropertyChanged; 114 115 } 115 116 private void DeregisterRunEvents(IRun run) { 116 run. Changed -= new System.EventHandler(run_Changed);117 } 118 private void run_ Changed(object sender,EventArgs e) {117 run.PropertyChanged -= run_PropertyChanged; 118 } 119 private void run_PropertyChanged(object sender, PropertyChangedEventArgs e) { 119 120 if (suppressUpdates) return; 120 var run = (IRun)sender; 121 UpdateRuns(new IRun[] { run }); 121 if (InvokeRequired) { 122 Invoke((Action<object, PropertyChangedEventArgs>)run_PropertyChanged, sender, e); 123 } else { 124 var run = (IRun)sender; 125 if (e.PropertyName == "Color" || e.PropertyName == "Visible") 126 UpdateRuns(new IRun[] { run }); 127 } 122 128 } 123 129 #endregion -
trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionTableView.cs
r11171 r11344 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.ComponentModel; 24 25 using System.Linq; 25 26 using System.Windows.Forms; … … 70 71 private void RegisterRunEvents(IEnumerable<IRun> runs) { 71 72 foreach (IRun run in runs) 72 run. Changed += new EventHandler(run_Changed);73 run.PropertyChanged += run_PropertyChanged; 73 74 } 74 75 protected override void DeregisterContentEvents() { … … 83 84 private void DeregisterRunEvents(IEnumerable<IRun> runs) { 84 85 foreach (IRun run in runs) 85 run. Changed -= new EventHandler(run_Changed);86 run.PropertyChanged -= run_PropertyChanged; 86 87 } 87 88 private void Content_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) { … … 100 101 else UpdateCaption(); 101 102 } 102 private void run_ Changed(object sender,EventArgs e) {103 private void run_PropertyChanged(object sender, PropertyChangedEventArgs e) { 103 104 if (suppressUpdates) return; 104 105 if (InvokeRequired) 105 this.Invoke( new EventHandler(run_Changed), sender, e);106 this.Invoke((Action<object, PropertyChangedEventArgs>)run_PropertyChanged, sender, e); 106 107 else { 107 108 IRun run = (IRun)sender; 108 UpdateRun(run); 109 if (e.PropertyName == "Color" || e.PropertyName == "Visible") 110 UpdateRun(run); 109 111 } 110 112 } -
trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionView.cs
r11171 r11344 23 23 using System.Collections; 24 24 using System.Collections.Generic; 25 using System.ComponentModel; 25 26 using System.Drawing; 26 27 using System.Linq; … … 79 80 item.ItemImageChanged -= new EventHandler(Item_ItemImageChanged); 80 81 item.ToStringChanged -= new EventHandler(Item_ToStringChanged); 81 item. Changed -= new EventHandler(Item_Changed);82 item.PropertyChanged -= Item_PropertyChanged; 82 83 } 83 84 private void RegisterItemEvents(IRun item) { 84 85 item.ItemImageChanged += new EventHandler(Item_ItemImageChanged); 85 86 item.ToStringChanged += new EventHandler(Item_ToStringChanged); 86 item. Changed += new EventHandler(Item_Changed);87 item.PropertyChanged += Item_PropertyChanged; 87 88 } 88 89 … … 385 386 try { 386 387 RunCollection.Modify(); 387 } 388 finally { 388 } finally { 389 389 ReadOnly = false; 390 390 } … … 462 462 } 463 463 } 464 private void Item_ Changed(object sender,EventArgs e) {464 private void Item_PropertyChanged(object sender, PropertyChangedEventArgs e) { 465 465 if (InvokeRequired) 466 this.Invoke( new EventHandler(Item_Changed), sender, e);466 this.Invoke((Action<object, PropertyChangedEventArgs>)Item_PropertyChanged, sender, e); 467 467 else { 468 468 IRun run = (IRun)sender; 469 UpdateRun(run); 469 if (e.PropertyName == "Color" || e.PropertyName == "Visible") 470 UpdateRun(run); 470 471 } 471 472 } -
trunk/sources/HeuristicLab.Optimization.Views/3.3/RunView.cs
r11171 r11344 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.ComponentModel; 25 using System.Linq; 23 26 using System.Windows.Forms; 27 using HeuristicLab.Collections; 24 28 using HeuristicLab.Common; 25 29 using HeuristicLab.Core; … … 34 38 [Content(typeof(IRun), true)] 35 39 public sealed partial class RunView : NamedItemView { 40 private readonly Dictionary<string, ListViewItem> parametersItemToListViewItem; 41 private readonly Dictionary<string, ListViewItem> resultsItemToListViewItem; 36 42 /// <summary> 37 43 /// Gets or sets the variable to represent visually. … … 49 55 public RunView() { 50 56 InitializeComponent(); 57 parametersItemToListViewItem = new Dictionary<string, ListViewItem>(); 58 resultsItemToListViewItem = new Dictionary<string, ListViewItem>(); 51 59 } 52 60 53 61 protected override void RegisterContentEvents() { 54 62 base.RegisterContentEvents(); 55 Content.Changed += new EventHandler(Content_Changed); 63 Content.PropertyChanged += Content_PropertyChanged; 64 RegisterContentParametersEvents(); 65 RegisterContentResultsEents(); 66 } 67 private void RegisterContentParametersEvents() { 68 Content.Parameters.ItemsAdded += ParametersOnItemsChanged; 69 Content.Parameters.ItemsRemoved += ParametersOnItemsChanged; 70 Content.Parameters.ItemsReplaced += ParametersOnItemsChanged; 71 Content.Parameters.CollectionReset += ParametersOnItemsChanged; 72 } 73 private void RegisterContentResultsEents() { 74 Content.Results.ItemsAdded += ResultsOnItemsChanged; 75 Content.Results.ItemsRemoved += ResultsOnItemsChanged; 76 Content.Results.ItemsReplaced += ResultsOnItemsChanged; 77 Content.Results.CollectionReset += ResultsOnItemsChanged; 56 78 } 57 79 protected override void DeregisterContentEvents() { 58 80 base.DeregisterContentEvents(); 59 Content.Changed -= new EventHandler(Content_Changed); 60 } 61 private void Content_Changed(object sender, EventArgs e) { 62 if (InvokeRequired) 63 this.Invoke(new EventHandler(Content_Changed), sender, e); 64 else 65 UpdateColor(); 81 Content.PropertyChanged -= Content_PropertyChanged; 82 DeregisterContentParametersEvents(); 83 DeregisterContentResultsEvents(); 84 } 85 private void DeregisterContentParametersEvents() { 86 Content.Parameters.ItemsAdded -= ParametersOnItemsChanged; 87 Content.Parameters.ItemsRemoved -= ParametersOnItemsChanged; 88 Content.Parameters.ItemsReplaced -= ParametersOnItemsChanged; 89 Content.Parameters.CollectionReset -= ParametersOnItemsChanged; 90 } 91 private void DeregisterContentResultsEvents() { 92 Content.Results.ItemsAdded -= ResultsOnItemsChanged; 93 Content.Results.ItemsRemoved -= ResultsOnItemsChanged; 94 Content.Results.ItemsReplaced -= ResultsOnItemsChanged; 95 Content.Results.CollectionReset -= ResultsOnItemsChanged; 96 } 97 98 private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) { 99 if (e.PropertyName == "Color") { 100 if (InvokeRequired) this.Invoke((Action)UpdateColor, null); 101 else UpdateColor(); 102 } else if (e.PropertyName == "Parameters") { 103 if (InvokeRequired) this.Invoke((Action<bool>)FillParametersListView, true); 104 else FillParametersListView(); 105 RegisterContentParametersEvents(); 106 } else if (e.PropertyName == "Results") { 107 if (InvokeRequired) this.Invoke((Action<bool>)FillResultsListView, true); 108 else FillResultsListView(); 109 RegisterContentResultsEents(); 110 } 111 } 112 113 private void ParametersOnItemsChanged(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>> e) { 114 foreach (var item in e.OldItems) { 115 listView.Items.Remove(parametersItemToListViewItem[item.Key]); 116 parametersItemToListViewItem.Remove(item.Key); 117 } 118 foreach (var item in e.Items) { 119 var listViewItem = CreateListViewItem(item.Key, Content.Parameters[item.Key], listView.Groups["parametersGroup"]); 120 listView.Items.Add(listViewItem); 121 parametersItemToListViewItem[item.Key] = listViewItem; 122 } 123 } 124 125 private void ResultsOnItemsChanged(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>> e) { 126 foreach (var item in e.OldItems) { 127 listView.Items.Remove(resultsItemToListViewItem[item.Key]); 128 resultsItemToListViewItem.Remove(item.Key); 129 } 130 foreach (var item in e.Items) { 131 var listViewItem = CreateListViewItem(item.Key, Content.Results[item.Key], listView.Groups["resultsGroup"]); 132 listView.Items.Add(listViewItem); 133 resultsItemToListViewItem[item.Key] = listViewItem; 134 } 66 135 } 67 136 … … 101 170 if (listView.SelectedItems.Count == 1) selectedName = listView.SelectedItems[0].SubItems[0].Text; 102 171 103 listView.Items.Clear(); 104 listView.SmallImageList.Images.Clear(); 172 FillParametersListView(false); 173 FillResultsListView(false); 174 if (listView.Items.Count > 0) { 175 for (int i = 0; i < listView.Columns.Count; i++) 176 listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); 177 selectedName = null; 178 } 179 } 180 181 private void FillParametersListView(bool resize = true) { 182 listView.BeginUpdate(); 183 foreach (var item in listView.Groups["parametersGroup"].Items.OfType<ListViewItem>().OrderByDescending(x => x.ImageIndex).ToList()) { 184 listView.SmallImageList.Images.RemoveAt(item.ImageIndex); 185 listView.Items.Remove(item); 186 } 187 parametersItemToListViewItem.Clear(); 188 189 var counter = 0; 190 foreach (var item in listView.Items.OfType<ListViewItem>().OrderBy(x => x.ImageIndex).ToList()) 191 item.ImageIndex = counter++; 192 listView.EndUpdate(); 193 105 194 if (Content != null) { 106 foreach (string key in Content.Parameters.Keys) 107 CreateListViewItem(key, Content.Parameters[key], listView.Groups["parametersGroup"], selectedName); 108 foreach (string key in Content.Results.Keys) 109 CreateListViewItem(key, Content.Results[key], listView.Groups["resultsGroup"], selectedName); 110 if (listView.Items.Count > 0) { 195 foreach (string key in Content.Parameters.Keys) { 196 var listViewItem = CreateListViewItem(key, Content.Parameters[key], listView.Groups["parametersGroup"]); 197 listView.Items.Add(listViewItem); 198 if ((selectedName != null) && key.Equals(selectedName)) listViewItem.Selected = true; 199 parametersItemToListViewItem[key] = listViewItem; 200 } 201 if (resize && listView.Items.Count > 0) { 111 202 for (int i = 0; i < listView.Columns.Count; i++) 112 203 listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); 113 selectedName = null; 114 } 115 } 116 } 117 118 private void CreateListViewItem(string name, IItem value, ListViewGroup group, string selectedName) { 119 ListViewItem item = new ListViewItem(new string[] { name, value != null ? value.ToString() : "-" }); 204 } 205 } 206 } 207 208 private void FillResultsListView(bool resize = true) { 209 listView.BeginUpdate(); 210 foreach (var item in listView.Groups["resultsGroup"].Items.OfType<ListViewItem>().OrderByDescending(x => x.ImageIndex).ToList()) { 211 listView.SmallImageList.Images.RemoveAt(item.ImageIndex); 212 listView.Items.Remove(item); 213 } 214 resultsItemToListViewItem.Clear(); 215 216 var counter = 0; 217 foreach (var item in listView.Items.OfType<ListViewItem>().OrderBy(x => x.ImageIndex).ToList()) 218 item.ImageIndex = counter++; 219 listView.EndUpdate(); 220 221 if (Content != null) { 222 foreach (string key in Content.Results.Keys) { 223 var listViewItem = CreateListViewItem(key, Content.Results[key], listView.Groups["resultsGroup"]); 224 listView.Items.Add(listViewItem); 225 if ((selectedName != null) && key.Equals(selectedName)) listViewItem.Selected = true; 226 resultsItemToListViewItem[key] = listViewItem; 227 } 228 if (resize && listView.Items.Count > 0) { 229 for (int i = 0; i < listView.Columns.Count; i++) 230 listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); 231 } 232 } 233 } 234 235 private ListViewItem CreateListViewItem(string name, IItem value, ListViewGroup group) { 236 var item = new ListViewItem(new string[] { name, value != null ? value.ToString() : "-" }); 120 237 item.Tag = value; 121 238 item.Group = group; 122 239 listView.SmallImageList.Images.Add(value == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : value.ItemImage); 123 240 item.ImageIndex = listView.SmallImageList.Images.Count - 1; 124 listView.Items.Add(item); 125 if ((selectedName != null) && name.Equals(selectedName)) item.Selected = true; 241 return item; 126 242 } 127 243 -
trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/IRun.cs
r11171 r11344 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 22 using System.ComponentModel; 24 23 using System.Drawing; 24 using HeuristicLab.Collections; 25 25 using HeuristicLab.Core; 26 26 … … 29 29 /// Represents the parameters and results of an algorithm run. 30 30 /// </summary> 31 public interface IRun : INamedItem {31 public interface IRun : INamedItem, INotifyPropertyChanged { 32 32 IAlgorithm Algorithm { get; } 33 I Dictionary<string, IItem> Parameters { get; }34 I Dictionary<string, IItem> Results { get; }33 IObservableDictionary<string, IItem> Parameters { get; } 34 IObservableDictionary<string, IItem> Results { get; } 35 35 36 36 Color Color { get; set; } 37 37 bool Visible { get; set; } 38 event EventHandler Changed;39 38 } 40 39 } -
trunk/sources/HeuristicLab.Optimization/3.3/Run.cs
r11171 r11344 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.ComponentModel; 24 25 using System.Drawing; 25 using System.Linq;26 using HeuristicLab.Collections; 26 27 using HeuristicLab.Common; 27 28 using HeuristicLab.Core; … … 44 45 algorithm = cloner.Clone(original.algorithm); 45 46 46 parameters = new Dictionary<string, IItem>();47 parameters = new ObservableDictionary<string, IItem>(); 47 48 foreach (string key in original.parameters.Keys) 48 49 parameters.Add(key, cloner.Clone(original.parameters[key])); 49 50 50 results = new Dictionary<string, IItem>();51 results = new ObservableDictionary<string, IItem>(); 51 52 foreach (string key in original.results.Keys) 52 53 results.Add(key, cloner.Clone(original.results[key])); 53 54 } 55 54 56 public override IDeepCloneable Clone(Cloner cloner) { 55 57 return new Run(this, cloner); … … 62 64 color = Color.Black; 63 65 algorithm = null; 64 parameters = new Dictionary<string, IItem>();65 results = new Dictionary<string, IItem>();66 parameters = new ObservableDictionary<string, IItem>(); 67 results = new ObservableDictionary<string, IItem>(); 66 68 } 67 69 public Run(IAlgorithm algorithm) … … 88 90 89 91 private void Initialize(IAlgorithm algorithm) { 90 parameters = new Dictionary<string, IItem>();91 results = new Dictionary<string, IItem>();92 parameters = new ObservableDictionary<string, IItem>(); 93 results = new ObservableDictionary<string, IItem>(); 92 94 93 95 if (algorithm.StoreAlgorithmInEachRun) { 94 IAlgorithmclone = (IAlgorithm)algorithm.Clone();96 var clone = (IAlgorithm)algorithm.Clone(); 95 97 clone.CollectParameterValues(parameters); 96 98 clone.CollectResultValues(results); … … 98 100 this.algorithm = clone; 99 101 } else { 100 algorithm.CollectParameterValues(parameters); 101 algorithm.CollectResultValues(results); 102 Cloner cloner = new Cloner(); 103 parameters = parameters.Select(x => new KeyValuePair<string, IItem>(x.Key, cloner.Clone(x.Value))).ToDictionary(x => x.Key, x => x.Value); 104 results = results.Select(x => new KeyValuePair<string, IItem>(x.Key, cloner.Clone(x.Value))).ToDictionary(x => x.Key, x => x.Value); 102 var par = new Dictionary<string, IItem>(); 103 var res = new Dictionary<string, IItem>(); 104 algorithm.CollectParameterValues(par); 105 algorithm.CollectResultValues(res); 106 var cloner = new Cloner(); 107 foreach (var k in par) parameters.Add(k.Key, cloner.Clone(k.Value)); 108 foreach (var k in res) results.Add(k.Key, cloner.Clone(k.Value)); 105 109 } 106 110 } … … 115 119 get { return algorithm; } 116 120 } 117 [Storable] 118 private Dictionary<string, IItem> parameters;119 p ublic IDictionary<string, IItem>Parameters {121 122 [Storable(Name = "parameters")] 123 private IDictionary<string, IItem> StorableParameters { 120 124 get { return parameters; } 125 set { 126 if (!(value is IObservableDictionary<string, IItem>)) 127 parameters = new ObservableDictionary<string, IItem>(value); 128 else parameters = (IObservableDictionary<string, IItem>)value; 129 } 121 130 } 122 [Storable] 123 private Dictionary<string, IItem> results; 124 public IDictionary<string, IItem> Results { 131 private IObservableDictionary<string, IItem> parameters; 132 public IObservableDictionary<string, IItem> Parameters { 133 get { return parameters; } 134 private set { 135 if (parameters != value) { 136 parameters = value; 137 OnPropertyChanged("Parameters"); 138 } 139 } 140 } 141 142 [Storable(Name = "results")] 143 private IDictionary<string, IItem> StorableResults { 125 144 get { return results; } 145 set { 146 if (!(value is IObservableDictionary<string, IItem>)) 147 results = new ObservableDictionary<string, IItem>(value); 148 else results = (IObservableDictionary<string, IItem>)value; 149 } 150 } 151 private IObservableDictionary<string, IItem> results; 152 public IObservableDictionary<string, IItem> Results { 153 get { return results; } 154 set { 155 if (results != value) { 156 results = value; 157 OnPropertyChanged("Results"); 158 } 159 } 126 160 } 127 161 … … 133 167 if (color != value) { 134 168 this.color = value; 135 this.OnChanged();169 OnPropertyChanged("Color"); 136 170 } 137 171 } … … 143 177 if (visible != value) { 144 178 this.visible = value; 145 this.OnChanged();179 OnPropertyChanged("Visible"); 146 180 } 147 181 } 148 182 } 149 public event EventHandler Changed; 150 p rivate void OnChanged() {151 EventHandler handler = Changed;152 if (handler != null)153 handler(this, EventArgs.Empty);183 184 public event PropertyChangedEventHandler PropertyChanged; 185 private void OnPropertyChanged(string property) { 186 var handler = PropertyChanged; 187 if (handler != null) handler(this, new PropertyChangedEventArgs(property)); 154 188 } 155 189 } -
trunk/sources/HeuristicLab.Optimization/3.3/RunCollection.cs
r11171 r11344 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.ComponentModel; 24 25 using System.Linq; 25 26 using HeuristicLab.Collections; … … 160 161 foreach (KeyValuePair<string, IItem> result in run.Results) 161 162 AddResult(result.Key, result.Value); 163 run.PropertyChanged += RunOnPropertyChanged; 164 RegisterRunParametersEvents(run); 165 RegisterRunResultsEvents(run); 166 } 167 foreach (IRun run in oldItems) { 168 run.PropertyChanged -= RunOnPropertyChanged; 169 DeregisterRunParametersEvents(run); 170 DeregisterRunResultsEvents(run); 162 171 } 163 172 columnNameCache = null; … … 178 187 foreach (KeyValuePair<string, IItem> result in run.Results) 179 188 columnsChanged |= AddResult(result.Key, result.Value); 189 run.PropertyChanged += RunOnPropertyChanged; 190 RegisterRunParametersEvents(run); 191 RegisterRunResultsEvents(run); 180 192 } 181 193 if (columnsChanged) columnNameCache = null; … … 198 210 foreach (string resultName in run.Results.Keys) 199 211 columnsChanged |= RemoveResultName(resultName); 212 run.PropertyChanged -= RunOnPropertyChanged; 213 DeregisterRunParametersEvents(run); 214 DeregisterRunResultsEvents(run); 200 215 } 201 216 if (columnsChanged) columnNameCache = null; … … 205 220 OnRowsChanged(); 206 221 OnRowNamesChanged(); 222 if (columnsChanged) { 223 OnColumnsChanged(); 224 OnColumnNamesChanged(); 225 } 226 } 227 228 private void RunOnPropertyChanged(object sender, PropertyChangedEventArgs e) { 229 if (e.PropertyName == "Parameters") { 230 RegisterRunParametersEvents((IRun)sender); 231 } else if (e.PropertyName == "Results") { 232 RegisterRunResultsEvents((IRun)sender); 233 } 234 } 235 236 private void RegisterRunParametersEvents(IRun run) { 237 IObservableDictionary<string, IItem> dict = run.Parameters; 238 dict.ItemsAdded += RunOnParameterChanged; 239 dict.ItemsRemoved += RunOnParameterChanged; 240 dict.ItemsReplaced += RunOnParameterChanged; 241 dict.CollectionReset += RunOnParameterChanged; 242 } 243 244 private void RegisterRunResultsEvents(IRun run) { 245 IObservableDictionary<string, IItem> dict = run.Results; 246 dict.ItemsAdded += RunOnResultChanged; 247 dict.ItemsRemoved += RunOnResultChanged; 248 dict.ItemsReplaced += RunOnResultChanged; 249 dict.CollectionReset += RunOnResultChanged; 250 } 251 252 private void DeregisterRunParametersEvents(IRun run) { 253 IObservableDictionary<string, IItem> dict = run.Parameters; 254 dict.ItemsAdded -= RunOnParameterChanged; 255 dict.ItemsRemoved -= RunOnParameterChanged; 256 dict.ItemsReplaced -= RunOnParameterChanged; 257 dict.CollectionReset -= RunOnParameterChanged; 258 } 259 260 private void DeregisterRunResultsEvents(IRun run) { 261 IObservableDictionary<string, IItem> dict = run.Results; 262 dict.ItemsAdded -= RunOnResultChanged; 263 dict.ItemsRemoved -= RunOnResultChanged; 264 dict.ItemsReplaced -= RunOnResultChanged; 265 dict.CollectionReset -= RunOnResultChanged; 266 } 267 268 private void RunOnParameterChanged(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>> e) { 269 bool columnsChanged = false; 270 foreach (var param in e.Items) 271 columnsChanged |= AddParameter(param.Key, param.Value); 272 foreach (var param in e.OldItems) 273 columnsChanged |= RemoveParameterName(param.Key); 274 if (columnsChanged) columnNameCache = null; 275 OnReset(); 276 if (columnsChanged) { 277 OnColumnsChanged(); 278 OnColumnNamesChanged(); 279 } 280 } 281 282 private void RunOnResultChanged(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>> e) { 283 bool columnsChanged = false; 284 foreach (var result in e.Items) 285 columnsChanged |= AddResult(result.Key, result.Value); 286 foreach (var result in e.OldItems) 287 columnsChanged |= RemoveResultName(result.Key); 288 if (columnsChanged) columnNameCache = null; 289 OnReset(); 207 290 if (columnsChanged) { 208 291 OnColumnsChanged(); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/RunCollectionVariableImpactView.cs
r11171 r11344 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.ComponentModel; 24 25 using System.Drawing; 25 26 using System.Linq; … … 66 67 private void RegisterRunEvents(IEnumerable<IRun> runs) { 67 68 foreach (IRun run in runs) 68 run. Changed += Run_Changed;69 run.PropertyChanged += Run_PropertyChanged; 69 70 } 70 71 private void DeregisterRunEvents(IEnumerable<IRun> runs) { 71 72 foreach (IRun run in runs) 72 run. Changed -= Run_Changed;73 run.PropertyChanged -= Run_PropertyChanged; 73 74 } 74 75 private void Content_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) { … … 88 89 if (!Content.UpdateOfRunsInProgress) UpdateData(); 89 90 } 90 private void Run_Changed(object sender, EventArgs e) { 91 if (!Content.UpdateOfRunsInProgress) UpdateData(); 91 private void Run_PropertyChanged(object sender, PropertyChangedEventArgs e) { 92 if (!Content.UpdateOfRunsInProgress && e.PropertyName == "Visible") 93 UpdateData(); 92 94 } 93 95 #endregion
Note: See TracChangeset
for help on using the changeset viewer.