Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingCheckedVariablesView.cs @ 14514

Last change on this file since 14514 was 14511, checked in by pfleck, 7 years ago

#2709

  • Added Check Inputs/All/None buttons instead of showing disabled buttons of the ItemCollectionView.
  • Removed the PreprocessingCheckedItemListView. A standard ListView is used instead.
  • Fixed slow updating when simultaneously (un-)checking multiple variables in the chart views. (currently only works by using the new buttons)
File size: 6.7 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
[14384]22using System.Collections.Generic;
[14381]23using System.Drawing;
[12676]24using System.Linq;
[10303]25using System.Windows.Forms;
[10628]26using HeuristicLab.Collections;
[14511]27using HeuristicLab.Common.Resources;
[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)]
[14459]35  public partial class PreprocessingCheckedVariablesView : ItemView {
[10377]36
[14511]37    protected bool suppressCheckedChangedUpdate = false;
38
[14381]39    public new PreprocessingChartContent Content {
40      get { return (PreprocessingChartContent)base.Content; }
41      set { base.Content = value; }
42    }
[10717]43
[14381]44    protected PreprocessingCheckedVariablesView() {
[10303]45      InitializeComponent();
[14511]46      checkInputsTargetButton.Text = string.Empty;
47      checkInputsTargetButton.Image = VSImageLibrary.Namespace;
48      checkAllButton.Text = string.Empty;
49      checkAllButton.Image = VSImageLibrary.Expand;
50      uncheckAllButton.Text = string.Empty;
51      uncheckAllButton.Image = VSImageLibrary.Collapse;
[10303]52    }
53
[14384]54    protected bool IsVariableChecked(string name) {
[14270]55      return Content.VariableItemList.CheckedItems.Any(x => x.Value.Value == name);
[10628]56    }
[14384]57    protected IList<string> GetCheckedVariables() {
[14511]58      return Content.VariableItemList.CheckedItems.Select(i => i.Value.Value).ToList();
[14384]59    }
[10628]60
[14381]61    protected override void OnContentChanged() {
62      base.OnContentChanged();
63      if (Content == null) return;
[10573]64
[14511]65      variablesListView.ItemChecked -= variablesListView_ItemChecked;
66      variablesListView.Items.Clear();
67      foreach (var variable in Content.VariableItemList) {
68        bool isInputTarget = Content.PreprocessingData.InputVariables.Contains(variable.Value)
69          || Content.PreprocessingData.TargetVariable == variable.Value;
70        variablesListView.Items.Add(new ListViewItem(variable.Value) {
71          Tag = variable,
72          Checked = IsVariableChecked(variable.Value),
73          ForeColor = isInputTarget ? Color.Black : Color.Gray
74        });
[10818]75      }
[14511]76      variablesListView.ItemChecked += variablesListView_ItemChecked;
[10847]77    }
[14381]78    protected override void RegisterContentEvents() {
79      base.RegisterContentEvents();
80      Content.PreprocessingData.Changed += PreprocessingData_Changed;
[14511]81      Content.VariableItemList.CheckedItemsChanged += CheckedItemsChanged;
[10717]82    }
[14511]83
[14381]84    protected override void DeregisterContentEvents() {
85      Content.PreprocessingData.Changed -= PreprocessingData_Changed;
[14511]86      Content.VariableItemList.CheckedItemsChanged -= CheckedItemsChanged;
[14381]87      base.DeregisterContentEvents();
[10847]88    }
89
[14381]90    protected virtual void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) {
[14511]91      // sync listview
92      foreach (var item in checkedItems.Items)
93        variablesListView.Items[item.Index].Checked = Content.VariableItemList.ItemChecked(item.Value);
[10717]94    }
[14511]95    private void variablesListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
96      // sync checked item list
97      var variable = (StringValue)e.Item.Tag;
98      Content.VariableItemList.SetItemCheckedState(variable, e.Item.Checked);
99    }
[10717]100
[14381]101    private void PreprocessingData_Changed(object sender, DataPreprocessingChangedEventArgs e) {
[10628]102      switch (e.Type) {
103        case DataPreprocessingChangedEventType.DeleteColumn:
[10992]104          RemoveVariable(Content.PreprocessingData.GetVariableName(e.Column));
[10628]105          break;
106        case DataPreprocessingChangedEventType.AddColumn:
[10992]107          AddVariable(Content.PreprocessingData.GetVariableName(e.Column));
[10628]108          break;
109        case DataPreprocessingChangedEventType.ChangeColumn:
110        case DataPreprocessingChangedEventType.ChangeItem:
[14381]111          UpdateVariable(Content.PreprocessingData.GetVariableName(e.Column));
[10628]112          break;
[10817]113        default:
[14381]114          ResetAllVariables();
[10628]115          break;
[10382]116      }
[10377]117    }
118
[14381]119    protected virtual void AddVariable(string name) {
120      Content.VariableItemList.Add(new StringValue(name));
121      if (!Content.PreprocessingData.InputVariables.Contains(name) && Content.PreprocessingData.TargetVariable != name) {
[14511]122        var listViewItem = variablesListView.FindItemWithText(name, false, 0, false);
[14381]123        listViewItem.ForeColor = Color.LightGray;
[10736]124      }
[10717]125    }
[14381]126    protected virtual void RemoveVariable(string name) {
127      var stringValue = Content.VariableItemList.SingleOrDefault(n => n.Value == name);
[10628]128      if (stringValue != null)
[10818]129        Content.VariableItemList.Remove(stringValue);
[10377]130    }
[14381]131    protected virtual void UpdateVariable(string name) {
[10628]132    }
[14381]133    protected virtual void ResetAllVariables() {
[10736]134    }
135
[14511]136    protected virtual void CheckedChangedUpdate() {
137
[10804]138    }
[10717]139
[14511]140    private void checkInputsTargetButton_Click(object sender, System.EventArgs e) {
141      suppressCheckedChangedUpdate = true;
142      foreach (var name in Content.VariableItemList) {
[14381]143        var isInputTarget = Content.PreprocessingData.InputVariables.Contains(name.Value) || Content.PreprocessingData.TargetVariable == name.Value;
[14511]144        Content.VariableItemList.SetItemCheckedState(name, isInputTarget);
[10717]145      }
[14511]146      suppressCheckedChangedUpdate = false;
147      CheckedChangedUpdate();
[10717]148    }
[14511]149
150    private void checkAllButton_Click(object sender, System.EventArgs e) {
151      suppressCheckedChangedUpdate = true;
152      foreach (var name in Content.VariableItemList) {
153        Content.VariableItemList.SetItemCheckedState(name, true);
[10972]154      }
[14511]155      suppressCheckedChangedUpdate = false;
156      CheckedChangedUpdate();
[10972]157    }
[14511]158
159    private void uncheckAllButton_Click(object sender, System.EventArgs e) {
160      suppressCheckedChangedUpdate = true;
161      foreach (var name in Content.VariableItemList) {
162        Content.VariableItemList.SetItemCheckedState(name, false);
[10717]163      }
[14511]164      suppressCheckedChangedUpdate = false;
165      CheckedChangedUpdate();
[10717]166    }
[10303]167  }
168}
169
170
Note: See TracBrowser for help on using the repository browser.