#region License Information
/* HeuristicLab
* Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using HeuristicLab.MainForm;
using HeuristicLab.MainForm.WindowsForms;
namespace HeuristicLab.Clients.OKB {
[View("Result View")]
[Content(typeof(Result), true)]
public partial class ResultView : NamedOKBItemView {
private List dataTypeComboBoxValues;
public new Result Content {
get { return (Result)base.Content; }
set { base.Content = value; }
}
public ResultView() {
InitializeComponent();
}
protected override void OnInitialized(System.EventArgs e) {
base.OnInitialized(e);
dataTypeComboBoxValues = OKBClient.Instance.DataTypes.ToList();
dataTypeComboBox.DataSource = dataTypeComboBoxValues;
dataTypeComboBox.SelectedIndex = -1;
}
protected override void OnContentChanged() {
base.OnContentChanged();
if (Content == null) {
aliasTextBox.Text = string.Empty;
dataTypeComboBox.SelectedIndex = -1;
} else {
aliasTextBox.Text = Content.Alias;
dataTypeComboBox.SelectedItem = dataTypeComboBoxValues.FirstOrDefault(d => d.Id == Content.DataTypeId);
}
}
protected override void SetEnabledStateOfControls() {
base.SetEnabledStateOfControls();
aliasTextBox.Enabled = Content != null;
aliasTextBox.ReadOnly = ReadOnly;
dataTypeComboBox.Enabled = Content != null && !ReadOnly;
}
protected override void OnContentPropertyChanged(string propertyName) {
switch (propertyName) {
case "Alias":
aliasTextBox.Text = Content.Alias;
break;
case "DataTypeId":
dataTypeComboBox.SelectedItem = dataTypeComboBoxValues.FirstOrDefault(d => d.Id == Content.DataTypeId);
break;
}
}
protected virtual void aliasTextBox_KeyDown(object sender, KeyEventArgs e) {
if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
aliasLabel.Focus(); // set focus on label to validate data
if (e.KeyCode == Keys.Escape) {
aliasTextBox.Text = Content.Alias;
aliasLabel.Focus(); // set focus on label to validate data
}
}
protected virtual void aliasTextBox_TextChanged(object sender, EventArgs e) {
if (aliasTextBox.Text != Content.Alias)
Content.Alias = aliasTextBox.Text;
}
private void dataTypeComboBox_SelectedIndexChanged(object sender, EventArgs e) {
if (Content != null) Content.DataTypeId = ((DataType)dataTypeComboBox.SelectedItem).Id;
}
}
}