Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 7580 was 7331, checked in by ascheibe, 13 years ago

#1174

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