1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2018 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 |
|
---|
22 | using System;
|
---|
23 | using System.ComponentModel;
|
---|
24 | using System.Drawing;
|
---|
25 | using System.Linq;
|
---|
26 | using System.Security.Permissions;
|
---|
27 | using System.Windows.Forms;
|
---|
28 | using HeuristicLab.MainForm;
|
---|
29 | using HeuristicLab.MainForm.WindowsForms;
|
---|
30 | using HeuristicLab.Problems.DataAnalysis.Implementation;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Problems.DataAnalysis.Views {
|
---|
33 |
|
---|
34 | [View("NamedIntervals View")]
|
---|
35 | [Content(typeof(NamedIntervals), true)]
|
---|
36 | public partial class NamedIntervalsView : AsynchronousContentView {
|
---|
37 |
|
---|
38 | public new NamedIntervals Content {
|
---|
39 | get => (NamedIntervals)base.Content;
|
---|
40 | set => base.Content = value;
|
---|
41 | }
|
---|
42 |
|
---|
43 | public DataGridView DataGridView {
|
---|
44 | get => dataGridView;
|
---|
45 | }
|
---|
46 |
|
---|
47 | public NamedIntervalsView() {
|
---|
48 | InitializeComponent();
|
---|
49 | setColumnNames();
|
---|
50 | dataGridView.AutoGenerateColumns = false;
|
---|
51 | dataGridView.AllowUserToAddRows = false;
|
---|
52 | }
|
---|
53 |
|
---|
54 | protected override void OnContentChanged() {
|
---|
55 | base.OnContentChanged();
|
---|
56 | if (Content == null) {
|
---|
57 | DataGridView.Rows.Clear();
|
---|
58 | DataGridView.Columns.Clear();
|
---|
59 | } else if (!DataGridView.IsCurrentCellInEditMode) {
|
---|
60 | UpdateData();
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | protected override void SetEnabledStateOfControls() {
|
---|
65 | base.SetEnabledStateOfControls();
|
---|
66 | dataGridView.Enabled = Content != null;
|
---|
67 | dataGridView.ReadOnly = ReadOnly;
|
---|
68 | }
|
---|
69 |
|
---|
70 | protected void UpdateData() {
|
---|
71 | var variablesCount = Content.VariableIntervals.Count;
|
---|
72 |
|
---|
73 | DataGridViewRow[] rows = new DataGridViewRow[variablesCount];
|
---|
74 | for (var i = 0; i < variablesCount; ++i) {
|
---|
75 | var row = new DataGridViewRow();
|
---|
76 | rows[i] = row;
|
---|
77 | }
|
---|
78 | dataGridView.Rows.AddRange(rows);
|
---|
79 |
|
---|
80 | setRowsHeader();
|
---|
81 | FillRows();
|
---|
82 |
|
---|
83 | dataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.ColumnHeader);
|
---|
84 | dataGridView.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders);
|
---|
85 | dataGridView.Enabled = true;
|
---|
86 |
|
---|
87 | }
|
---|
88 |
|
---|
89 | protected void FillRows() {
|
---|
90 | for (var i = 0; i < dataGridView.RowCount; ++i) {
|
---|
91 | var key = (string)dataGridView.Rows[i].HeaderCell.Value;
|
---|
92 | dataGridView.Rows[i].Cells[0].Value = Content.VariableIntervals[key].LowerBound;
|
---|
93 | dataGridView.Rows[i].Cells[1].Value = Content.VariableIntervals[key].UpperBound;
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | protected void setRowsHeader() {
|
---|
98 | for (var i = 0; i < Content.VariableIntervals.Count; ++i) {
|
---|
99 | var item = Content.VariableIntervals.ElementAt(i);
|
---|
100 | dataGridView.Rows[i].HeaderCell.Value = item.Key;
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | protected void setColumnNames() {
|
---|
105 | dataGridView.Columns.Add("lowerBound", "Lower Bound");
|
---|
106 | dataGridView.Columns.Add("upperBound", "Upper Bound");
|
---|
107 | }
|
---|
108 |
|
---|
109 | private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) {
|
---|
110 |
|
---|
111 | }
|
---|
112 |
|
---|
113 | private void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) {
|
---|
114 | double value;
|
---|
115 |
|
---|
116 | if (!double.TryParse(e.FormattedValue.ToString(), out value)) {
|
---|
117 | dataGridView.Rows[e.RowIndex].ErrorText = "Value has to be a double value";
|
---|
118 | e.Cancel = true;
|
---|
119 | } else if (string.IsNullOrEmpty(e.FormattedValue.ToString())) {
|
---|
120 | dataGridView.Rows[e.RowIndex].ErrorText = "Value has to best";
|
---|
121 | e.Cancel = true;
|
---|
122 | } else if (double.Parse(dataGridView.Rows[e.RowIndex].Cells[0].Value.ToString()) >
|
---|
123 | double.Parse(dataGridView.Rows[e.RowIndex].Cells[1].Value.ToString())) {
|
---|
124 | dataGridView.Rows[e.RowIndex].ErrorText = "Lower Bound of Interval has to be smaller than Upper Bound";
|
---|
125 | e.Cancel = true;
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 | private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) {
|
---|
130 | dataGridView.Rows[e.RowIndex].ErrorText = string.Empty;
|
---|
131 | }
|
---|
132 | }
|
---|
133 | }
|
---|