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