Free cookie consent management tool by TermsFeed Policy Generator

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

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

Worked on OKB (#1174)

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