Free cookie consent management tool by TermsFeed Policy Generator

source: branches/MemPRAlgorithm/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingCheckedVariablesView.cs @ 15725

Last change on this file since 15725 was 14562, checked in by abeham, 8 years ago

#2701: Updated branch to trunk

File size: 7.0 KB
RevLine 
[10539]1#region License Information
2/* HeuristicLab
[14185]3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[10539]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
[10717]22using System;
[14384]23using System.Collections.Generic;
[14381]24using System.Drawing;
[12676]25using System.Linq;
[10303]26using System.Windows.Forms;
[10628]27using HeuristicLab.Collections;
[10303]28using HeuristicLab.Core.Views;
[10628]29using HeuristicLab.Data;
[10303]30using HeuristicLab.MainForm;
31
32namespace HeuristicLab.DataPreprocessing.Views {
[14381]33  [View("Preprocessing Checked Variables View")]
[10658]34  [Content(typeof(PreprocessingChartContent), false)]
[14382]35  public abstract partial class PreprocessingCheckedVariablesView : ItemView {
[10377]36
[14381]37    public new PreprocessingChartContent Content {
38      get { return (PreprocessingChartContent)base.Content; }
39      set { base.Content = value; }
40    }
[10717]41
[14381]42    protected PreprocessingCheckedVariablesView() {
[10303]43      InitializeComponent();
44    }
45
[14384]46    protected bool IsVariableChecked(string name) {
[14270]47      return Content.VariableItemList.CheckedItems.Any(x => x.Value.Value == name);
[10628]48    }
[14384]49    protected IList<string> GetCheckedVariables() {
50      return checkedItemList.Content.CheckedItems.Select(i => i.Value.Value).ToList();
51    }
[10628]52
[14381]53    protected override void OnContentChanged() {
54      base.OnContentChanged();
55      if (Content == null) return;
[10573]56
[10992]57      if (Content.VariableItemList == null) {
[14418]58        IList<string> inputs = Content.PreprocessingData.InputVariables;
59        if (Content.PreprocessingData.TargetVariable != null)
[14562]60          inputs = inputs.Union(new[] { Content.PreprocessingData.TargetVariable }).ToList();
[14418]61        Content.VariableItemList = Content.CreateVariableItemList(inputs);
[12676]62      } else {
63        var checkedNames = Content.VariableItemList.CheckedItems.Select(x => x.Value.Value);
[14418]64        Content.VariableItemList = Content.CreateVariableItemList(checkedNames.ToList());
[10818]65      }
[14381]66      Content.VariableItemList.CheckedItemsChanged += CheckedItemsChanged;
67
[10818]68      checkedItemList.Content = Content.VariableItemList;
[14381]69      var target = Content.PreprocessingData.TargetVariable;
70      var inputAndTarget = Content.PreprocessingData.InputVariables.Union(target != null ? new[] { target } : new string[] { });
71      foreach (var col in Content.PreprocessingData.GetDoubleVariableNames().Except(inputAndTarget)) {
[14562]72        var listViewItem = checkedItemList.ItemsListView.FindItemWithText(col, false, 0, false);
[14381]73        listViewItem.ForeColor = Color.LightGray;
[10847]74      }
75    }
[14381]76    protected override void RegisterContentEvents() {
77      base.RegisterContentEvents();
78      Content.PreprocessingData.Changed += PreprocessingData_Changed;
79      Content.PreprocessingData.SelectionChanged += PreprocessingData_SelctionChanged;
[10717]80    }
[14381]81    protected override void DeregisterContentEvents() {
82      Content.PreprocessingData.Changed -= PreprocessingData_Changed;
83      Content.PreprocessingData.SelectionChanged -= PreprocessingData_SelctionChanged;
84      base.DeregisterContentEvents();
[10847]85    }
86
[14381]87    protected virtual void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) {
[10717]88    }
89
[14381]90    private void PreprocessingData_Changed(object sender, DataPreprocessingChangedEventArgs e) {
[10628]91      switch (e.Type) {
92        case DataPreprocessingChangedEventType.DeleteColumn:
[10992]93          RemoveVariable(Content.PreprocessingData.GetVariableName(e.Column));
[10628]94          break;
95        case DataPreprocessingChangedEventType.AddColumn:
[10992]96          AddVariable(Content.PreprocessingData.GetVariableName(e.Column));
[10628]97          break;
98        case DataPreprocessingChangedEventType.ChangeColumn:
99        case DataPreprocessingChangedEventType.ChangeItem:
[14381]100          UpdateVariable(Content.PreprocessingData.GetVariableName(e.Column));
[10628]101          break;
[10817]102        default:
[14381]103          ResetAllVariables();
[10628]104          break;
[10382]105      }
[10377]106    }
107
[14381]108    protected virtual void AddVariable(string name) {
109      Content.VariableItemList.Add(new StringValue(name));
110      if (!Content.PreprocessingData.InputVariables.Contains(name) && Content.PreprocessingData.TargetVariable != name) {
[14562]111        var listViewItem = checkedItemList.ItemsListView.FindItemWithText(name, false, 0, false);
[14381]112        listViewItem.ForeColor = Color.LightGray;
[10736]113      }
[10717]114    }
[14381]115    protected virtual void RemoveVariable(string name) {
116      var stringValue = Content.VariableItemList.SingleOrDefault(n => n.Value == name);
[10628]117      if (stringValue != null)
[10818]118        Content.VariableItemList.Remove(stringValue);
[10377]119    }
[14381]120    protected virtual void UpdateVariable(string name) {
[10628]121    }
[14381]122    protected virtual void ResetAllVariables() {
[10736]123    }
124
[14381]125    protected virtual void PreprocessingData_SelctionChanged(object sender, EventArgs e) {
[10804]126    }
[10717]127
[14381]128    #region ContextMenu Events
129    private void variablesListcontextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e) {
130      var data = Content.PreprocessingData;
131      checkInputsTargetToolStripMenuItem.Text = "Check Inputs" + (data.TargetVariable != null ? "+Target" : "");
132      checkOnlyInputsTargetToolStripMenuItem.Text = "Check only Inputs" + (data.TargetVariable != null ? "+Target" : "");
[10717]133    }
[14381]134    private void checkInputsTargetToolStripMenuItem_Click(object sender, EventArgs e) {
135      foreach (var name in checkedItemList.Content) {
136        var isInputTarget = Content.PreprocessingData.InputVariables.Contains(name.Value) || Content.PreprocessingData.TargetVariable == name.Value;
137        if (isInputTarget) {
138          checkedItemList.Content.SetItemCheckedState(name, true);
[10717]139        }
140      }
141    }
[14381]142    private void checkOnlyInputsTargetToolStripMenuItem_Click(object sender, EventArgs e) {
143      foreach (var name in checkedItemList.Content) {
144        var isInputTarget = Content.PreprocessingData.InputVariables.Contains(name.Value) || Content.PreprocessingData.TargetVariable == name.Value;
145        checkedItemList.Content.SetItemCheckedState(name, isInputTarget);
[10972]146      }
147    }
[14381]148    private void checkAllToolStripMenuItem_Click(object sender, EventArgs e) {
149      foreach (var name in checkedItemList.Content) {
150        checkedItemList.Content.SetItemCheckedState(name, true);
[10717]151      }
152    }
[14381]153    private void uncheckAllToolStripMenuItem_Click(object sender, EventArgs e) {
154      foreach (var name in checkedItemList.Content) {
155        checkedItemList.Content.SetItemCheckedState(name, false);
156      }
157    }
158    #endregion
[10303]159  }
160}
161
162
Note: See TracBrowser for help on using the repository browser.