[2655] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[2790] | 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[2655] | 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.ComponentModel;
|
---|
| 24 | using System.Windows.Forms;
|
---|
| 25 | using HeuristicLab.MainForm;
|
---|
| 26 |
|
---|
| 27 | namespace HeuristicLab.Core.Views {
|
---|
| 28 | /// <summary>
|
---|
| 29 | /// The visual representation of a <see cref="Variable"/>.
|
---|
| 30 | /// </summary>
|
---|
[2917] | 31 | [View("NamedItem View")]
|
---|
[2790] | 32 | [Content(typeof(NamedItem), false)]
|
---|
[2727] | 33 | [Content(typeof(INamedItem), false)]
|
---|
[2664] | 34 | public partial class NamedItemView : ItemView {
|
---|
[2727] | 35 | public new INamedItem Content {
|
---|
| 36 | get { return (INamedItem)base.Content; }
|
---|
[2713] | 37 | set { base.Content = value; }
|
---|
[2655] | 38 | }
|
---|
| 39 |
|
---|
[2664] | 40 | public NamedItemView() {
|
---|
[2655] | 41 | InitializeComponent();
|
---|
[2676] | 42 | errorProvider.SetIconAlignment(nameTextBox, ErrorIconAlignment.MiddleLeft);
|
---|
| 43 | errorProvider.SetIconPadding(nameTextBox, 2);
|
---|
[2655] | 44 | }
|
---|
| 45 |
|
---|
[2713] | 46 | protected override void DeregisterContentEvents() {
|
---|
| 47 | Content.NameChanged -= new EventHandler(Content_NameChanged);
|
---|
| 48 | Content.DescriptionChanged -= new EventHandler(Content_DescriptionChanged);
|
---|
| 49 | base.DeregisterContentEvents();
|
---|
[2655] | 50 | }
|
---|
[2713] | 51 | protected override void RegisterContentEvents() {
|
---|
| 52 | base.RegisterContentEvents();
|
---|
| 53 | Content.NameChanged += new EventHandler(Content_NameChanged);
|
---|
| 54 | Content.DescriptionChanged += new EventHandler(Content_DescriptionChanged);
|
---|
[2655] | 55 | }
|
---|
| 56 |
|
---|
[2713] | 57 | protected override void OnContentChanged() {
|
---|
| 58 | base.OnContentChanged();
|
---|
| 59 | if (Content == null) {
|
---|
[3454] | 60 | nameTextBox.Text = string.Empty;
|
---|
| 61 | descriptionTextBox.Text = string.Empty;
|
---|
[2917] | 62 | toolTip.SetToolTip(descriptionTextBox, string.Empty);
|
---|
[3764] | 63 | if (ViewAttribute.HasViewAttribute(this.GetType()))
|
---|
| 64 | this.Caption = ViewAttribute.GetViewName(this.GetType());
|
---|
| 65 | else
|
---|
| 66 | this.Caption = "NamedItem View";
|
---|
[2655] | 67 | } else {
|
---|
[2713] | 68 | nameTextBox.Text = Content.Name;
|
---|
| 69 | descriptionTextBox.Text = Content.Description;
|
---|
[2917] | 70 | toolTip.SetToolTip(descriptionTextBox, Content.Description);
|
---|
[3764] | 71 | Caption = Content.Name;
|
---|
[2655] | 72 | }
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[3904] | 75 | protected override void SetEnabledStateOfControls() {
|
---|
| 76 | base.SetEnabledStateOfControls();
|
---|
[3350] | 77 | if (Content == null) {
|
---|
| 78 | nameTextBox.Enabled = false;
|
---|
| 79 | descriptionTextBox.Enabled = false;
|
---|
| 80 | } else {
|
---|
| 81 | nameTextBox.Enabled = true;
|
---|
| 82 | nameTextBox.ReadOnly = ReadOnly || !Content.CanChangeName; ;
|
---|
| 83 | descriptionTextBox.Enabled = true;
|
---|
| 84 | descriptionTextBox.ReadOnly = ReadOnly || !Content.CanChangeDescription;
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[2713] | 88 | protected virtual void Content_NameChanged(object sender, EventArgs e) {
|
---|
[2655] | 89 | if (InvokeRequired)
|
---|
[2713] | 90 | Invoke(new EventHandler(Content_NameChanged), sender, e);
|
---|
[3764] | 91 | else {
|
---|
[2713] | 92 | nameTextBox.Text = Content.Name;
|
---|
[3764] | 93 | Caption = Content.Name;
|
---|
| 94 | }
|
---|
[2655] | 95 | }
|
---|
[2713] | 96 | protected virtual void Content_DescriptionChanged(object sender, EventArgs e) {
|
---|
[2655] | 97 | if (InvokeRequired)
|
---|
[2713] | 98 | Invoke(new EventHandler(Content_DescriptionChanged), sender, e);
|
---|
[2917] | 99 | else {
|
---|
[2713] | 100 | descriptionTextBox.Text = Content.Description;
|
---|
[2917] | 101 | toolTip.SetToolTip(descriptionTextBox, Content.Description);
|
---|
| 102 | }
|
---|
[2655] | 103 | }
|
---|
| 104 |
|
---|
| 105 | protected virtual void nameTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
[2916] | 106 | if ((Content != null) && (Content.CanChangeName)) {
|
---|
[3764] | 107 | if (string.IsNullOrEmpty(nameTextBox.Text)) {
|
---|
| 108 | e.Cancel = true;
|
---|
| 109 | errorProvider.SetError(nameTextBox, "Name cannot be empty");
|
---|
| 110 | nameTextBox.SelectAll();
|
---|
| 111 | return;
|
---|
| 112 | }
|
---|
[2713] | 113 | Content.Name = nameTextBox.Text;
|
---|
[2655] | 114 | // check if variable name was set successfully
|
---|
[2713] | 115 | if (!Content.Name.Equals(nameTextBox.Text)) {
|
---|
[2676] | 116 | e.Cancel = true;
|
---|
| 117 | errorProvider.SetError(nameTextBox, "Invalid Name");
|
---|
[2655] | 118 | nameTextBox.SelectAll();
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
[2676] | 122 | protected virtual void nameTextBox_Validated(object sender, EventArgs e) {
|
---|
| 123 | errorProvider.SetError(nameTextBox, string.Empty);
|
---|
| 124 | }
|
---|
| 125 | protected virtual void nameTextBox_KeyDown(object sender, KeyEventArgs e) {
|
---|
| 126 | if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
|
---|
| 127 | nameLabel.Focus(); // set focus on label to validate data
|
---|
| 128 | if (e.KeyCode == Keys.Escape) {
|
---|
[2713] | 129 | nameTextBox.Text = Content.Name;
|
---|
[2676] | 130 | nameLabel.Focus(); // set focus on label to validate data
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
[2655] | 133 | protected virtual void descriptionTextBox_Validated(object sender, EventArgs e) {
|
---|
[2713] | 134 | if (Content.CanChangeDescription)
|
---|
| 135 | Content.Description = descriptionTextBox.Text;
|
---|
[2655] | 136 | }
|
---|
[2917] | 137 |
|
---|
| 138 | protected void descriptionTextBox_DoubleClick(object sender, EventArgs e) {
|
---|
[3396] | 139 | using (TextDialog dialog = new TextDialog("Description of " + Content.Name, descriptionTextBox.Text, ReadOnly || !Content.CanChangeDescription)) {
|
---|
[2917] | 140 | if (dialog.ShowDialog(this) == DialogResult.OK)
|
---|
| 141 | Content.Description = dialog.Content;
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
[2655] | 144 | }
|
---|
| 145 | }
|
---|