#region License Information /* HeuristicLab * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Windows.Forms; using HeuristicLab.Core; using HeuristicLab.Core.Views; using HeuristicLab.MainForm; namespace HeuristicLab.Parameters.Views { /// /// The visual representation of a . /// [View("ScopeTreeLookupParameter View")] [Content(typeof(ScopeTreeLookupParameter<>), true)] public partial class ScopeTreeLookupParameterView : ParameterView where T : class, IItem { /// /// Gets or sets the variable to represent visually. /// /// Uses property of base class . /// No own data storage present. public new ScopeTreeLookupParameter Content { get { return (ScopeTreeLookupParameter)base.Content; } set { base.Content = value; } } /// /// Initializes a new instance of with caption "Variable". /// public ScopeTreeLookupParameterView() { InitializeComponent(); } /// /// Removes the eventhandlers from the underlying . /// /// Calls of base class . protected override void DeregisterContentEvents() { Content.ActualNameChanged -= new EventHandler(Content_ActualNameChanged); Content.DepthChanged -= new EventHandler(Content_DepthChanged); base.DeregisterContentEvents(); } /// /// Adds eventhandlers to the underlying . /// /// Calls of base class . protected override void RegisterContentEvents() { base.RegisterContentEvents(); Content.ActualNameChanged += new EventHandler(Content_ActualNameChanged); Content.DepthChanged += new EventHandler(Content_DepthChanged); } protected override void OnContentChanged() { base.OnContentChanged(); if (Content == null) { actualNameTextBox.Text = string.Empty; depthTextBox.Text = string.Empty; } else { actualNameTextBox.Text = Content.ActualName; depthTextBox.Text = Content.Depth.ToString(); } } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); actualNameTextBox.Enabled = Content != null; actualNameTextBox.ReadOnly = ReadOnly; depthTextBox.Enabled = Content != null; depthTextBox.ReadOnly = ReadOnly; } protected virtual void Content_ActualNameChanged(object sender, EventArgs e) { if (InvokeRequired) Invoke(new EventHandler(Content_ActualNameChanged), sender, e); else actualNameTextBox.Text = Content.ActualName; } protected virtual void Content_DepthChanged(object sender, EventArgs e) { if (InvokeRequired) Invoke(new EventHandler(Content_DepthChanged), sender, e); else depthTextBox.Text = Content.Depth.ToString(); } protected virtual void actualNameTextBox_Validated(object sender, EventArgs e) { Content.ActualName = actualNameTextBox.Text; } protected virtual void depthTextBox_KeyDown(object sender, KeyEventArgs e) { if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) { depthLabel.Focus(); // set focus on label to validate data e.SuppressKeyPress = true; } else if (e.KeyCode == Keys.Escape) { depthTextBox.Text = Content.Depth.ToString(); depthLabel.Focus(); // set focus on label to validate data e.SuppressKeyPress = true; } } protected virtual void depthTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) { int val; if (!int.TryParse(depthTextBox.Text, out val) || (val < 0)) { e.Cancel = true; errorProvider.SetError(depthTextBox, "Invalid Value (depth must be an integer number greater or equal to zero)"); depthTextBox.SelectAll(); } } protected virtual void depthTextBox_Validated(object sender, EventArgs e) { Content.Depth = int.Parse(depthTextBox.Text); errorProvider.SetError(depthTextBox, string.Empty); } } }