Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4433 was 4426, checked in by swagner, 14 years ago

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