1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2013 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.Linq;
|
---|
23 | using HeuristicLab.Core.Views;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.DataPreprocessing.Filter;
|
---|
27 | using HeuristicLab.MainForm;
|
---|
28 | using System.Collections;
|
---|
29 | using System;
|
---|
30 | using System.Collections.Generic;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
33 | [View("Comparison Filter View")]
|
---|
34 | [Content(typeof(ComparisonFilter), false)]
|
---|
35 | public partial class ComparisonFilterView : ItemView {
|
---|
36 | public ComparisonFilterView() {
|
---|
37 | InitializeComponent();
|
---|
38 | }
|
---|
39 |
|
---|
40 | public new ComparisonFilter Content {
|
---|
41 | get { return (ComparisonFilter)base.Content; }
|
---|
42 | set { base.Content = value; }
|
---|
43 | }
|
---|
44 |
|
---|
45 |
|
---|
46 | protected override void OnContentChanged()
|
---|
47 | {
|
---|
48 | base.OnContentChanged();
|
---|
49 | cbAttr.Items.Clear(); //cmbConstraintColumn.Items.Clear();
|
---|
50 | cbFilterOperation.Items.Clear(); //cmbConstraintOperation.Items.Clear();
|
---|
51 | tbFilterData.Text = string.Empty;
|
---|
52 | if (Content != null)
|
---|
53 | {
|
---|
54 | cbFilterOperation.Items.AddRange(Content.AllowedConstraintOperations.ToArray());
|
---|
55 | if (Content.ConstraintOperation != null)
|
---|
56 | cbFilterOperation.SelectedItem = Content.ConstraintOperation;
|
---|
57 | else if (cbFilterOperation.Items.Count != 0)
|
---|
58 | cbFilterOperation.SelectedIndex = 0;
|
---|
59 | UpdateColumnComboBox();
|
---|
60 | ReadOnly = Content.Active;
|
---|
61 | if (Content.ConstraintData != null)
|
---|
62 | {
|
---|
63 | tbFilterData.Text = Content.ConstraintData.GetValue();
|
---|
64 | }
|
---|
65 | else
|
---|
66 | {
|
---|
67 | this.Content_ConstraintColumnChanged(cbAttr, EventArgs.Empty); // TODO
|
---|
68 | }
|
---|
69 | }
|
---|
70 | if (Content == null || Content.ConstraintData == null)
|
---|
71 | {
|
---|
72 | tbFilterData.Text = string.Empty;
|
---|
73 | }
|
---|
74 | else
|
---|
75 | {
|
---|
76 | tbFilterData.Text = Content.ConstraintData.GetValue();
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | protected virtual void UpdateColumnComboBox()
|
---|
81 | {
|
---|
82 | this.cbAttr.Items.Clear();
|
---|
83 | if (Content.ConstrainedValue != null)
|
---|
84 | {
|
---|
85 | this.cbAttr.Items.AddRange(Content.ConstrainedValue.VariableNames.ToArray<string>());
|
---|
86 | //if (!string.IsNullOrEmpty(Content.ConstraintColumn))
|
---|
87 | this.cbAttr.SelectedItem = this.cbAttr.Items[Content.ConstraintColumn];
|
---|
88 |
|
---|
89 | if (Content.ConstraintColumn != null)
|
---|
90 | {
|
---|
91 | cbAttr.SelectedItem = Content.ConstraintColumn;
|
---|
92 | if (Content.ConstraintData != null)
|
---|
93 | tbFilterData.Text = Content.ConstraintData.GetValue();
|
---|
94 | else
|
---|
95 | this.Content_ConstraintColumnChanged(cbAttr, EventArgs.Empty);
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | protected override void RegisterContentEvents()
|
---|
101 | {
|
---|
102 | base.RegisterContentEvents();
|
---|
103 | this.Content.ActiveChanged += new EventHandler(Content_ActiveChanged);
|
---|
104 | this.Content.ConstraintOperationChanged += new EventHandler(Content_ComparisonOperationChanged);
|
---|
105 | this.Content.ConstraintColumnChanged += new EventHandler(Content_ConstraintColumnChanged);
|
---|
106 | this.Content.ConstrainedValueChanged += new EventHandler(Content_ConstrainedValueChanged);
|
---|
107 | this.Content.ConstraintDataChanged += new EventHandler(Content_ConstrainedDataChanged);
|
---|
108 | }
|
---|
109 |
|
---|
110 | protected override void DeregisterContentEvents()
|
---|
111 | {
|
---|
112 | base.DeregisterContentEvents();
|
---|
113 | this.Content.ActiveChanged -= new EventHandler(Content_ActiveChanged);
|
---|
114 | this.Content.ConstraintOperationChanged -= new EventHandler(Content_ComparisonOperationChanged);
|
---|
115 | this.Content.ConstraintColumnChanged -= new EventHandler(Content_ConstraintColumnChanged);
|
---|
116 | this.Content.ConstrainedValueChanged -= new EventHandler(Content_ConstrainedValueChanged);
|
---|
117 | this.Content.ConstraintDataChanged -= new EventHandler(Content_ConstrainedDataChanged);
|
---|
118 | }
|
---|
119 |
|
---|
120 | protected virtual void Content_ConstrainedValueChanged(object sender, EventArgs e)
|
---|
121 | {
|
---|
122 | this.UpdateColumnComboBox();
|
---|
123 | }
|
---|
124 |
|
---|
125 | private void Content_ConstrainedDataChanged(object sender, EventArgs e)
|
---|
126 | {
|
---|
127 | if (Content.ConstraintData != null)
|
---|
128 | tbFilterData.Text = Content.ConstraintData.GetValue();
|
---|
129 | else
|
---|
130 | tbFilterData.Text = string.Empty;
|
---|
131 | }
|
---|
132 |
|
---|
133 | protected virtual void Content_ConstraintColumnChanged(object sender, EventArgs e)
|
---|
134 | {
|
---|
135 | if (Content.ConstrainedValue != null)
|
---|
136 | {
|
---|
137 | if (cbAttr.Items.IndexOf(cbAttr.SelectedItem) != Content.ConstraintColumn)
|
---|
138 | {
|
---|
139 | cbAttr.SelectedItem = this.cbAttr.Items[Content.ConstraintColumn];
|
---|
140 | }
|
---|
141 | }
|
---|
142 | if (Content.ConstraintData == null)
|
---|
143 | this.Content.ConstraintData = new StringValue();
|
---|
144 | }
|
---|
145 |
|
---|
146 |
|
---|
147 | protected virtual void Content_ComparisonOperationChanged(object sender, EventArgs e)
|
---|
148 | {
|
---|
149 | if (Content.ConstraintOperation != (ConstraintOperation)this.cbFilterOperation.SelectedItem)
|
---|
150 | this.cbFilterOperation.SelectedItem = Content.ConstraintOperation;
|
---|
151 | }
|
---|
152 |
|
---|
153 | protected override void SetEnabledStateOfControls()
|
---|
154 | {
|
---|
155 | base.SetEnabledStateOfControls();
|
---|
156 | /*
|
---|
157 | cbAttr.Enabled = !this.ReadOnly && Content != null;
|
---|
158 | cbFilterOperation.Enabled = !this.ReadOnly && Content != null;
|
---|
159 | tbFilterData.Enabled = Content != null;
|
---|
160 | tbFilterData.ReadOnly = ReadOnly;
|
---|
161 | * */
|
---|
162 | cbAttr.Enabled = Content != null && !Content.Active;
|
---|
163 | cbFilterOperation.Enabled = Content != null && !Content.Active;
|
---|
164 | tbFilterData.Enabled = Content != null && !Content.Active;
|
---|
165 | }
|
---|
166 |
|
---|
167 | private void cbAttr_SelectedIndexChanged(object sender, EventArgs e)
|
---|
168 | {
|
---|
169 | if (Content.ConstrainedValue != null)
|
---|
170 | {
|
---|
171 | Content.ConstraintColumn = Content.ConstrainedValue.GetColumnIndex(cbAttr.SelectedItem.ToString());
|
---|
172 | }
|
---|
173 | }
|
---|
174 |
|
---|
175 | private void cbFilterOperation_SelectedIndexChanged(object sender, EventArgs e)
|
---|
176 | {
|
---|
177 | Content.ConstraintOperation = (ConstraintOperation)this.cbFilterOperation.SelectedItem;
|
---|
178 | }
|
---|
179 |
|
---|
180 | protected virtual void Content_ActiveChanged(object sender, EventArgs e)
|
---|
181 | {
|
---|
182 | this.ReadOnly = !Content.Active;
|
---|
183 | SetEnabledStateOfControls();
|
---|
184 | Refresh(); ResumeRepaint(true);
|
---|
185 | }
|
---|
186 |
|
---|
187 | private void tbFilterData_Validated(object sender, EventArgs e)
|
---|
188 | {
|
---|
189 | IStringConvertibleValue value = new StringValue();
|
---|
190 | value.SetValue(tbFilterData.Text);
|
---|
191 | Content.ConstraintData = value;
|
---|
192 | }
|
---|
193 |
|
---|
194 | private void tbFilterData_Validating(object sender, System.ComponentModel.CancelEventArgs e)
|
---|
195 | {
|
---|
196 | string errorMessage = string.Empty;
|
---|
197 | if (!Content.ConstraintData.Validate(tbFilterData.Text, out errorMessage))
|
---|
198 | {
|
---|
199 | errorProvider.SetError(tbFilterData, errorMessage);
|
---|
200 | e.Cancel = true;
|
---|
201 | }
|
---|
202 | else
|
---|
203 | errorProvider.Clear();
|
---|
204 | }
|
---|
205 |
|
---|
206 | }
|
---|
207 | }
|
---|