Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost.Views/3.3/BioBoostRegionDetailView.cs @ 13072

Last change on this file since 13072 was 13072, checked in by gkronber, 7 years ago

#2499: added code from HeuristicLab.BioBoost.Views (from private repository) nothing much has been changed

File size: 2.7 KB
Line 
1using System.Globalization;
2using HeuristicLab.BioBoost.Representation;
3using HeuristicLab.Core.Views;
4using HeuristicLab.Data;
5using HeuristicLab.MainForm;
6using SharpMap.Data;
7using System;
8using System.Collections.Generic;
9using System.ComponentModel;
10using System.Linq;
11using System.Linq.Expressions;
12using System.Windows.Forms;
13using System.Windows.Forms.DataVisualization.Charting;
14
15namespace 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}
Note: See TracBrowser for help on using the repository browser.