Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core.Views/3.3/EngineView.cs @ 3455

Last change on this file since 3455 was 3455, checked in by swagner, 14 years ago

Removed manual propagation of ReadOnly property (#973)

File size: 3.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 HeuristicLab.MainForm;
24
25namespace HeuristicLab.Core.Views {
26  /// <summary>
27  /// Base class for editors of engines.
28  /// </summary>
29  [View("Engine View")]
30  [Content(typeof(Engine), true)]
31  [Content(typeof(IEngine), false)]
32  public partial class EngineView : ItemView {
33    /// <summary>
34    /// Gets or sets the current engine.
35    /// </summary>
36    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="EditorBase"/>.</remarks>
37    public new IEngine Content {
38      get { return (IEngine)base.Content; }
39      set { base.Content = value; }
40    }
41
42    /// <summary>
43    /// Initializes a new instance of <see cref="EngineBaseEditor"/>.
44    /// </summary>
45    public EngineView() {
46      InitializeComponent();
47    }
48    public EngineView(IEngine content)
49      : this() {
50      Content = content;
51    }
52
53    /// <summary>
54    /// Removes the event handlers from the underlying <see cref="IEngine"/>.
55    /// </summary>
56    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
57    protected override void DeregisterContentEvents() {
58      Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
59      base.DeregisterContentEvents();
60    }
61
62    /// <summary>
63    /// Adds event handlers to the underlying <see cref="IEngine"/>.
64    /// </summary>
65    /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
66    protected override void RegisterContentEvents() {
67      base.RegisterContentEvents();
68      Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
69    }
70
71    /// <summary>
72    /// Updates all controls with the latest data of the model.
73    /// </summary>
74    /// <remarks>Calls <see cref="EditorBase.UpdateControls"/> of base class <see cref="EditorBase"/>.</remarks>
75    protected override void OnContentChanged() {
76      base.OnContentChanged();
77      if (Content == null) {
78        logView.Content = null;
79        executionTimeTextBox.Text = "-";
80      } else {
81        logView.Content = Content.Log;
82        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
83      }
84      SetEnabledStateOfControls();
85    }
86
87    protected override void OnReadOnlyChanged() {
88      base.OnReadOnlyChanged();
89      SetEnabledStateOfControls();
90    }
91
92    private void SetEnabledStateOfControls() {
93      if (Content == null) {
94        logView.Enabled = false;
95        executionTimeTextBox.Enabled = false;
96      } else {
97        logView.Enabled = true;
98        executionTimeTextBox.Enabled = true;
99      }
100    }
101
102    protected virtual void Content_ExecutionTimeChanged(object sender, EventArgs e) {
103      if (InvokeRequired)
104        Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
105      else
106        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
107    }
108  }
109}
Note: See TracBrowser for help on using the repository browser.