source: branches/OKB/HeuristicLab.Clients.OKB-3.3/Views/AlgorithmView.cs @ 4441

Last change on this file since 4441 was 4441, checked in by swagner, 10 years ago

Worked on OKB data model and services (#1174)

File size: 3.6 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.Linq;
23using System.Windows.Forms;
24using HeuristicLab.MainForm;
25using HeuristicLab.MainForm.WindowsForms;
26
27namespace HeuristicLab.Clients.OKB {
28  [View("Algorithm View")]
29  [Content(typeof(Algorithm), true)]
30  public partial class AlgorithmView : NamedOKBItemView {
31    public new Algorithm Content {
32      get { return (Algorithm)base.Content; }
33      set { base.Content = value; }
34    }
35
36    public AlgorithmView() {
37      InitializeComponent();
38    }
39
40    protected override void OnInitialized(System.EventArgs e) {
41      base.OnInitialized(e);
42      platformComboBox.DataSource = Administrator.Instance.Platforms.ToList();
43      algorithmClassComboBox.DataSource = Administrator.Instance.AlgorithmClasses.ToList();
44    }
45
46    protected override void DeregisterContentEvents() {
47      // ...
48      base.DeregisterContentEvents();
49    }
50    protected override void RegisterContentEvents() {
51      base.RegisterContentEvents();
52      // ...
53    }
54
55    protected override void OnContentChanged() {
56      base.OnContentChanged();
57      if (Content == null) {
58        platformComboBox.SelectedIndex = -1;
59        algorithmClassComboBox.SelectedIndex = -1;
60      } else {
61        platformComboBox.SelectedItem = Administrator.Instance.Platforms.FirstOrDefault(p => p.Id == Content.PlatformId);
62        algorithmClassComboBox.SelectedItem = Administrator.Instance.AlgorithmClasses.FirstOrDefault(a => a.Id == Content.AlgorithmClassId);
63      }
64    }
65
66    protected override void SetEnabledStateOfControls() {
67      base.SetEnabledStateOfControls();
68      platformComboBox.Enabled = Content != null;
69      algorithmClassComboBox.Enabled = Content != null;
70    }
71
72    protected override void OnContentPropertyChanged(string propertyName) {
73      switch (propertyName) {
74        case "PlatformId":
75          platformComboBox.SelectedItem = Administrator.Instance.Platforms.FirstOrDefault(p => p.Id == Content.PlatformId);
76          break;
77        case "AlgorithmClassId":
78          algorithmClassComboBox.SelectedItem = Administrator.Instance.AlgorithmClasses.FirstOrDefault(a => a.Id == Content.AlgorithmClassId);
79          break;
80      }
81    }
82
83    private void platformComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
84      if (Content != null) {
85        Platform selected = platformComboBox.SelectedItem as Platform;
86        if (selected != null) Content.PlatformId = selected.Id;
87      }
88    }
89    private void algorithmClassComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
90      if (Content != null) {
91        AlgorithmClass selected = algorithmClassComboBox.SelectedItem as AlgorithmClass;
92        if (selected != null) Content.AlgorithmClassId = selected.Id;
93      }
94    }
95  }
96}
Note: See TracBrowser for help on using the repository browser.