Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Parameters.Views/3.3/LookupParameterView.cs @ 4040

Last change on this file since 4040 was 3904, checked in by mkommend, 14 years ago

Added SetEnabledStateOfControls as protected virtual method in !View. Therefore the overloading of OnReadOnlyChanged and OnLockedChanged got obsolete in most views, because the method got called in the !View respectively ContentView. (ticket #1021)

File size: 3.5 KB
RevLine 
[2740]1#region License Information
2/* HeuristicLab
[2790]3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2740]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;
[3376]23using HeuristicLab.Common;
[2740]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>
[2917]32  [View("LookupParameter View")]
[2756]33  [Content(typeof(LookupParameter<>), true)]
34  [Content(typeof(ILookupParameter<>), false)]
35  public partial class LookupParameterView<T> : ParameterView where T : class, IItem {
[2740]36    /// <summary>
37    /// Gets or sets the variable to represent visually.
38    /// </summary>
39    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
40    /// No own data storage present.</remarks>
[2756]41    public new ILookupParameter<T> Content {
42      get { return (ILookupParameter<T>)base.Content; }
[2740]43      set { base.Content = value; }
44    }
45
46    /// <summary>
47    /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".
48    /// </summary>
[2756]49    public LookupParameterView() {
[2740]50      InitializeComponent();
51    }
52
53    /// <summary>
54    /// Removes the eventhandlers from the underlying <see cref="IVariable"/>.
55    /// </summary>
56    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
57    protected override void DeregisterContentEvents() {
58      Content.ActualNameChanged -= new EventHandler(Content_ActualNameChanged);
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    }
70
71    protected override void OnContentChanged() {
72      base.OnContentChanged();
[3764]73      if (Content == null)
[2740]74        actualNameTextBox.Text = "-";
[3764]75      else
[2740]76        actualNameTextBox.Text = Content.ActualName;
77    }
78
[3904]79    protected override void SetEnabledStateOfControls() {
80      base.SetEnabledStateOfControls();
[3365]81      actualNameTextBox.Enabled = Content != null;
82      actualNameTextBox.ReadOnly = ReadOnly;
83    }
84
[2740]85    protected virtual void Content_ActualNameChanged(object sender, EventArgs e) {
86      if (InvokeRequired)
87        Invoke(new EventHandler(Content_ActualNameChanged), sender, e);
88      else
89        actualNameTextBox.Text = Content.ActualName;
90    }
91
92    protected virtual void actualNameTextBox_Validated(object sender, EventArgs e) {
93      Content.ActualName = actualNameTextBox.Text;
94    }
95  }
96}
Note: See TracBrowser for help on using the repository browser.