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