1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 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.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Windows.Forms;
|
---|
26 | using HeuristicLab.Common.Resources;
|
---|
27 | using HeuristicLab.Core.Views;
|
---|
28 | using HeuristicLab.Data;
|
---|
29 | using HeuristicLab.MainForm;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Clients.OKB.RunCreation {
|
---|
32 | [View("OKBProblem View")]
|
---|
33 | [Content(typeof(SingleObjectiveOKBProblem), true)]
|
---|
34 | [Content(typeof(MultiObjectiveOKBProblem), true)]
|
---|
35 | public sealed partial class OKBProblemView : NamedItemView {
|
---|
36 | public new OKBProblem Content {
|
---|
37 | get { return (OKBProblem)base.Content; }
|
---|
38 | set { base.Content = value; }
|
---|
39 | }
|
---|
40 |
|
---|
41 | public OKBProblemView() {
|
---|
42 | InitializeComponent();
|
---|
43 | downloadCharacteristicsButton.Text = string.Empty;
|
---|
44 | downloadCharacteristicsButton.Image = VSImageLibrary.Refresh;
|
---|
45 | uploadCharacteristicsButton.Text = string.Empty;
|
---|
46 | uploadCharacteristicsButton.Image = VSImageLibrary.PublishToWeb;
|
---|
47 | }
|
---|
48 |
|
---|
49 | protected override void OnInitialized(System.EventArgs e) {
|
---|
50 | base.OnInitialized(e);
|
---|
51 | RunCreationClient.Instance.Refreshing += new EventHandler(RunCreationClient_Refreshing);
|
---|
52 | RunCreationClient.Instance.Refreshed += new EventHandler(RunCreationClient_Refreshed);
|
---|
53 | PopulateComboBox();
|
---|
54 | }
|
---|
55 |
|
---|
56 | protected override void DeregisterContentEvents() {
|
---|
57 | Content.ProblemChanged -= new EventHandler(Content_ProblemChanged);
|
---|
58 | base.DeregisterContentEvents();
|
---|
59 | }
|
---|
60 | protected override void RegisterContentEvents() {
|
---|
61 | base.RegisterContentEvents();
|
---|
62 | Content.ProblemChanged += new EventHandler(Content_ProblemChanged);
|
---|
63 | }
|
---|
64 |
|
---|
65 | protected override void OnContentChanged() {
|
---|
66 | base.OnContentChanged();
|
---|
67 | if (Content == null) {
|
---|
68 | problemComboBox.SelectedIndex = -1;
|
---|
69 | parameterCollectionView.Content = null;
|
---|
70 | } else {
|
---|
71 | problemComboBox.SelectedItem = RunCreationClient.Instance.Problems.FirstOrDefault(x => x.Id == Content.ProblemId);
|
---|
72 | parameterCollectionView.Content = Content.Parameters;
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | protected override void SetEnabledStateOfControls() {
|
---|
77 | base.SetEnabledStateOfControls();
|
---|
78 | problemComboBox.Enabled = (Content != null) && !ReadOnly && !Locked && (problemComboBox.Items.Count > 0);
|
---|
79 | cloneProblemButton.Enabled = (Content != null) && (Content.ProblemId != -1) && !ReadOnly && !Locked;
|
---|
80 | refreshButton.Enabled = (Content != null) && !ReadOnly && !Locked;
|
---|
81 | parameterCollectionView.Enabled = Content != null;
|
---|
82 | characteristicsMatrixView.Enabled = Content != null;
|
---|
83 | downloadCharacteristicsButton.Enabled = Content != null && Content.ProblemId != -1 && !Locked;
|
---|
84 | uploadCharacteristicsButton.Enabled = Content != null && Content.ProblemId != -1 && !Locked && !ReadOnly
|
---|
85 | && characteristicsMatrixView.Content != null && characteristicsMatrixView.Content.Rows > 0;
|
---|
86 | }
|
---|
87 |
|
---|
88 | protected override void OnClosed(FormClosedEventArgs e) {
|
---|
89 | RunCreationClient.Instance.Refreshing -= new EventHandler(RunCreationClient_Refreshing);
|
---|
90 | RunCreationClient.Instance.Refreshed -= new EventHandler(RunCreationClient_Refreshed);
|
---|
91 | base.OnClosed(e);
|
---|
92 | }
|
---|
93 |
|
---|
94 | private void RunCreationClient_Refreshing(object sender, EventArgs e) {
|
---|
95 | if (InvokeRequired) {
|
---|
96 | Invoke(new EventHandler(RunCreationClient_Refreshing), sender, e);
|
---|
97 | } else {
|
---|
98 | Cursor = Cursors.AppStarting;
|
---|
99 | problemComboBox.Enabled = cloneProblemButton.Enabled = refreshButton.Enabled = parameterCollectionView.Enabled = false;
|
---|
100 | }
|
---|
101 | }
|
---|
102 | private void RunCreationClient_Refreshed(object sender, EventArgs e) {
|
---|
103 | if (InvokeRequired) {
|
---|
104 | Invoke(new EventHandler(RunCreationClient_Refreshed), sender, e);
|
---|
105 | } else {
|
---|
106 | PopulateComboBox();
|
---|
107 | SetEnabledStateOfControls();
|
---|
108 | Cursor = Cursors.Default;
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | #region Content Events
|
---|
113 | private void Content_ProblemChanged(object sender, EventArgs e) {
|
---|
114 | if (InvokeRequired)
|
---|
115 | Invoke(new EventHandler(Content_ProblemChanged), sender, e);
|
---|
116 | else {
|
---|
117 | OnContentChanged();
|
---|
118 | SetEnabledStateOfControls();
|
---|
119 | }
|
---|
120 | }
|
---|
121 | #endregion
|
---|
122 |
|
---|
123 | #region Control Events
|
---|
124 | private void cloneProblemButton_Click(object sender, EventArgs e) {
|
---|
125 | MainFormManager.MainForm.ShowContent(Content.CloneProblem());
|
---|
126 | }
|
---|
127 | private void refreshButton_Click(object sender, System.EventArgs e) {
|
---|
128 | RunCreationClient.Instance.Refresh();
|
---|
129 | }
|
---|
130 | private void problemComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
|
---|
131 | Problem problem = problemComboBox.SelectedValue as Problem;
|
---|
132 | if ((problem != null) && (Content != null)) {
|
---|
133 | Content.Load(problem.Id);
|
---|
134 | if (Content.ProblemId != problem.Id) // reset selected item if load was not successful
|
---|
135 | problemComboBox.SelectedItem = RunCreationClient.Instance.Problems.FirstOrDefault(x => x.Id == Content.ProblemId);
|
---|
136 | }
|
---|
137 | }
|
---|
138 | private void downloadCharacteristicsButton_Click(object sender, EventArgs e) {
|
---|
139 | var values = RunCreationClient.GetCharacteristicValues(Content.ProblemId).ToList();
|
---|
140 | var content = new StringMatrix(values.Count, 3);
|
---|
141 | for (var i = 0; i < values.Count; i++) {
|
---|
142 | content[i, 0] = values[i].Name;
|
---|
143 | content[i, 1] = values[i].ToString();
|
---|
144 | content[i, 2] = values[i].GetType().Name;
|
---|
145 | }
|
---|
146 | characteristicsMatrixView.Content = content;
|
---|
147 | SetEnabledStateOfControls();
|
---|
148 | }
|
---|
149 | private void uploadCharacteristicsButton_Click(object sender, EventArgs e) {
|
---|
150 | var matrix = characteristicsMatrixView.Content as StringMatrix;
|
---|
151 | if (matrix == null) return;
|
---|
152 | var values = new List<Value>(matrix.Rows);
|
---|
153 | for (var i = 0; i < matrix.Rows; i++) {
|
---|
154 | var name = matrix[i, 0];
|
---|
155 | var strValue = matrix[i, 1];
|
---|
156 | var type = matrix[i, 2];
|
---|
157 | values.Add(Value.Create(name, strValue, type));
|
---|
158 | }
|
---|
159 | try {
|
---|
160 | RunCreationClient.SetCharacteristicValues(Content.ProblemId, values);
|
---|
161 | } catch (Exception ex) { PluginInfrastructure.ErrorHandling.ShowErrorDialog(ex); }
|
---|
162 | }
|
---|
163 | #endregion
|
---|
164 |
|
---|
165 | #region Helpers
|
---|
166 | private void PopulateComboBox() {
|
---|
167 | problemComboBox.DataSource = null;
|
---|
168 | problemComboBox.DataSource = RunCreationClient.Instance.Problems.ToList();
|
---|
169 | problemComboBox.DisplayMember = "Name";
|
---|
170 | }
|
---|
171 | #endregion
|
---|
172 | }
|
---|
173 | }
|
---|