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.Core.Views;
|
---|
25 | using HeuristicLab.MainForm;
|
---|
26 | using HeuristicLab.MainForm.WindowsForms;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Clients.OKB {
|
---|
29 | [View("NamedOKBItem View")]
|
---|
30 | [Content(typeof(NamedOKBItem), true)]
|
---|
31 | [Content(typeof(INamedOKBItem), false)]
|
---|
32 | public partial class NamedOKBItemView : OKBItemView {
|
---|
33 | public new INamedOKBItem Content {
|
---|
34 | get { return (INamedOKBItem)base.Content; }
|
---|
35 | set { base.Content = value; }
|
---|
36 | }
|
---|
37 |
|
---|
38 | public NamedOKBItemView() {
|
---|
39 | InitializeComponent();
|
---|
40 | }
|
---|
41 |
|
---|
42 | protected override void OnContentChanged() {
|
---|
43 | base.OnContentChanged();
|
---|
44 | if (Content == null) {
|
---|
45 | nameTextBox.Text = string.Empty;
|
---|
46 | descriptionTextBox.Text = string.Empty;
|
---|
47 | toolTip.SetToolTip(descriptionTextBox, string.Empty);
|
---|
48 | if (ViewAttribute.HasViewAttribute(this.GetType()))
|
---|
49 | this.Caption = ViewAttribute.GetViewName(this.GetType());
|
---|
50 | else
|
---|
51 | this.Caption = "NamedEntity View";
|
---|
52 | } else {
|
---|
53 | nameTextBox.Text = Content.Name;
|
---|
54 | descriptionTextBox.Text = Content.Description;
|
---|
55 | toolTip.SetToolTip(descriptionTextBox, Content.Description);
|
---|
56 | Caption = Content.Name;
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | protected override void SetEnabledStateOfControls() {
|
---|
61 | base.SetEnabledStateOfControls();
|
---|
62 | if (Content == null) {
|
---|
63 | nameTextBox.Enabled = false;
|
---|
64 | descriptionTextBox.Enabled = false;
|
---|
65 | } else {
|
---|
66 | nameTextBox.Enabled = true;
|
---|
67 | nameTextBox.ReadOnly = ReadOnly;
|
---|
68 | descriptionTextBox.Enabled = true;
|
---|
69 | descriptionTextBox.ReadOnly = ReadOnly;
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | protected override void OnContentPropertyChanged(string propertyName) {
|
---|
74 | switch (propertyName) {
|
---|
75 | case "Name":
|
---|
76 | nameTextBox.Text = Content.Name;
|
---|
77 | Caption = Content.Name;
|
---|
78 | break;
|
---|
79 | case "Description":
|
---|
80 | descriptionTextBox.Text = Content.Description;
|
---|
81 | toolTip.SetToolTip(descriptionTextBox, Content.Description);
|
---|
82 | break;
|
---|
83 | }
|
---|
84 | }
|
---|
85 |
|
---|
86 | protected virtual void nameTextBox_KeyDown(object sender, KeyEventArgs e) {
|
---|
87 | if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
|
---|
88 | nameLabel.Focus(); // set focus on label to validate data
|
---|
89 | if (e.KeyCode == Keys.Escape) {
|
---|
90 | nameTextBox.Text = Content.Name;
|
---|
91 | nameLabel.Focus(); // set focus on label to validate data
|
---|
92 | }
|
---|
93 | }
|
---|
94 | protected virtual void nameTextBox_TextChanged(object sender, EventArgs e) {
|
---|
95 | if (nameTextBox.Text != Content.Name)
|
---|
96 | Content.Name = nameTextBox.Text;
|
---|
97 | }
|
---|
98 | protected virtual void descriptionTextBox_TextChanged(object sender, EventArgs e) {
|
---|
99 | if (descriptionTextBox.Text != Content.Description)
|
---|
100 | Content.Description = descriptionTextBox.Text;
|
---|
101 | }
|
---|
102 |
|
---|
103 | protected void descriptionTextBox_DoubleClick(object sender, EventArgs e) {
|
---|
104 | using (TextDialog dialog = new TextDialog("Description of " + Content.Name, descriptionTextBox.Text, ReadOnly)) {
|
---|
105 | if (dialog.ShowDialog(this) == DialogResult.OK)
|
---|
106 | Content.Description = dialog.Content;
|
---|
107 | }
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|