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