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 |
|
---|
22 | using System;
|
---|
23 | using System.IO;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Windows.Forms;
|
---|
26 | using HeuristicLab.Common;
|
---|
27 | using HeuristicLab.Core.Views;
|
---|
28 | using HeuristicLab.MainForm;
|
---|
29 | using HeuristicLab.MainForm.WindowsForms;
|
---|
30 | using HeuristicLab.Persistence.Default.Xml;
|
---|
31 | using HeuristicLab.PluginInfrastructure;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.Clients.OKB {
|
---|
34 | [View("Run View")]
|
---|
35 | [Content(typeof(Run), true)]
|
---|
36 | public partial class RunView : ItemView {
|
---|
37 | public new Run Content {
|
---|
38 | get { return (Run)base.Content; }
|
---|
39 | set { base.Content = value; }
|
---|
40 | }
|
---|
41 |
|
---|
42 | public RunView() {
|
---|
43 | InitializeComponent();
|
---|
44 | }
|
---|
45 |
|
---|
46 | protected override void OnContentChanged() {
|
---|
47 | base.OnContentChanged();
|
---|
48 | if (Content == null) {
|
---|
49 | randomSeedTextBox.Text = string.Empty;
|
---|
50 | finishedDateTextBox.Text = string.Empty;
|
---|
51 | userTextBox.Text = string.Empty;
|
---|
52 | clientTextBox.Text = string.Empty;
|
---|
53 | } else {
|
---|
54 | randomSeedTextBox.Text = Content.RandomSeed.ToString();
|
---|
55 | finishedDateTextBox.Text = Content.FinishedDate.ToString();
|
---|
56 | userTextBox.Text = Content.UserId.ToString();
|
---|
57 | clientTextBox.Text = Content.ClientId.ToString();
|
---|
58 | }
|
---|
59 | FillResultsListView();
|
---|
60 | }
|
---|
61 |
|
---|
62 | protected override void SetEnabledStateOfControls() {
|
---|
63 | base.SetEnabledStateOfControls();
|
---|
64 | randomSeedTextBox.Enabled = Content != null;
|
---|
65 | finishedDateTextBox.Enabled = Content != null;
|
---|
66 | userTextBox.Enabled = Content != null;
|
---|
67 | clientTextBox.Enabled = Content != null;
|
---|
68 | resultsGroupBox.Enabled = Content != null;
|
---|
69 | }
|
---|
70 |
|
---|
71 | private void FillResultsListView() {
|
---|
72 | resultsListView.Items.Clear();
|
---|
73 | resultsListView.SmallImageList.Images.Clear();
|
---|
74 | if (Content != null) {
|
---|
75 | foreach (ResultValue resultValue in Content.ResultValues) {
|
---|
76 | Result result = OKBClient.Instance.GetResult(resultValue.ResultId);
|
---|
77 | ListViewItem item = new ListViewItem(result.Name);
|
---|
78 | item.ToolTipText = result.Description;
|
---|
79 | if (resultValue is ResultBoolValue) {
|
---|
80 | item.SubItems.Add(((ResultBoolValue)resultValue).Value.ToString());
|
---|
81 | } else if (resultValue is ResultIntValue) {
|
---|
82 | item.SubItems.Add(((ResultIntValue)resultValue).Value.ToString());
|
---|
83 | } else if (resultValue is ResultFloatValue) {
|
---|
84 | item.SubItems.Add(((ResultFloatValue)resultValue).Value.ToString());
|
---|
85 | } else if (resultValue is ResultStringValue) {
|
---|
86 | item.SubItems.Add(((ResultStringValue)resultValue).Value);
|
---|
87 | } else if (resultValue is ResultBlobValue) {
|
---|
88 | DataType dataType = OKBClient.Instance.DataTypes.FirstOrDefault(x => x.Id == resultValue.DataTypeId);
|
---|
89 | item.SubItems.Add(dataType == null ? "-" : dataType.Name);
|
---|
90 | item.Tag = resultValue;
|
---|
91 | }
|
---|
92 | resultsListView.Items.Add(item);
|
---|
93 | }
|
---|
94 |
|
---|
95 | if (resultsListView.Items.Count > 0) {
|
---|
96 | for (int i = 0; i < resultsListView.Columns.Count; i++)
|
---|
97 | resultsListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
|
---|
98 | }
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | private void resultsListView_DoubleClick(object sender, System.EventArgs e) {
|
---|
103 | if ((resultsListView.SelectedItems.Count == 1) && (resultsListView.SelectedItems[0].Tag != null)) {
|
---|
104 | ResultBlobValue value = resultsListView.SelectedItems[0].Tag as ResultBlobValue;
|
---|
105 | if (value != null) {
|
---|
106 | using (MemoryStream stream = new MemoryStream(value.Value)) {
|
---|
107 | try {
|
---|
108 | MainFormManager.MainForm.ShowContent(XmlParser.Deserialize<IContent>(stream));
|
---|
109 | }
|
---|
110 | catch (Exception ex) {
|
---|
111 | ErrorHandling.ShowErrorDialog(ex);
|
---|
112 | }
|
---|
113 | stream.Close();
|
---|
114 | }
|
---|
115 | }
|
---|
116 | }
|
---|
117 | }
|
---|
118 | }
|
---|
119 | }
|
---|