Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching.Views/3.3/RunCollectionModifierExecutableView.cs @ 10301

Last change on this file since 10301 was 10128, checked in by ascheibe, 11 years ago

#1886 cleaned up Hive RunCollection Modifier Task classes

File size: 7.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Windows.Forms;
24using HeuristicLab.Analysis.SolutionCaching;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Core.Views;
28using HeuristicLab.MainForm;
29using HeuristicLab.PluginInfrastructure;
30
31namespace HeuristicLab.Optimization.Views {
32  [View("RunCollectionModifierExecutable View")]
33  [Content(typeof(RunCollectionModifierExecutable), true)]
34  public partial class RunCollectionModifierExecutableView : ParameterizedNamedItemView {
35    public RunCollectionModifierExecutableView() {
36      InitializeComponent();
37    }
38
39    public new RunCollectionModifierExecutable Content {
40      get { return (RunCollectionModifierExecutable)base.Content; }
41      set { base.Content = value; }
42    }
43
44    protected override void DeregisterContentEvents() {
45      Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
46      Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);
47      Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
48      Content.Prepared -= new EventHandler(Content_Prepared);
49      Content.Started -= new EventHandler(Content_Started);
50      Content.Paused -= new EventHandler(Content_Paused);
51      Content.Stopped -= new EventHandler(Content_Stopped);
52      base.DeregisterContentEvents();
53    }
54    protected override void RegisterContentEvents() {
55      base.RegisterContentEvents();
56      Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
57      Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
58      Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
59      Content.Prepared += new EventHandler(Content_Prepared);
60      Content.Started += new EventHandler(Content_Started);
61      Content.Paused += new EventHandler(Content_Paused);
62      Content.Stopped += new EventHandler(Content_Stopped);
63    }
64
65    protected override void OnContentChanged() {
66      base.OnContentChanged();
67      if (Content == null) {
68        executionTimeTextBox.Text = "-";
69      } else {
70        Locked = ReadOnly = Content.ExecutionState == ExecutionState.Started;
71        parameterCollectionView.Locked = Content.ExecutionState == ExecutionState.Started;
72        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
73      }
74    }
75
76    protected override void SetEnabledStateOfControls() {
77      base.SetEnabledStateOfControls();
78      executionTimeTextBox.Enabled = Content != null;
79      SetEnabledStateOfExecutableButtons();
80    }
81
82    #region Content Events
83    protected virtual void Content_ExecutionStateChanged(object sender, EventArgs e) {
84      if (InvokeRequired)
85        Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
86      else
87        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
88    }
89    protected virtual void Content_Prepared(object sender, EventArgs e) {
90      if (InvokeRequired)
91        Invoke(new EventHandler(Content_Prepared), sender, e);
92      else {
93        nameTextBox.Enabled = infoLabel.Enabled = true;
94        ReadOnly = Locked = false;
95        parameterCollectionView.Locked = false;
96        SetEnabledStateOfExecutableButtons();
97      }
98    }
99    protected virtual void Content_Started(object sender, EventArgs e) {
100      if (InvokeRequired)
101        Invoke(new EventHandler(Content_Started), sender, e);
102      else {
103        nameTextBox.Enabled = infoLabel.Enabled = false;
104        ReadOnly = Locked = true;
105        parameterCollectionView.Locked = true;
106        SetEnabledStateOfExecutableButtons();
107        Content.Progress = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>()
108             .AddOperationProgressToContent(Content, "Running modifiers...");
109      }
110    }
111    protected virtual void Content_Paused(object sender, EventArgs e) {
112      if (InvokeRequired)
113        Invoke(new EventHandler(Content_Paused), sender, e);
114      else {
115        MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromContent(Content, false);
116        nameTextBox.Enabled = infoLabel.Enabled = true;
117        ReadOnly = Locked = false;
118        parameterCollectionView.Locked = false;
119        SetEnabledStateOfExecutableButtons();
120      }
121    }
122    protected virtual void Content_Stopped(object sender, EventArgs e) {
123      if (InvokeRequired)
124        Invoke(new EventHandler(Content_Stopped), sender, e);
125      else {
126        MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromContent(Content, false);
127        nameTextBox.Enabled = infoLabel.Enabled = true;
128        ReadOnly = Locked = false;
129        parameterCollectionView.Locked = false;
130        SetEnabledStateOfExecutableButtons();
131      }
132    }
133    protected virtual void Content_ExecutionTimeChanged(object sender, EventArgs e) {
134      if (InvokeRequired)
135        Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
136      else
137        executionTimeTextBox.Text = Content == null ? "-" : Content.ExecutionTime.ToString();
138    }
139    protected virtual void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {
140      if (InvokeRequired)
141        Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e);
142      else {
143        ErrorHandling.ShowErrorDialog(this, e.Value);
144      }
145    }
146    #endregion
147
148    #region Control events
149    protected virtual void startButton_Click(object sender, EventArgs e) {
150      Content.Start();
151    }
152    protected virtual void pauseButton_Click(object sender, EventArgs e) {
153      Content.Pause();
154    }
155    protected virtual void stopButton_Click(object sender, EventArgs e) {
156      Content.Stop();
157    }
158    protected virtual void resetButton_Click(object sender, EventArgs e) {
159      Content.Prepare();
160    }
161    #endregion
162
163    #region Helpers
164    protected virtual void SetEnabledStateOfExecutableButtons() {
165      if (Content == null) {
166        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
167      } else {
168        startButton.Enabled = (Content.ExecutionState == ExecutionState.Prepared) || (Content.ExecutionState == ExecutionState.Paused);
169        pauseButton.Enabled = Content.ExecutionState == ExecutionState.Started;
170        stopButton.Enabled = (Content.ExecutionState == ExecutionState.Started) || (Content.ExecutionState == ExecutionState.Paused);
171        resetButton.Enabled = Content.ExecutionState != ExecutionState.Started;
172      }
173    }
174    #endregion
175  }
176}
Note: See TracBrowser for help on using the repository browser.