#region License Information
/* HeuristicLab
* Copyright (C) 2002-2015 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 HeuristicLab.BioBoost.Representation;
using HeuristicLab.Core.Views;
using HeuristicLab.MainForm;
using SharpMap.Data;
using System;
using System.ComponentModel;
using System.Linq;
namespace HeuristicLab.BioBoost.Views {
[Content(typeof(RegionDetailData), IsDefaultView = true)]
public partial class BioBoostRegionDetailView : ItemView {
public new RegionDetailData Content {
get { return (RegionDetailData)base.Content; }
set { base.Content = value; }
}
public BioBoostRegionDetailView() {
InitializeComponent();
}
protected override void DeregisterContentEvents() {
base.DeregisterContentEvents();
}
protected override void RegisterContentEvents() {
base.RegisterContentEvents();
}
protected override void SetEnabledStateOfControls() {
base.SetEnabledStateOfControls();
dataGridView.Enabled = Content != null;
}
protected override void OnContentChanged() {
base.OnContentChanged();
if (Content == null) {
Clear();
} else {
Clear();
Populate(Content.Solution, Content.RegionName);
}
}
public event EventHandler RegionLabelClicked;
protected void OnRegionLabelClicked() {
EventHandler h = RegionLabelClicked;
if (h != null)
h.Invoke(this, EventArgs.Empty);
}
private void Populate(BioBoostCompoundSolution solution, string regionName) {
regionNameLabel.Text = regionName; regionDescriptionLabel.Text = GetRegionDescription(regionName);
var locidx = solution.LocationNames.IndexOfFirst(s => s == regionName);
if (locidx < 0) return;
dataGridView.Rows.Clear();
foreach (var array in solution.DoubleValues) {
dataGridView.Rows.Add(array.Key, array.Value[locidx]);
}
dataGridView.Sort(NameColumn, ListSortDirection.Ascending);
}
private void Clear() {
regionNameLabel.Text = "";
regionDescriptionLabel.Text = "";
dataGridView.Rows.Clear();
}
private string GetRegionDescription(string regionName) {
if (regionName != null && Content.Solution.Geometry.Features.Columns.Contains("name")) {
var row = Content.Solution.Geometry.Features.Rows.Cast().FirstOrDefault(r => (string)r["NUTS_ID"] == regionName);
if (row != null)
return row["name"].ToString();
}
return "";
}
private void regionNameLabel_Click(object sender, EventArgs e) {
OnRegionLabelClicked();
}
}
}