#region License Information /* HeuristicLab * Copyright (C) 2002-2011 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("ScopePathLookupParameter View")] [Content(typeof(ScopePathLookupParameter<>), true)] public partial class ScopePathLookupParameterView : 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 ScopePathLookupParameter Content { get { return (ScopePathLookupParameter)base.Content; } set { base.Content = value; } } /// /// Initializes a new instance of with caption "Variable". /// public ScopePathLookupParameterView() { InitializeComponent(); } /// /// Removes the eventhandlers from the underlying . /// /// Calls of base class . protected override void DeregisterContentEvents() { Content.ActualNameChanged -= new EventHandler(Content_ActualNameChanged); Content.PathChanged -= new EventHandler(Content_PathChanged); base.DeregisterContentEvents(); } /// /// Adds eventhandlers to the underlying . /// /// Calls of base class . protected override void RegisterContentEvents() { base.RegisterContentEvents(); Content.ActualNameChanged += new EventHandler(Content_ActualNameChanged); Content.PathChanged += new EventHandler(Content_PathChanged); } protected override void OnContentChanged() { base.OnContentChanged(); if (Content == null) { actualNameTextBox.Text = string.Empty; pathTextBox.Text = string.Empty; } else { actualNameTextBox.Text = Content.ActualName; pathTextBox.Text = Content.Path; } } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); actualNameTextBox.Enabled = Content != null; actualNameTextBox.ReadOnly = ReadOnly; pathTextBox.Enabled = Content != null; pathTextBox.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_PathChanged(object sender, EventArgs e) { if (InvokeRequired) Invoke(new EventHandler(Content_PathChanged), sender, e); else pathTextBox.Text = Content.Path; } protected virtual void actualNameTextBox_Validated(object sender, EventArgs e) { Content.ActualName = actualNameTextBox.Text; } protected virtual void pathTextBox_KeyDown(object sender, KeyEventArgs e) { if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) pathLabel.Focus(); // set focus on label to validate data if (e.KeyCode == Keys.Escape) { pathTextBox.Text = Content.Path; pathLabel.Focus(); // set focus on label to validate data } } protected virtual void pathTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) { if (!ScopePathLookupParameter.ValidPathRegex.IsMatch(pathTextBox.Text)) { e.Cancel = true; errorProvider.SetError(pathTextBox, "Invalid Path"); pathTextBox.SelectAll(); } } protected virtual void pathTextBox_Validated(object sender, EventArgs e) { Content.Path = pathTextBox.Text; errorProvider.SetError(pathTextBox, string.Empty); } } }