Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/RunCreation/Views/OKBProblemView.cs @ 5640

Last change on this file since 5640 was 5640, checked in by swagner, 12 years ago

Worked on OKB (#1174)

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