Free cookie consent management tool by TermsFeed Policy Generator

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

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

Worked on OKB (#1174)

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