[8055] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Linq;
|
---|
| 24 | using System.Windows.Forms;
|
---|
| 25 | using HeuristicLab.Core.Views;
|
---|
| 26 | using HeuristicLab.MainForm;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Clients.OKB.RunCreation {
|
---|
| 29 | [View("OKBProblem View")]
|
---|
| 30 | [Content(typeof(SingleObjectiveOKBProblem), true)]
|
---|
| 31 | [Content(typeof(MultiObjectiveOKBProblem), true)]
|
---|
| 32 | public sealed partial class OKBProblemView : NamedItemView {
|
---|
| 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 | parameterCollectionView.Content = null;
|
---|
| 63 | } else {
|
---|
| 64 | problemComboBox.SelectedItem = RunCreationClient.Instance.Problems.FirstOrDefault(x => x.Id == Content.ProblemId);
|
---|
| 65 | parameterCollectionView.Content = Content.Parameters;
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | protected override void SetEnabledStateOfControls() {
|
---|
| 70 | base.SetEnabledStateOfControls();
|
---|
| 71 | problemComboBox.Enabled = (Content != null) && !ReadOnly && !Locked && (problemComboBox.Items.Count > 0);
|
---|
| 72 | cloneProblemButton.Enabled = (Content != null) && (Content.ProblemId != -1) && !ReadOnly && !Locked;
|
---|
| 73 | refreshButton.Enabled = (Content != null) && !ReadOnly && !Locked;
|
---|
| 74 | parameterCollectionView.Enabled = Content != null;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | protected override void OnClosed(FormClosedEventArgs e) {
|
---|
| 78 | RunCreationClient.Instance.Refreshing -= new EventHandler(RunCreationClient_Refreshing);
|
---|
| 79 | RunCreationClient.Instance.Refreshed -= new EventHandler(RunCreationClient_Refreshed);
|
---|
| 80 | base.OnClosed(e);
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | private void RunCreationClient_Refreshing(object sender, EventArgs e) {
|
---|
| 84 | if (InvokeRequired) {
|
---|
| 85 | Invoke(new EventHandler(RunCreationClient_Refreshing), sender, e);
|
---|
| 86 | } else {
|
---|
| 87 | Cursor = Cursors.AppStarting;
|
---|
| 88 | problemComboBox.Enabled = cloneProblemButton.Enabled = refreshButton.Enabled = parameterCollectionView.Enabled = false;
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 | private void RunCreationClient_Refreshed(object sender, EventArgs e) {
|
---|
| 92 | if (InvokeRequired) {
|
---|
| 93 | Invoke(new EventHandler(RunCreationClient_Refreshed), sender, e);
|
---|
| 94 | } else {
|
---|
| 95 | PopulateComboBox();
|
---|
| 96 | SetEnabledStateOfControls();
|
---|
| 97 | Cursor = Cursors.Default;
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | #region Content Events
|
---|
| 102 | private void Content_ProblemChanged(object sender, EventArgs e) {
|
---|
| 103 | if (InvokeRequired)
|
---|
| 104 | Invoke(new EventHandler(Content_ProblemChanged), sender, e);
|
---|
| 105 | else
|
---|
| 106 | OnContentChanged();
|
---|
| 107 | }
|
---|
| 108 | #endregion
|
---|
| 109 |
|
---|
| 110 | #region Control Events
|
---|
| 111 | private void cloneProblemButton_Click(object sender, EventArgs e) {
|
---|
| 112 | MainFormManager.MainForm.ShowContent(Content.CloneProblem());
|
---|
| 113 | }
|
---|
| 114 | private void refreshButton_Click(object sender, System.EventArgs e) {
|
---|
| 115 | RunCreationClient.Instance.Refresh();
|
---|
| 116 | }
|
---|
| 117 | private void problemComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
|
---|
| 118 | Problem problem = problemComboBox.SelectedValue as Problem;
|
---|
| 119 | if ((problem != null) && (Content != null)) {
|
---|
| 120 | Content.Load(problem.Id);
|
---|
| 121 | if (Content.ProblemId != problem.Id) // reset selected item if load was not successful
|
---|
| 122 | problemComboBox.SelectedItem = RunCreationClient.Instance.Problems.FirstOrDefault(x => x.Id == Content.ProblemId);
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 | #endregion
|
---|
| 126 |
|
---|
| 127 | #region Helpers
|
---|
| 128 | private void PopulateComboBox() {
|
---|
| 129 | problemComboBox.DataSource = null;
|
---|
| 130 | problemComboBox.DataSource = RunCreationClient.Instance.Problems.ToList();
|
---|
| 131 | problemComboBox.DisplayMember = "Name";
|
---|
| 132 | }
|
---|
| 133 | #endregion
|
---|
| 134 | }
|
---|
| 135 | }
|
---|