Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1886 improved RunCollectionModifierExecutable and added a new view for it

File size: 7.2 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        nameTextBox.Enabled = infoLabel.Enabled = true;
116        ReadOnly = Locked = false;
117        parameterCollectionView.Locked = false;
118        SetEnabledStateOfExecutableButtons();
119      }
120    }
121    protected virtual void Content_Stopped(object sender, EventArgs e) {
122      if (InvokeRequired)
123        Invoke(new EventHandler(Content_Stopped), sender, e);
124      else {
125        nameTextBox.Enabled = infoLabel.Enabled = true;
126        ReadOnly = Locked = false;
127        parameterCollectionView.Locked = false;
128        SetEnabledStateOfExecutableButtons();
129      }
130    }
131    protected virtual void Content_ExecutionTimeChanged(object sender, EventArgs e) {
132      if (InvokeRequired)
133        Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
134      else
135        executionTimeTextBox.Text = Content == null ? "-" : Content.ExecutionTime.ToString();
136    }
137    protected virtual void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {
138      if (InvokeRequired)
139        Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e);
140      else
141        ErrorHandling.ShowErrorDialog(this, e.Value);
142    }
143    #endregion
144
145    #region Control events
146    protected virtual void startButton_Click(object sender, EventArgs e) {
147      Content.Start();
148    }
149    protected virtual void pauseButton_Click(object sender, EventArgs e) {
150      Content.Pause();
151    }
152    protected virtual void stopButton_Click(object sender, EventArgs e) {
153      Content.Stop();
154    }
155    protected virtual void resetButton_Click(object sender, EventArgs e) {
156      Content.Prepare();
157    }
158    #endregion
159
160    #region Helpers
161    protected virtual void SetEnabledStateOfExecutableButtons() {
162      if (Content == null) {
163        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
164      } else {
165        startButton.Enabled = (Content.ExecutionState == ExecutionState.Prepared) || (Content.ExecutionState == ExecutionState.Paused);
166        pauseButton.Enabled = Content.ExecutionState == ExecutionState.Started;
167        stopButton.Enabled = (Content.ExecutionState == ExecutionState.Started) || (Content.ExecutionState == ExecutionState.Paused);
168        resetButton.Enabled = Content.ExecutionState != ExecutionState.Started;
169      }
170    }
171    #endregion
172  }
173}
Note: See TracBrowser for help on using the repository browser.