- Timestamp:
- 06/16/11 10:56:26 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization.Views/3.3/ExperimentView.cs
r5832 r6425 20 20 #endregion 21 21 22 using System;23 22 using System.Linq; 24 23 using System.Windows.Forms; 25 using HeuristicLab.Common;26 24 using HeuristicLab.Core; 27 using HeuristicLab.Core.Views;28 25 using HeuristicLab.MainForm; 29 using HeuristicLab.PluginInfrastructure;30 26 31 27 namespace HeuristicLab.Optimization.Views { 32 /// <summary>33 /// The base class for visual representations of items.34 /// </summary>35 28 [View("Experiment View")] 36 29 [Content(typeof(Experiment), true)] 37 public sealed partial class ExperimentView : NamedItemView { 38 public new Experiment Content { 39 get { return (Experiment)base.Content; } 40 set { base.Content = value; } 41 } 42 43 /// <summary> 44 /// Initializes a new instance of <see cref="ItemBaseView"/>. 45 /// </summary> 30 public sealed partial class ExperimentView : IOptimizerView { 46 31 public ExperimentView() { 47 32 InitializeComponent(); 48 33 } 49 34 50 protected override void DeregisterContentEvents() { 51 Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred); 52 Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged); 53 Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged); 54 Content.Prepared -= new EventHandler(Content_Prepared); 55 Content.Started -= new EventHandler(Content_Started); 56 Content.Paused -= new EventHandler(Content_Paused); 57 Content.Stopped -= new EventHandler(Content_Stopped); 58 base.DeregisterContentEvents(); 59 } 60 protected override void RegisterContentEvents() { 61 base.RegisterContentEvents(); 62 Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred); 63 Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged); 64 Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged); 65 Content.Prepared += new EventHandler(Content_Prepared); 66 Content.Started += new EventHandler(Content_Started); 67 Content.Paused += new EventHandler(Content_Paused); 68 Content.Stopped += new EventHandler(Content_Stopped); 35 public new Experiment Content { 36 get { return (Experiment)base.Content; } 37 set { base.Content = value; } 69 38 } 70 39 … … 74 43 optimizerListView.Content = null; 75 44 runsViewHost.Content = null; 76 executionTimeTextBox.Text = "-";77 45 } else { 78 Locked = ReadOnly = Content.ExecutionState == ExecutionState.Started;79 46 optimizerListView.Content = Content.Optimizers; 80 47 runsViewHost.Content = Content.Runs; 81 executionTimeTextBox.Text = Content.ExecutionTime.ToString();82 48 } 83 49 } … … 87 53 optimizerListView.Enabled = Content != null; 88 54 runsViewHost.Enabled = Content != null; 89 executionTimeTextBox.Enabled = Content != null;90 SetEnabledStateOfExecutableButtons();91 55 } 92 56 … … 102 66 base.OnClosed(e); 103 67 } 104 105 #region Content Events106 private void Content_ExecutionStateChanged(object sender, EventArgs e) {107 if (InvokeRequired)108 Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);109 else110 startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;111 }112 private void Content_Prepared(object sender, EventArgs e) {113 if (InvokeRequired)114 Invoke(new EventHandler(Content_Prepared), sender, e);115 else {116 nameTextBox.Enabled = infoLabel.Enabled = true;117 ReadOnly = Locked = false;118 SetEnabledStateOfExecutableButtons();119 }120 }121 private void Content_Started(object sender, EventArgs e) {122 if (InvokeRequired)123 Invoke(new EventHandler(Content_Started), sender, e);124 else {125 nameTextBox.Enabled = infoLabel.Enabled = false;126 ReadOnly = Locked = true;127 SetEnabledStateOfExecutableButtons();128 }129 }130 private void Content_Paused(object sender, EventArgs e) {131 if (InvokeRequired)132 Invoke(new EventHandler(Content_Paused), sender, e);133 else {134 nameTextBox.Enabled = infoLabel.Enabled = true;135 ReadOnly = Locked = false;136 SetEnabledStateOfExecutableButtons();137 }138 }139 private void Content_Stopped(object sender, EventArgs e) {140 if (InvokeRequired)141 Invoke(new EventHandler(Content_Stopped), sender, e);142 else {143 nameTextBox.Enabled = infoLabel.Enabled = true;144 ReadOnly = Locked = false;145 SetEnabledStateOfExecutableButtons();146 }147 }148 private void Content_ExecutionTimeChanged(object sender, EventArgs e) {149 if (InvokeRequired)150 Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);151 else152 executionTimeTextBox.Text = Content == null ? "-" : Content.ExecutionTime.ToString();153 }154 private void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {155 if (InvokeRequired)156 Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e);157 else158 ErrorHandling.ShowErrorDialog(this, e.Value);159 }160 #endregion161 162 #region Control events163 private void startButton_Click(object sender, EventArgs e) {164 Content.Start();165 }166 private void pauseButton_Click(object sender, EventArgs e) {167 Content.Pause();168 }169 private void stopButton_Click(object sender, EventArgs e) {170 Content.Stop();171 }172 private void resetButton_Click(object sender, EventArgs e) {173 Content.Prepare(false);174 }175 #endregion176 177 #region Helpers178 private void SetEnabledStateOfExecutableButtons() {179 if (Content == null) {180 startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;181 } else {182 startButton.Enabled = (Content.ExecutionState == ExecutionState.Prepared) || (Content.ExecutionState == ExecutionState.Paused);183 pauseButton.Enabled = Content.ExecutionState == ExecutionState.Started;184 stopButton.Enabled = (Content.ExecutionState == ExecutionState.Started) || (Content.ExecutionState == ExecutionState.Paused);185 resetButton.Enabled = Content.ExecutionState != ExecutionState.Started;186 }187 }188 #endregion189 68 } 190 69 }
Note: See TracChangeset
for help on using the changeset viewer.