Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost.Views/3.3/BioBoostRegionDetailView.cs @ 17097

Last change on this file since 17097 was 13074, checked in by gkronber, 9 years ago

#2499: added license header and removed unused usings

File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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
22using HeuristicLab.BioBoost.Representation;
23using HeuristicLab.Core.Views;
24using HeuristicLab.MainForm;
25using SharpMap.Data;
26using System;
27using System.ComponentModel;
28using System.Linq;
29
30namespace HeuristicLab.BioBoost.Views {
31
32  [Content(typeof(RegionDetailData), IsDefaultView = true)]
33  public partial class BioBoostRegionDetailView : ItemView {
34
35    public new RegionDetailData Content {
36      get { return (RegionDetailData)base.Content; }
37      set { base.Content = value; }
38    }
39
40    public BioBoostRegionDetailView() {
41      InitializeComponent();
42    }
43
44    protected override void DeregisterContentEvents() {
45      base.DeregisterContentEvents();
46    }
47
48    protected override void RegisterContentEvents() {
49      base.RegisterContentEvents();
50    }
51
52    protected override void SetEnabledStateOfControls() {
53      base.SetEnabledStateOfControls();
54      dataGridView.Enabled = Content != null;
55    }
56
57    protected override void OnContentChanged() {
58      base.OnContentChanged();
59      if (Content == null) {
60        Clear();
61      } else {
62        Clear();
63        Populate(Content.Solution, Content.RegionName);
64      }
65    }
66
67    public event EventHandler RegionLabelClicked;
68
69    protected void OnRegionLabelClicked() {
70      EventHandler h = RegionLabelClicked;
71      if (h != null)
72        h.Invoke(this, EventArgs.Empty);
73    }
74
75    private void Populate(BioBoostCompoundSolution solution, string regionName) {
76      regionNameLabel.Text = regionName; regionDescriptionLabel.Text = GetRegionDescription(regionName);
77      var locidx = solution.LocationNames.IndexOfFirst(s => s == regionName);
78      if (locidx < 0) return;
79      dataGridView.Rows.Clear();
80      foreach (var array in solution.DoubleValues) {
81        dataGridView.Rows.Add(array.Key, array.Value[locidx]);
82      }
83      dataGridView.Sort(NameColumn, ListSortDirection.Ascending);
84    }
85
86    private void Clear() {
87      regionNameLabel.Text = "";
88      regionDescriptionLabel.Text = "";
89      dataGridView.Rows.Clear();
90    }
91
92    private string GetRegionDescription(string regionName) {
93      if (regionName != null && Content.Solution.Geometry.Features.Columns.Contains("name")) {
94        var row = Content.Solution.Geometry.Features.Rows.Cast<FeatureDataRow>().FirstOrDefault(r => (string)r["NUTS_ID"] == regionName);
95        if (row != null)
96          return row["name"].ToString();
97      }
98      return "";
99    }
100
101    private void regionNameLabel_Click(object sender, EventArgs e) {
102      OnRegionLabelClicked();
103    }
104  }
105}
Note: See TracBrowser for help on using the repository browser.