Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB/HeuristicLab.Clients.OKB-3.3/Views/ResultView.cs @ 5532

Last change on this file since 5532 was 4929, checked in by swagner, 14 years ago

Worked on OKB (#1174)

File size: 3.4 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("Result View")]
31  [Content(typeof(Result), true)]
32  public partial class ResultView : NamedOKBItemView {
33    private List<DataType> dataTypeComboBoxValues;
34
35    public new Result Content {
36      get { return (Result)base.Content; }
37      set { base.Content = value; }
38    }
39
40    public ResultView() {
41      InitializeComponent();
42    }
43
44    protected override void OnInitialized(System.EventArgs e) {
45      base.OnInitialized(e);
46      dataTypeComboBoxValues = OKBClient.Instance.DataTypes.ToList();
47      dataTypeComboBox.DataSource = dataTypeComboBoxValues;
48      dataTypeComboBox.SelectedIndex = -1;
49    }
50
51    protected override void OnContentChanged() {
52      base.OnContentChanged();
53      if (Content == null) {
54        aliasTextBox.Text = string.Empty;
55        dataTypeComboBox.SelectedIndex = -1;
56      } else {
57        aliasTextBox.Text = Content.Alias;
58        dataTypeComboBox.SelectedItem = dataTypeComboBoxValues.FirstOrDefault(d => d.Id == Content.DataTypeId);
59      }
60    }
61
62    protected override void SetEnabledStateOfControls() {
63      base.SetEnabledStateOfControls();
64      aliasTextBox.Enabled = Content != null;
65      aliasTextBox.ReadOnly = ReadOnly;
66      dataTypeComboBox.Enabled = Content != null && !ReadOnly;
67    }
68
69    protected override void OnContentPropertyChanged(string propertyName) {
70      switch (propertyName) {
71        case "Alias":
72          aliasTextBox.Text = Content.Alias;
73          break;
74        case "DataTypeId":
75          dataTypeComboBox.SelectedItem = dataTypeComboBoxValues.FirstOrDefault(d => d.Id == Content.DataTypeId);
76          break;
77      }
78    }
79
80    protected virtual void aliasTextBox_KeyDown(object sender, KeyEventArgs e) {
81      if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
82        aliasLabel.Focus();  // set focus on label to validate data
83      if (e.KeyCode == Keys.Escape) {
84        aliasTextBox.Text = Content.Alias;
85        aliasLabel.Focus();  // set focus on label to validate data
86      }
87    }
88    protected virtual void aliasTextBox_TextChanged(object sender, EventArgs e) {
89      if (aliasTextBox.Text != Content.Alias)
90        Content.Alias = aliasTextBox.Text;
91    }
92
93    private void dataTypeComboBox_SelectedIndexChanged(object sender, EventArgs e) {
94      if (Content != null) Content.DataTypeId = ((DataType)dataTypeComboBox.SelectedItem).Id;
95    }
96  }
97}
Note: See TracBrowser for help on using the repository browser.