1 | using System.Globalization;
|
---|
2 | using HeuristicLab.BioBoost.Representation;
|
---|
3 | using HeuristicLab.Core.Views;
|
---|
4 | using HeuristicLab.Data;
|
---|
5 | using HeuristicLab.MainForm;
|
---|
6 | using SharpMap.Data;
|
---|
7 | using System;
|
---|
8 | using System.Collections.Generic;
|
---|
9 | using System.ComponentModel;
|
---|
10 | using System.Linq;
|
---|
11 | using System.Linq.Expressions;
|
---|
12 | using System.Windows.Forms;
|
---|
13 | using System.Windows.Forms.DataVisualization.Charting;
|
---|
14 |
|
---|
15 | namespace HeuristicLab.BioBoost.Views {
|
---|
16 |
|
---|
17 | [Content(typeof(RegionDetailData), IsDefaultView = true)]
|
---|
18 | public partial class BioBoostRegionDetailView : ItemView {
|
---|
19 |
|
---|
20 | public new RegionDetailData Content {
|
---|
21 | get { return (RegionDetailData)base.Content; }
|
---|
22 | set { base.Content = value; }
|
---|
23 | }
|
---|
24 |
|
---|
25 | public BioBoostRegionDetailView() {
|
---|
26 | InitializeComponent();
|
---|
27 | }
|
---|
28 |
|
---|
29 | protected override void DeregisterContentEvents() {
|
---|
30 | base.DeregisterContentEvents();
|
---|
31 | }
|
---|
32 |
|
---|
33 | protected override void RegisterContentEvents() {
|
---|
34 | base.RegisterContentEvents();
|
---|
35 | }
|
---|
36 |
|
---|
37 | protected override void SetEnabledStateOfControls() {
|
---|
38 | base.SetEnabledStateOfControls();
|
---|
39 | dataGridView.Enabled = Content != null;
|
---|
40 | }
|
---|
41 |
|
---|
42 | protected override void OnContentChanged() {
|
---|
43 | base.OnContentChanged();
|
---|
44 | if (Content == null) {
|
---|
45 | Clear();
|
---|
46 | } else {
|
---|
47 | Clear();
|
---|
48 | Populate(Content.Solution, Content.RegionName);
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | public event EventHandler RegionLabelClicked;
|
---|
53 |
|
---|
54 | protected void OnRegionLabelClicked() {
|
---|
55 | EventHandler h = RegionLabelClicked;
|
---|
56 | if (h != null)
|
---|
57 | h.Invoke(this, EventArgs.Empty);
|
---|
58 | }
|
---|
59 |
|
---|
60 | private void Populate(BioBoostCompoundSolution solution, string regionName) {
|
---|
61 | regionNameLabel.Text = regionName; regionDescriptionLabel.Text = GetRegionDescription(regionName);
|
---|
62 | var locidx = solution.LocationNames.IndexOfFirst(s => s == regionName);
|
---|
63 | if (locidx < 0) return;
|
---|
64 | dataGridView.Rows.Clear();
|
---|
65 | foreach (var array in solution.DoubleValues) {
|
---|
66 | dataGridView.Rows.Add(array.Key, array.Value[locidx]);
|
---|
67 | }
|
---|
68 | dataGridView.Sort(NameColumn, ListSortDirection.Ascending);
|
---|
69 | }
|
---|
70 |
|
---|
71 | private void Clear() {
|
---|
72 | regionNameLabel.Text = "";
|
---|
73 | regionDescriptionLabel.Text = "";
|
---|
74 | dataGridView.Rows.Clear();
|
---|
75 | }
|
---|
76 |
|
---|
77 | private string GetRegionDescription(string regionName) {
|
---|
78 | if (regionName != null && Content.Solution.Geometry.Features.Columns.Contains("name")) {
|
---|
79 | var row = Content.Solution.Geometry.Features.Rows.Cast<FeatureDataRow>().FirstOrDefault(r => (string)r["NUTS_ID"] == regionName);
|
---|
80 | if (row != null)
|
---|
81 | return row["name"].ToString();
|
---|
82 | }
|
---|
83 | return "";
|
---|
84 | }
|
---|
85 |
|
---|
86 | private void regionNameLabel_Click(object sender, EventArgs e) {
|
---|
87 | OnRegionLabelClicked();
|
---|
88 | }
|
---|
89 | }
|
---|
90 | }
|
---|