Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB/HeuristicLab.Clients.OKB-3.3/Views/DataTypeView.cs @ 4466

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

Worked on OKB (#1174)

File size: 4.6 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 System.Linq;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27using HeuristicLab.MainForm.WindowsForms;
28
29namespace HeuristicLab.Clients.OKB {
30  [View("DataType View")]
31  [Content(typeof(DataType), true)]
32  public partial class DataTypeView : OKBItemView {
33    public new DataType Content {
34      get { return (DataType)base.Content; }
35      set { base.Content = value; }
36    }
37
38    public DataTypeView() {
39      InitializeComponent();
40    }
41
42    protected override void OnInitialized(System.EventArgs e) {
43      base.OnInitialized(e);
44      platformComboBox.DataSource = Administrator.Instance.Platforms.ToList();
45    }
46
47    protected override void OnContentChanged() {
48      base.OnContentChanged();
49      if (Content == null) {
50        nameTextBox.Text = string.Empty;
51        sqlNameTextBox.Text = string.Empty;
52        platformComboBox.SelectedIndex = -1;
53        if (ViewAttribute.HasViewAttribute(this.GetType()))
54          this.Caption = ViewAttribute.GetViewName(this.GetType());
55        else
56          this.Caption = "DataType View";
57      } else {
58        nameTextBox.Text = Content.Name;
59        sqlNameTextBox.Text = Content.SqlName;
60        platformComboBox.SelectedItem = Administrator.Instance.Platforms.FirstOrDefault(p => p.Id == Content.PlatformId);
61        Caption = Content.Name;
62      }
63    }
64
65    protected override void SetEnabledStateOfControls() {
66      base.SetEnabledStateOfControls();
67      if (Content == null) {
68        nameTextBox.Enabled = false;
69        sqlNameTextBox.Enabled = false;
70        platformComboBox.Enabled = false;
71      } else {
72        nameTextBox.Enabled = true;
73        nameTextBox.ReadOnly = ReadOnly;
74        sqlNameTextBox.Enabled = true;
75        sqlNameTextBox.ReadOnly = ReadOnly;
76        platformComboBox.Enabled = true;
77      }
78    }
79
80    protected override void OnContentPropertyChanged(string propertyName) {
81      switch (propertyName) {
82        case "Name":
83          nameTextBox.Text = Content.Name;
84          Caption = Content.Name;
85          break;
86        case "SqlName":
87          sqlNameTextBox.Text = Content.SqlName;
88          break;
89        case "PlatformId":
90          platformComboBox.SelectedItem = Administrator.Instance.Platforms.FirstOrDefault(p => p.Id == Content.PlatformId);
91          break;
92      }
93    }
94
95    private void nameTextBox_KeyDown(object sender, KeyEventArgs e) {
96      if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
97        nameLabel.Focus();  // set focus on label to validate data
98      if (e.KeyCode == Keys.Escape) {
99        nameTextBox.Text = Content.Name;
100        nameLabel.Focus();  // set focus on label to validate data
101      }
102    }
103    private void nameTextBox_TextChanged(object sender, EventArgs e) {
104      if (nameTextBox.Text != Content.Name)
105        Content.Name = nameTextBox.Text;
106    }
107    private void sqlNameTextBox_KeyDown(object sender, KeyEventArgs e) {
108      if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
109        sqlNameLabel.Focus();  // set focus on label to validate data
110      if (e.KeyCode == Keys.Escape) {
111        sqlNameTextBox.Text = Content.SqlName;
112        sqlNameLabel.Focus();  // set focus on label to validate data
113      }
114    }
115    private void sqlNameTextBox_TextChanged(object sender, EventArgs e) {
116      if (sqlNameTextBox.Text != Content.SqlName)
117        Content.SqlName = sqlNameTextBox.Text;
118    }
119    private void platformComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
120      if (Content != null) {
121        Platform selected = platformComboBox.SelectedItem as Platform;
122        if (selected != null) Content.PlatformId = selected.Id;
123      }
124    }
125  }
126}
Note: See TracBrowser for help on using the repository browser.