Free cookie consent management tool by TermsFeed Policy Generator

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

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