Free cookie consent management tool by TermsFeed Policy Generator

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

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

Worked on OKB (#1174)

File size: 5.0 KB
RevLine 
[5344]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.Linq;
24using System.Windows.Forms;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27using HeuristicLab.MainForm.WindowsForms;
28
29namespace HeuristicLab.Clients.OKB {
30  [View("OKBAlgorithm View")]
31  [Content(typeof(OKBAlgorithm), true)]
32  public sealed partial class OKBAlgorithmView : ItemView {
33    public new OKBAlgorithm Content {
34      get { return (OKBAlgorithm)base.Content; }
35      set { base.Content = value; }
36    }
37
38    public OKBAlgorithmView() {
39      InitializeComponent();
40    }
41
42    protected override void OnInitialized(System.EventArgs e) {
43      base.OnInitialized(e);
44      OKBClient.Instance.Refreshing += new EventHandler(OKBClient_Refreshing);
45      OKBClient.Instance.Refreshed += new EventHandler(OKBClient_Refreshed);
46      PopulateComboBox();
47    }
48
49    protected override void DeregisterContentEvents() {
50      Content.AlgorithmChanged -= new EventHandler(Content_AlgorithmChanged);
51      base.DeregisterContentEvents();
52    }
53    protected override void RegisterContentEvents() {
54      base.RegisterContentEvents();
55      Content.AlgorithmChanged += new EventHandler(Content_AlgorithmChanged);
56    }
57
58    protected override void OnContentChanged() {
59      base.OnContentChanged();
60      if (Content == null) {
61        algorithmComboBox.SelectedIndex = -1;
62        viewHost.Content = null;
63      } else {
64        algorithmComboBox.SelectedItem = OKBClient.Instance.Algorithms.FirstOrDefault(x => x.Id == Content.AlgorithmId);
65        viewHost.Content = Content.Algorithm;
66      }
67    }
68    protected override void SetEnabledStateOfControls() {
69      base.SetEnabledStateOfControls();
70      algorithmComboBox.Enabled = (Content != null) && !ReadOnly && !Locked && (algorithmComboBox.Items.Count > 0);
71      refreshButton.Enabled = (Content != null) && !ReadOnly && !Locked;
72    }
73
74    private void PopulateComboBox() {
75      algorithmComboBox.DataSource = null;
76      Platform platform = OKBClient.Instance.Platforms.FirstOrDefault(x => x.Name == "HeuristicLab 3.3");
77      if (platform != null) {
78        algorithmComboBox.DataSource = OKBClient.Instance.Algorithms.Where(x => x.PlatformId == platform.Id).ToList();
79        algorithmComboBox.DisplayMember = "Name";
80      }
81    }
82
83    protected override void OnClosed(FormClosedEventArgs e) {
84      OKBClient.Instance.Refreshing -= new EventHandler(OKBClient_Refreshing);
85      OKBClient.Instance.Refreshed -= new EventHandler(OKBClient_Refreshed);
86      base.OnClosed(e);
87    }
88
89    private void OKBClient_Refreshing(object sender, EventArgs e) {
90      if (InvokeRequired) {
91        Invoke(new EventHandler(OKBClient_Refreshing), sender, e);
92      } else {
93        Cursor = Cursors.AppStarting;
94        algorithmComboBox.Enabled = refreshButton.Enabled = viewHost.Enabled = false;
95      }
96    }
97    private void OKBClient_Refreshed(object sender, EventArgs e) {
98      if (InvokeRequired) {
99        Invoke(new EventHandler(OKBClient_Refreshed), sender, e);
100      } else {
101        PopulateComboBox();
102        SetEnabledStateOfControls();
103        Cursor = Cursors.Default;
104      }
105    }
106
107    #region Content Events
108    private void Content_AlgorithmChanged(object sender, EventArgs e) {
109      if (InvokeRequired)
110        Invoke(new EventHandler(Content_AlgorithmChanged), sender, e);
111      else {
112        algorithmComboBox.SelectedItem = OKBClient.Instance.Algorithms.FirstOrDefault(x => x.Id == Content.AlgorithmId);
113        viewHost.Content = Content.Algorithm;
114      }
115    }
116    #endregion
117
118    #region Control Events
119    private void refreshButton_Click(object sender, System.EventArgs e) {
120      OKBClient.Instance.Refresh();
121    }
122    private void algorithmComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
123      Algorithm algorithm = algorithmComboBox.SelectedValue as Algorithm;
124      if ((algorithm != null) && (Content != null)) {
125        Content.Load(algorithm.Id);
126        if (Content.AlgorithmId != algorithm.Id)  // reset selected item if load was not successful
127          algorithmComboBox.SelectedItem = OKBClient.Instance.Algorithms.FirstOrDefault(x => x.Id == Content.AlgorithmId);
128      }
129    }
130    #endregion
131  }
132}
Note: See TracBrowser for help on using the repository browser.