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