Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB/HeuristicLab.Clients.OKB-3.3/Views/ExperimentView.cs @ 6618

Last change on this file since 6618 was 4943, checked in by swagner, 14 years ago

Worked on OKB (#1174)

File size: 5.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.Linq;
23using System.Windows.Forms;
24using HeuristicLab.Core.Views;
25using HeuristicLab.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
27
28namespace HeuristicLab.Clients.OKB {
29  [View("Experiment View")]
30  [Content(typeof(Experiment), true)]
31  public partial class ExperimentView : ItemView {
32    public new Experiment Content {
33      get { return (Experiment)base.Content; }
34      set { base.Content = value; }
35    }
36
37    public ExperimentView() {
38      InitializeComponent();
39    }
40
41    protected override void OnContentChanged() {
42      base.OnContentChanged();
43      runCollectionView.Content = null;
44      if (Content == null) {
45        algorithmTextBox.Text = string.Empty;
46        toolTip.SetToolTip(algorithmTextBox, string.Empty);
47        problemTextBox.Text = string.Empty;
48        toolTip.SetToolTip(problemTextBox, string.Empty);
49      } else {
50        Algorithm algorithm = OKBClient.Instance.Algorithms.FirstOrDefault(x => x.Id == Content.AlgorithmId);
51        algorithmTextBox.Text = algorithm == null ? string.Empty : algorithm.Name;
52        toolTip.SetToolTip(algorithmTextBox, algorithm == null ? string.Empty : algorithm.Description);
53        Problem problem = OKBClient.Instance.Problems.FirstOrDefault(x => x.Id == Content.ProblemId);
54        problemTextBox.Text = problem == null ? string.Empty : problem.Name;
55        toolTip.SetToolTip(problemTextBox, problem == null ? string.Empty : problem.Description);
56      }
57      FillParametersListView();
58    }
59
60    protected override void SetEnabledStateOfControls() {
61      base.SetEnabledStateOfControls();
62      algorithmTextBox.Enabled = Content != null;
63      problemTextBox.Enabled = Content != null;
64      parametersListView.Enabled = Content != null;
65      refreshRunsButton.Enabled = Content != null;
66    }
67
68    private void FillParametersListView() {
69      parametersListView.Items.Clear();
70      parametersListView.SmallImageList.Images.Clear();
71      if (Content != null) {
72        foreach (AlgorithmParameterValue parameterValue in Content.AlgorithmParameterValues) {
73          AlgorithmParameter parameter = OKBClient.Instance.GetAlgorithmParameter(parameterValue.AlgorithmParameterId);
74          ListViewItem item = new ListViewItem(parameter.Name);
75          item.ToolTipText = parameter.Description;
76          if (parameterValue is AlgorithmParameterBoolValue) {
77            item.SubItems.Add(((AlgorithmParameterBoolValue)parameterValue).Value.ToString());
78          } else if (parameterValue is AlgorithmParameterIntValue) {
79            item.SubItems.Add(((AlgorithmParameterIntValue)parameterValue).Value.ToString());
80          } else if (parameterValue is AlgorithmParameterFloatValue) {
81            item.SubItems.Add(((AlgorithmParameterFloatValue)parameterValue).Value.ToString());
82          } else if (parameterValue is AlgorithmParameterStringValue) {
83            item.SubItems.Add(((AlgorithmParameterStringValue)parameterValue).Value);
84          } else if (parameterValue is AlgorithmParameterBlobValue) {
85            DataType dataType = OKBClient.Instance.DataTypes.FirstOrDefault(x => x.Id == parameterValue.DataTypeId);
86            item.SubItems.Add(dataType == null ? "-" : dataType.Name);
87          }
88          item.Group = parametersListView.Groups["algorithmParametersGroup"];
89          parametersListView.Items.Add(item);
90        }
91        foreach (ProblemParameterValue parameterValue in Content.ProblemParameterValues) {
92          ProblemParameter parameter = OKBClient.Instance.GetProblemParameter(parameterValue.ProblemParameterId);
93          ListViewItem item = new ListViewItem(parameter.Name);
94          item.ToolTipText = parameter.Description;
95          if (parameterValue is ProblemParameterBoolValue) {
96            item.SubItems.Add(((ProblemParameterBoolValue)parameterValue).Value.ToString());
97          } else if (parameterValue is ProblemParameterIntValue) {
98            item.SubItems.Add(((ProblemParameterIntValue)parameterValue).Value.ToString());
99          } else if (parameterValue is ProblemParameterFloatValue) {
100            item.SubItems.Add(((ProblemParameterFloatValue)parameterValue).Value.ToString());
101          } else if (parameterValue is ProblemParameterStringValue) {
102            item.SubItems.Add(((ProblemParameterStringValue)parameterValue).Value);
103          } else if (parameterValue is ProblemParameterBlobValue) {
104            DataType dataType = OKBClient.Instance.DataTypes.FirstOrDefault(x => x.Id == parameterValue.DataTypeId);
105            item.SubItems.Add(dataType == null ? "-" : dataType.Name);
106          }
107          item.Group = parametersListView.Groups["problemParametersGroup"];
108          parametersListView.Items.Add(item);
109        }
110
111        if (parametersListView.Items.Count > 0) {
112          for (int i = 0; i < parametersListView.Columns.Count; i++)
113            parametersListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
114        }
115      }
116    }
117
118    private void refreshRunsButton_Click(object sender, System.EventArgs e) {
119      runCollectionView.Content = OKBClient.Instance.GetRuns(Content.Id);
120    }
121  }
122}
Note: See TracBrowser for help on using the repository browser.