Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.ExternalEvaluation.Views/3.3/EvaluationProcessChannelView.cs @ 4117

Last change on this file since 4117 was 4117, checked in by abeham, 14 years ago

#1041

  • Added views plugin for variable symbol to set the variable names
  • Beautified interface in the channel views (images in buttons)
  • fixed a bug in the tree interpreter regarding missing variables
  • Added missing frame file for ExternalEvaluation.Views plugin
  • Fixed build of ProtoGen in the solution file
File size: 4.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.Core.Views;
25using HeuristicLab.MainForm;
26using HeuristicLab.Common.Resources;
27
28namespace HeuristicLab.Problems.ExternalEvaluation.Views {
29  [View("Process-Channel View")]
30  [Content(typeof(EvaluationProcessChannel), IsDefaultView = true)]
31  public sealed partial class EvaluationProcessChannelView : NamedItemView {
32    public new EvaluationProcessChannel Content {
33      get { return (EvaluationProcessChannel)base.Content; }
34      set { base.Content = value; }
35    }
36
37    public EvaluationProcessChannelView() {
38      InitializeComponent();
39    }
40
41    protected override void DeregisterContentEvents() {
42      Content.ExecutableChanged -= new EventHandler(Content_ExecutableChanged);
43      Content.ArgumentsChanged -= new EventHandler(Content_ArgumentsChanged);
44      Content.ProcessStarted -= new EventHandler(Content_ProcessStarted);
45      Content.ProcessExited -= new EventHandler(Content_ProcessExited);
46      base.DeregisterContentEvents();
47    }
48
49    protected override void RegisterContentEvents() {
50      base.RegisterContentEvents();
51      Content.ExecutableChanged += new EventHandler(Content_ExecutableChanged);
52      Content.ArgumentsChanged += new EventHandler(Content_ArgumentsChanged);
53      Content.ProcessStarted += new EventHandler(Content_ProcessStarted);
54      Content.ProcessExited += new EventHandler(Content_ProcessExited);
55    }
56
57    #region Event Handlers (Content)
58    private void Content_ExecutableChanged(object sender, EventArgs e) {
59      executableTextBox.Text = Content.Executable;
60    }
61    private void Content_ArgumentsChanged(object sender, EventArgs e) {
62      argumentsTextBox.Text = Content.Arguments;
63    }
64    private void Content_ProcessStarted(object sender, EventArgs e) {
65      if (InvokeRequired) Invoke(new Action<object, EventArgs>(Content_ProcessStarted), sender, e);
66      else SetEnabledStateOfControls();
67    }
68    private void Content_ProcessExited(object sender, EventArgs e) {
69      if (InvokeRequired) Invoke(new Action<object, EventArgs>(Content_ProcessExited), sender, e);
70      else SetEnabledStateOfControls();
71    }
72    #endregion
73
74    protected override void OnContentChanged() {
75      base.OnContentChanged();
76      if (Content == null) {
77        executableTextBox.Text = String.Empty;
78        argumentsTextBox.Text = String.Empty;
79      } else {
80        executableTextBox.Text = Content.Executable;
81        argumentsTextBox.Text = Content.Arguments;
82      }
83    }
84
85    protected override void SetEnabledStateOfControls() {
86      base.SetEnabledStateOfControls();
87      bool readOnlyDriverNullOrStarted = ReadOnly || Content == null || Content.IsInitialized;
88      browseExecutableButton.Enabled = !readOnlyDriverNullOrStarted;
89      startButton.Enabled = !readOnlyDriverNullOrStarted;
90      terminateButton.Enabled = !ReadOnly && Content != null && Content.IsInitialized;
91      executableTextBox.Enabled = !readOnlyDriverNullOrStarted;
92      argumentsTextBox.Enabled = !readOnlyDriverNullOrStarted;
93    }
94
95    #region Event Handlers (child controls)
96    private void browseExecutableButton_Click(object sender, EventArgs e) {
97      if (openFileDialog.ShowDialog() == DialogResult.OK) {
98        try {
99          Content.Executable = openFileDialog.FileName;
100        } catch (InvalidOperationException ex) {
101          MessageBox.Show(ex.Message);
102        }
103      }
104    }
105    private void argumentsTextBox_Validated(object sender, EventArgs e) {
106      if (Content != null) {
107        Content.Arguments = argumentsTextBox.Text;
108      }
109    }
110    #endregion
111
112    private void startButton_Click(object sender, EventArgs e) {
113      try {
114        Content.Open();
115      } catch (InvalidOperationException ex) {
116        MessageBox.Show(ex.Message);
117      }
118    }
119
120    private void terminateButton_Click(object sender, EventArgs e) {
121      try {
122        Content.Close();
123      } catch (InvalidOperationException ex) {
124        MessageBox.Show(ex.Message);
125      }
126    }
127  }
128}
Note: See TracBrowser for help on using the repository browser.