#region License Information
/* HeuristicLab
* Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using HeuristicLab.Common;
using HeuristicLab.Core.Views;
using HeuristicLab.MainForm;
using HeuristicLab.MainForm.WindowsForms;
using HeuristicLab.Persistence.Default.Xml;
using HeuristicLab.PluginInfrastructure;
namespace HeuristicLab.Clients.OKB {
[View("Run View")]
[Content(typeof(Run), true)]
public partial class RunView : ItemView {
public new Run Content {
get { return (Run)base.Content; }
set { base.Content = value; }
}
public RunView() {
InitializeComponent();
}
protected override void OnContentChanged() {
base.OnContentChanged();
if (Content == null) {
randomSeedTextBox.Text = string.Empty;
createdDateTextBox.Text = string.Empty;
userTextBox.Text = string.Empty;
clientTextBox.Text = string.Empty;
} else {
randomSeedTextBox.Text = Content.RandomSeed.ToString();
createdDateTextBox.Text = Content.CreatedDate.ToString();
userTextBox.Text = Content.UserId.ToString();
clientTextBox.Text = Content.ClientId.ToString();
}
FillResultsListView();
}
protected override void SetEnabledStateOfControls() {
base.SetEnabledStateOfControls();
randomSeedTextBox.Enabled = Content != null;
createdDateTextBox.Enabled = Content != null;
userTextBox.Enabled = Content != null;
clientTextBox.Enabled = Content != null;
resultsGroupBox.Enabled = Content != null;
}
private void FillResultsListView() {
resultsListView.Items.Clear();
resultsListView.SmallImageList.Images.Clear();
if (Content != null) {
foreach (ResultValue resultValue in Content.ResultValues) {
Result result = OKBClient.Instance.GetResult(resultValue.ResultId);
ListViewItem item = new ListViewItem(result.Name);
item.ToolTipText = result.Description;
if (resultValue is ResultBoolValue) {
item.SubItems.Add(((ResultBoolValue)resultValue).Value.ToString());
} else if (resultValue is ResultIntValue) {
item.SubItems.Add(((ResultIntValue)resultValue).Value.ToString());
} else if (resultValue is ResultFloatValue) {
item.SubItems.Add(((ResultFloatValue)resultValue).Value.ToString());
} else if (resultValue is ResultStringValue) {
item.SubItems.Add(((ResultStringValue)resultValue).Value);
} else if (resultValue is ResultBlobValue) {
DataType dataType = OKBClient.Instance.DataTypes.FirstOrDefault(x => x.Id == resultValue.DataTypeId);
item.SubItems.Add(dataType == null ? "-" : dataType.Name);
item.Tag = resultValue;
}
resultsListView.Items.Add(item);
}
if (resultsListView.Items.Count > 0) {
for (int i = 0; i < resultsListView.Columns.Count; i++)
resultsListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
}
}
}
private void resultsListView_DoubleClick(object sender, System.EventArgs e) {
if ((resultsListView.SelectedItems.Count == 1) && (resultsListView.SelectedItems[0].Tag != null)) {
ResultBlobValue value = resultsListView.SelectedItems[0].Tag as ResultBlobValue;
if (value != null) {
using (MemoryStream stream = new MemoryStream(value.Value)) {
try {
MainFormManager.MainForm.ShowContent(XmlParser.Deserialize(stream));
}
catch (Exception ex) {
ErrorHandling.ShowErrorDialog(ex);
}
stream.Close();
}
}
}
}
}
}