Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HLScript/HeuristicLab.Parameters.Views/3.3/ScopeTreeLookupParameterView.cs @ 10980

Last change on this file since 10980 was 9456, checked in by swagner, 11 years ago

Updated copyright year and added some missing license headers (#1889)

File size: 5.1 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.Core;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27
28namespace HeuristicLab.Parameters.Views {
29  /// <summary>
30  /// The visual representation of a <see cref="Parameter"/>.
31  /// </summary>
32  [View("ScopeTreeLookupParameter View")]
33  [Content(typeof(ScopeTreeLookupParameter<>), true)]
34  public partial class ScopeTreeLookupParameterView<T> : ParameterView where T : class, IItem {
35    /// <summary>
36    /// Gets or sets the variable to represent visually.
37    /// </summary>
38    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
39    /// No own data storage present.</remarks>
40    public new ScopeTreeLookupParameter<T> Content {
41      get { return (ScopeTreeLookupParameter<T>)base.Content; }
42      set { base.Content = value; }
43    }
44
45    /// <summary>
46    /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".
47    /// </summary>
48    public ScopeTreeLookupParameterView() {
49      InitializeComponent();
50    }
51
52    /// <summary>
53    /// Removes the eventhandlers from the underlying <see cref="IVariable"/>.
54    /// </summary>
55    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
56    protected override void DeregisterContentEvents() {
57      Content.ActualNameChanged -= new EventHandler(Content_ActualNameChanged);
58      Content.DepthChanged -= new EventHandler(Content_DepthChanged);
59      base.DeregisterContentEvents();
60    }
61
62    /// <summary>
63    /// Adds eventhandlers to the underlying <see cref="IVariable"/>.
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.ActualNameChanged += new EventHandler(Content_ActualNameChanged);
69      Content.DepthChanged += new EventHandler(Content_DepthChanged);
70    }
71
72    protected override void OnContentChanged() {
73      base.OnContentChanged();
74      if (Content == null) {
75        actualNameTextBox.Text = string.Empty;
76        depthTextBox.Text = string.Empty;
77      } else {
78        actualNameTextBox.Text = Content.ActualName;
79        depthTextBox.Text = Content.Depth.ToString();
80      }
81    }
82
83    protected override void SetEnabledStateOfControls() {
84      base.SetEnabledStateOfControls();
85      actualNameTextBox.Enabled = Content != null;
86      actualNameTextBox.ReadOnly = ReadOnly;
87      depthTextBox.Enabled = Content != null;
88      depthTextBox.ReadOnly = ReadOnly;
89    }
90
91    protected virtual void Content_ActualNameChanged(object sender, EventArgs e) {
92      if (InvokeRequired)
93        Invoke(new EventHandler(Content_ActualNameChanged), sender, e);
94      else
95        actualNameTextBox.Text = Content.ActualName;
96    }
97    protected virtual void Content_DepthChanged(object sender, EventArgs e) {
98      if (InvokeRequired)
99        Invoke(new EventHandler(Content_DepthChanged), sender, e);
100      else
101        depthTextBox.Text = Content.Depth.ToString();
102    }
103
104    protected virtual void actualNameTextBox_Validated(object sender, EventArgs e) {
105      Content.ActualName = actualNameTextBox.Text;
106    }
107    protected virtual void depthTextBox_KeyDown(object sender, KeyEventArgs e) {
108      if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
109        depthLabel.Focus();  // set focus on label to validate data
110      if (e.KeyCode == Keys.Escape) {
111        depthTextBox.Text = Content.Depth.ToString();
112        depthLabel.Focus();  // set focus on label to validate data
113      }
114    }
115    protected virtual void depthTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
116      int val;
117      if (!int.TryParse(depthTextBox.Text, out val) || (val < 0)) {
118        e.Cancel = true;
119        errorProvider.SetError(depthTextBox, "Invalid Value (depth must be an integer number greater or equal to zero)");
120        depthTextBox.SelectAll();
121      }
122    }
123    protected virtual void depthTextBox_Validated(object sender, EventArgs e) {
124      Content.Depth = int.Parse(depthTextBox.Text);
125      errorProvider.SetError(depthTextBox, string.Empty);
126    }
127  }
128}
Note: See TracBrowser for help on using the repository browser.