Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB/HeuristicLab.Clients.OKB-3.3/NamedEntityView.cs @ 4422

Last change on this file since 4422 was 4421, checked in by swagner, 14 years ago

Worked on OKB data model and services (#1174)

File size: 4.5 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.ComponentModel;
24using System.Windows.Forms;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27using HeuristicLab.MainForm.WindowsForms;
28
29namespace HeuristicLab.Clients.OKB {
30  [View("NamedEntoty View")]
31  [Content(typeof(INamedEntity), false)]
32  public partial class NamedEntityView : ItemView {
33    public new INamedEntity Content {
34      get { return (INamedEntity)base.Content; }
35      set { base.Content = value; }
36    }
37
38    public NamedEntityView() {
39      InitializeComponent();
40    }
41
42    protected override void DeregisterContentEvents() {
43      Content.PropertyChanged -= new PropertyChangedEventHandler(Content_PropertyChanged);
44      base.DeregisterContentEvents();
45    }
46    protected override void RegisterContentEvents() {
47      base.RegisterContentEvents();
48      Content.PropertyChanged += new PropertyChangedEventHandler(Content_PropertyChanged);
49    }
50
51    protected override void OnContentChanged() {
52      base.OnContentChanged();
53      if (Content == null) {
54        nameTextBox.Text = string.Empty;
55        descriptionTextBox.Text = string.Empty;
56        toolTip.SetToolTip(descriptionTextBox, string.Empty);
57        if (ViewAttribute.HasViewAttribute(this.GetType()))
58          this.Caption = ViewAttribute.GetViewName(this.GetType());
59        else
60          this.Caption = "NamedEntity View";
61      } else {
62        nameTextBox.Text = Content.Name;
63        descriptionTextBox.Text = Content.Description;
64        toolTip.SetToolTip(descriptionTextBox, Content.Description);
65        Caption = Content.Name;
66      }
67    }
68
69    protected override void SetEnabledStateOfControls() {
70      base.SetEnabledStateOfControls();
71      if (Content == null) {
72        nameTextBox.Enabled = false;
73        descriptionTextBox.Enabled = false;
74      } else {
75        nameTextBox.Enabled = true;
76        nameTextBox.ReadOnly = ReadOnly;
77        descriptionTextBox.Enabled = true;
78        descriptionTextBox.ReadOnly = ReadOnly;
79      }
80    }
81
82    protected virtual void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
83      if (InvokeRequired)
84        Invoke(new PropertyChangedEventHandler(Content_PropertyChanged), sender, e);
85      else {
86        switch (e.PropertyName) {
87          case "Name":
88            nameTextBox.Text = Content.Name;
89            Caption = Content.Name;
90            break;
91          case "Description":
92            descriptionTextBox.Text = Content.Description;
93            toolTip.SetToolTip(descriptionTextBox, Content.Description);
94            break;
95        }
96        nameTextBox.Text = Content.Name;
97        Caption = Content.Name;
98      }
99    }
100
101    protected virtual void nameTextBox_KeyDown(object sender, KeyEventArgs e) {
102      if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
103        nameLabel.Focus();  // set focus on label to validate data
104      if (e.KeyCode == Keys.Escape) {
105        nameTextBox.Text = Content.Name;
106        nameLabel.Focus();  // set focus on label to validate data
107      }
108    }
109    protected virtual void nameTextBox_Validated(object sender, EventArgs e) {
110      Content.Name = nameTextBox.Text;
111    }
112    protected virtual void descriptionTextBox_Validated(object sender, EventArgs e) {
113      Content.Description = descriptionTextBox.Text;
114    }
115
116    protected void descriptionTextBox_DoubleClick(object sender, EventArgs e) {
117      using (TextDialog dialog = new TextDialog("Description of " + Content.Name, descriptionTextBox.Text, ReadOnly)) {
118        if (dialog.ShowDialog(this) == DialogResult.OK)
119          Content.Description = dialog.Content;
120      }
121    }
122  }
123}
Note: See TracBrowser for help on using the repository browser.