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 |
|
---|
31 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
32 | [View("Comparison Filter View")]
|
---|
33 | [Content(typeof(ComparisonFilter), false)]
|
---|
34 | public partial class ComparisonFilterView : ItemView {
|
---|
35 | public ComparisonFilterView() {
|
---|
36 | InitializeComponent();
|
---|
37 | }
|
---|
38 |
|
---|
39 | public new ComparisonFilter Content {
|
---|
40 | get { return (ComparisonFilter)base.Content; }
|
---|
41 | set { base.Content = value; }
|
---|
42 | }
|
---|
43 |
|
---|
44 |
|
---|
45 | protected override void OnContentChanged()
|
---|
46 | {
|
---|
47 | base.OnContentChanged();
|
---|
48 | cbAttr.Items.Clear(); //cmbConstraintColumn.Items.Clear();
|
---|
49 | cbFilterOperation.Items.Clear(); //cmbConstraintOperation.Items.Clear();
|
---|
50 | tbFilterData.Text = string.Empty;
|
---|
51 | if (Content != null)
|
---|
52 | {
|
---|
53 | cbFilterOperation.Items.AddRange(Content.AllowedConstraintOperations.ToArray());
|
---|
54 | if (Content.ConstraintOperation != null)
|
---|
55 | cbFilterOperation.SelectedItem = Content.ConstraintOperation;
|
---|
56 | else if (cbFilterOperation.Items.Count != 0)
|
---|
57 | cbFilterOperation.SelectedIndex = 0;
|
---|
58 | UpdateColumnComboBox();
|
---|
59 | ReadOnly = Content.Active;
|
---|
60 | if (Content.ConstraintData != null)
|
---|
61 | {
|
---|
62 | tbFilterData.Text = Content.ConstraintData.GetValue();
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | protected virtual void UpdateColumnComboBox()
|
---|
68 | {
|
---|
69 | this.cbAttr.Items.Clear();
|
---|
70 | if (Content.ConstrainedValue != null)
|
---|
71 | {
|
---|
72 | this.cbAttr.Items.AddRange(Content.ConstrainedValue.VariableNames.ToArray<string>());
|
---|
73 | //if (!string.IsNullOrEmpty(Content.ConstraintColumn))
|
---|
74 | this.cbAttr.SelectedItem = Content.ConstraintColumn;
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | protected override void RegisterContentEvents()
|
---|
79 | {
|
---|
80 | base.RegisterContentEvents();
|
---|
81 | this.Content.ActiveChanged += new EventHandler(Content_ActiveChanged);
|
---|
82 | this.Content.ConstraintOperationChanged += new EventHandler(Content_ComparisonOperationChanged);
|
---|
83 | this.Content.ConstraintColumnChanged += new EventHandler(Content_ConstraintColumnChanged);
|
---|
84 | this.Content.ConstrainedValueChanged += new EventHandler(Content_ConstrainedValueChanged);
|
---|
85 | }
|
---|
86 |
|
---|
87 | protected override void DeregisterContentEvents()
|
---|
88 | {
|
---|
89 | base.DeregisterContentEvents();
|
---|
90 | this.Content.ActiveChanged -= new EventHandler(Content_ActiveChanged);
|
---|
91 | this.Content.ConstraintOperationChanged -= new EventHandler(Content_ComparisonOperationChanged);
|
---|
92 | this.Content.ConstraintColumnChanged -= new EventHandler(Content_ConstraintColumnChanged);
|
---|
93 | this.Content.ConstrainedValueChanged += new EventHandler(Content_ConstrainedValueChanged);
|
---|
94 | }
|
---|
95 |
|
---|
96 | protected virtual void Content_ConstrainedValueChanged(object sender, EventArgs e)
|
---|
97 | {
|
---|
98 | this.UpdateColumnComboBox();
|
---|
99 | }
|
---|
100 |
|
---|
101 | protected virtual void Content_ConstraintColumnChanged(object sender, EventArgs e)
|
---|
102 | {
|
---|
103 | if (Content.ConstrainedValue != null)
|
---|
104 | {
|
---|
105 | cbAttr.SelectedItem = Content.ConstraintColumn;
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | protected virtual void Content_ComparisonOperationChanged(object sender, EventArgs e)
|
---|
110 | {
|
---|
111 | if (Content.ConstraintOperation != (ConstraintOperation)this.cbFilterOperation.SelectedItem)
|
---|
112 | this.cbFilterOperation.SelectedItem = Content.ConstraintOperation;
|
---|
113 | }
|
---|
114 |
|
---|
115 | protected override void SetEnabledStateOfControls()
|
---|
116 | {
|
---|
117 | base.SetEnabledStateOfControls();
|
---|
118 | cbAttr.Enabled = !this.ReadOnly && Content != null;
|
---|
119 | cbFilterOperation.Enabled = !this.ReadOnly && Content != null;
|
---|
120 | }
|
---|
121 |
|
---|
122 | private void cbAttr_SelectedIndexChanged(object sender, EventArgs e)
|
---|
123 | {
|
---|
124 | if (Content.ConstrainedValue != null)
|
---|
125 | {
|
---|
126 | Content.ConstraintColumn = Content.ConstrainedValue.GetColumnIndex(cbAttr.SelectedItem.ToString());
|
---|
127 | }
|
---|
128 | }
|
---|
129 |
|
---|
130 | private void cbFilterOperation_SelectedIndexChanged(object sender, EventArgs e)
|
---|
131 | {
|
---|
132 | Content.ConstraintOperation = (ConstraintOperation)this.cbFilterOperation.SelectedItem;
|
---|
133 | }
|
---|
134 |
|
---|
135 | protected virtual void Content_ActiveChanged(object sender, EventArgs e)
|
---|
136 | {
|
---|
137 | this.ReadOnly = Content.Active;
|
---|
138 | }
|
---|
139 |
|
---|
140 | }
|
---|
141 | }
|
---|