[4466] | 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 |
|
---|
| 22 | using System;
|
---|
[4558] | 23 | using System.Collections.Generic;
|
---|
[4492] | 24 | using System.Linq;
|
---|
[4466] | 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.MainForm;
|
---|
| 27 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.Clients.OKB {
|
---|
| 30 | [View("DataType View")]
|
---|
| 31 | [Content(typeof(DataType), true)]
|
---|
| 32 | public partial class DataTypeView : OKBItemView {
|
---|
[4558] | 33 | private List<Platform> platformComboBoxValues;
|
---|
| 34 |
|
---|
[4466] | 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);
|
---|
[4558] | 46 | platformComboBoxValues = OKBClient.Instance.Platforms.ToList();
|
---|
| 47 | platformComboBox.DataSource = platformComboBoxValues;
|
---|
[4466] | 48 | }
|
---|
| 49 |
|
---|
| 50 | protected override void OnContentChanged() {
|
---|
| 51 | base.OnContentChanged();
|
---|
| 52 | if (Content == null) {
|
---|
| 53 | nameTextBox.Text = string.Empty;
|
---|
[5295] | 54 | typeNameTextBox.Text = string.Empty;
|
---|
[4492] | 55 | sqlNameComboBox.SelectedIndex = -1;
|
---|
[4466] | 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;
|
---|
[5295] | 63 | typeNameTextBox.Text = Content.TypeName;
|
---|
[4492] | 64 | sqlNameComboBox.Text = Content.SqlName;
|
---|
[4558] | 65 | platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId);
|
---|
[4466] | 66 | Caption = Content.Name;
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | protected override void SetEnabledStateOfControls() {
|
---|
| 71 | base.SetEnabledStateOfControls();
|
---|
[4492] | 72 | nameTextBox.Enabled = Content != null;
|
---|
| 73 | nameTextBox.ReadOnly = ReadOnly;
|
---|
[5295] | 74 | typeNameTextBox.Enabled = Content != null;
|
---|
| 75 | typeNameTextBox.ReadOnly = ReadOnly;
|
---|
[4492] | 76 | sqlNameComboBox.Enabled = (Content != null) && !ReadOnly;
|
---|
| 77 | platformComboBox.Enabled = (Content != null) && !ReadOnly;
|
---|
[4466] | 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;
|
---|
[5295] | 86 | case "TypeName":
|
---|
| 87 | typeNameTextBox.Text = Content.Name;
|
---|
| 88 | break;
|
---|
[4466] | 89 | case "SqlName":
|
---|
[4492] | 90 | sqlNameComboBox.Text = Content.SqlName;
|
---|
[4466] | 91 | break;
|
---|
| 92 | case "PlatformId":
|
---|
[4558] | 93 | platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId);
|
---|
[4466] | 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 | }
|
---|
[5295] | 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 | }
|
---|
[4492] | 122 | private void sqlNameComboBox_SelectedValueChanged(object sender, EventArgs e) {
|
---|
| 123 | if (sqlNameComboBox.Text != Content.SqlName) {
|
---|
| 124 | Content.SqlName = sqlNameComboBox.Text;
|
---|
[4466] | 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 | }
|
---|