Changeset 14511 for branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingCheckedVariablesView.cs
- Timestamp:
- 12/20/16 15:28:14 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingCheckedVariablesView.cs
r14459 r14511 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using System.Drawing; … … 26 25 using System.Windows.Forms; 27 26 using HeuristicLab.Collections; 27 using HeuristicLab.Common.Resources; 28 28 using HeuristicLab.Core.Views; 29 29 using HeuristicLab.Data; … … 35 35 public partial class PreprocessingCheckedVariablesView : ItemView { 36 36 37 protected bool suppressCheckedChangedUpdate = false; 38 37 39 public new PreprocessingChartContent Content { 38 40 get { return (PreprocessingChartContent)base.Content; } … … 42 44 protected PreprocessingCheckedVariablesView() { 43 45 InitializeComponent(); 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; 44 52 } 45 53 … … 48 56 } 49 57 protected IList<string> GetCheckedVariables() { 50 return checkedItemList.Content.CheckedItems.Select(i => i.Value.Value).ToList();58 return Content.VariableItemList.CheckedItems.Select(i => i.Value.Value).ToList(); 51 59 } 52 60 … … 55 63 if (Content == null) return; 56 64 57 if (Content.VariableItemList == null) { 58 IList<string> inputs = Content.PreprocessingData.InputVariables; 59 if (Content.PreprocessingData.TargetVariable != null) 60 inputs = inputs.Union(new[] { Content.PreprocessingData.TargetVariable }).ToList(); 61 Content.VariableItemList = Content.CreateVariableItemList(inputs); 62 } else { 63 var checkedNames = Content.VariableItemList.CheckedItems.Select(x => x.Value.Value); 64 Content.VariableItemList = Content.CreateVariableItemList(checkedNames.ToList()); 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 }); 65 75 } 66 Content.VariableItemList.CheckedItemsChanged += CheckedItemsChanged; 67 68 checkedItemList.Content = Content.VariableItemList; 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)) { 72 var listViewItem = checkedItemList.ItemsListView.FindItemWithText(col, false, 0, false); 73 listViewItem.ForeColor = Color.LightGray; 74 } 76 variablesListView.ItemChecked += variablesListView_ItemChecked; 75 77 } 76 78 protected override void RegisterContentEvents() { 77 79 base.RegisterContentEvents(); 78 80 Content.PreprocessingData.Changed += PreprocessingData_Changed; 79 Content. PreprocessingData.SelectionChanged += PreprocessingData_SelctionChanged;81 Content.VariableItemList.CheckedItemsChanged += CheckedItemsChanged; 80 82 } 83 81 84 protected override void DeregisterContentEvents() { 82 85 Content.PreprocessingData.Changed -= PreprocessingData_Changed; 83 Content. PreprocessingData.SelectionChanged -= PreprocessingData_SelctionChanged;86 Content.VariableItemList.CheckedItemsChanged -= CheckedItemsChanged; 84 87 base.DeregisterContentEvents(); 85 88 } 86 89 87 90 protected virtual void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) { 91 // sync listview 92 foreach (var item in checkedItems.Items) 93 variablesListView.Items[item.Index].Checked = Content.VariableItemList.ItemChecked(item.Value); 94 } 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); 88 99 } 89 100 … … 109 120 Content.VariableItemList.Add(new StringValue(name)); 110 121 if (!Content.PreprocessingData.InputVariables.Contains(name) && Content.PreprocessingData.TargetVariable != name) { 111 var listViewItem = checkedItemList.ItemsListView.FindItemWithText(name, false, 0, false);122 var listViewItem = variablesListView.FindItemWithText(name, false, 0, false); 112 123 listViewItem.ForeColor = Color.LightGray; 113 124 } … … 123 134 } 124 135 125 protected virtual void PreprocessingData_SelctionChanged(object sender, EventArgs e) { 136 protected virtual void CheckedChangedUpdate() { 137 126 138 } 127 139 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" : ""); 140 private void checkInputsTargetButton_Click(object sender, System.EventArgs e) { 141 suppressCheckedChangedUpdate = true; 142 foreach (var name in Content.VariableItemList) { 143 var isInputTarget = Content.PreprocessingData.InputVariables.Contains(name.Value) || Content.PreprocessingData.TargetVariable == name.Value; 144 Content.VariableItemList.SetItemCheckedState(name, isInputTarget); 145 } 146 suppressCheckedChangedUpdate = false; 147 CheckedChangedUpdate(); 133 148 } 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); 139 } 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); 140 154 } 155 suppressCheckedChangedUpdate = false; 156 CheckedChangedUpdate(); 141 157 } 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); 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); 146 163 } 164 suppressCheckedChangedUpdate = false; 165 CheckedChangedUpdate(); 147 166 } 148 private void checkAllToolStripMenuItem_Click(object sender, EventArgs e) {149 foreach (var name in checkedItemList.Content) {150 checkedItemList.Content.SetItemCheckedState(name, true);151 }152 }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 #endregion159 167 } 160 168 }
Note: See TracChangeset
for help on using the changeset viewer.