Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB/HeuristicLab.Clients.OKB-3.3/Views/NamedOKBItemView.cs @ 6094

Last change on this file since 6094 was 4492, checked in by swagner, 14 years ago

Worked on OKB (#1174)

File size: 3.8 KB
Line 
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
22using System;
23using System.Windows.Forms;
24using HeuristicLab.Core.Views;
25using HeuristicLab.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
27
28namespace 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      nameTextBox.Enabled = Content != null;
63      nameTextBox.ReadOnly = ReadOnly;
64      descriptionTextBox.Enabled = Content != null;
65      descriptionTextBox.ReadOnly = ReadOnly;
66    }
67
68    protected override void OnContentPropertyChanged(string propertyName) {
69      switch (propertyName) {
70        case "Name":
71          nameTextBox.Text = Content.Name;
72          Caption = Content.Name;
73          break;
74        case "Description":
75          descriptionTextBox.Text = Content.Description;
76          toolTip.SetToolTip(descriptionTextBox, Content.Description);
77          break;
78      }
79    }
80
81    protected virtual void nameTextBox_KeyDown(object sender, KeyEventArgs e) {
82      if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
83        nameLabel.Focus();  // set focus on label to validate data
84      if (e.KeyCode == Keys.Escape) {
85        nameTextBox.Text = Content.Name;
86        nameLabel.Focus();  // set focus on label to validate data
87      }
88    }
89    protected virtual void nameTextBox_TextChanged(object sender, EventArgs e) {
90      if (nameTextBox.Text != Content.Name)
91        Content.Name = nameTextBox.Text;
92    }
93    protected virtual void descriptionTextBox_TextChanged(object sender, EventArgs e) {
94      if (descriptionTextBox.Text != Content.Description)
95        Content.Description = descriptionTextBox.Text;
96    }
97
98    protected void descriptionTextBox_DoubleClick(object sender, EventArgs e) {
99      using (TextDialog dialog = new TextDialog("Description of " + Content.Name, descriptionTextBox.Text, ReadOnly)) {
100        if (dialog.ShowDialog(this) == DialogResult.OK)
101          Content.Description = dialog.Content;
102      }
103    }
104  }
105}
Note: See TracBrowser for help on using the repository browser.