Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/Views/DataTypeView.cs @ 5639

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

Worked on OKB (#1174)

File size: 5.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.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        typeNameTextBox.Text = string.Empty;
55        sqlNameComboBox.SelectedIndex = -1;
56        platformComboBox.SelectedIndex = -1;
57        if (ViewAttribute.HasViewAttribute(this.GetType()))
58          this.Caption = ViewAttribute.GetViewName(this.GetType());
59        else
60          this.Caption = "DataType View";
61      } else {
62        nameTextBox.Text = Content.Name;
63        typeNameTextBox.Text = Content.TypeName;
64        sqlNameComboBox.Text = Content.SqlName;
65        platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId);
66        Caption = Content.Name;
67      }
68    }
69
70    protected override void SetEnabledStateOfControls() {
71      base.SetEnabledStateOfControls();
72      nameTextBox.Enabled = Content != null;
73      nameTextBox.ReadOnly = ReadOnly;
74      typeNameTextBox.Enabled = Content != null;
75      typeNameTextBox.ReadOnly = ReadOnly;
76      sqlNameComboBox.Enabled = (Content != null) && !ReadOnly;
77      platformComboBox.Enabled = (Content != null) && !ReadOnly;
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 "TypeName":
87          typeNameTextBox.Text = Content.Name;
88          break;
89        case "SqlName":
90          sqlNameComboBox.Text = Content.SqlName;
91          break;
92        case "PlatformId":
93          platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId);
94          break;
95      }
96    }
97
98    private void nameTextBox_KeyDown(object sender, KeyEventArgs e) {
99      if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
100        nameLabel.Focus();  // set focus on label to validate data
101      if (e.KeyCode == Keys.Escape) {
102        nameTextBox.Text = Content.Name;
103        nameLabel.Focus();  // set focus on label to validate data
104      }
105    }
106    private void nameTextBox_TextChanged(object sender, EventArgs e) {
107      if (nameTextBox.Text != Content.Name)
108        Content.Name = nameTextBox.Text;
109    }
110    private void typeNameTextBox_KeyDown(object sender, KeyEventArgs e) {
111      if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
112        typeNameLabel.Focus();  // set focus on label to validate data
113      if (e.KeyCode == Keys.Escape) {
114        typeNameTextBox.Text = Content.TypeName;
115        typeNameLabel.Focus();  // set focus on label to validate data
116      }
117    }
118    private void typeNameTextBox_TextChanged(object sender, EventArgs e) {
119      if (typeNameTextBox.Text != Content.TypeName)
120        Content.TypeName = typeNameTextBox.Text;
121    }
122    private void sqlNameComboBox_SelectedValueChanged(object sender, EventArgs e) {
123      if (sqlNameComboBox.Text != Content.SqlName) {
124        Content.SqlName = sqlNameComboBox.Text;
125      }
126    }
127    private void platformComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
128      if (Content != null) {
129        Platform selected = platformComboBox.SelectedItem as Platform;
130        if (selected != null) Content.PlatformId = selected.Id;
131      }
132    }
133  }
134}
Note: See TracBrowser for help on using the repository browser.