Changeset 15110 for trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingCheckedVariablesView.cs
- Timestamp:
- 07/03/17 10:57:53 (7 years ago)
- Location:
- trunk/sources/HeuristicLab.DataPreprocessing.Views
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.DataPreprocessing.Views
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingCheckedVariablesView.cs
r14425 r15110 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using System.Drawing; … … 33 32 [View("Preprocessing Checked Variables View")] 34 33 [Content(typeof(PreprocessingChartContent), false)] 35 public abstract partial class PreprocessingCheckedVariablesView : ItemView { 34 public partial class PreprocessingCheckedVariablesView : ItemView { 35 protected bool SuppressCheckedChangedUpdate = false; 36 36 37 37 public new PreprocessingChartContent Content { … … 48 48 } 49 49 protected IList<string> GetCheckedVariables() { 50 return checkedItemList.Content.CheckedItems.Select(i => i.Value.Value).ToList();50 return Content.VariableItemList.CheckedItems.Select(i => i.Value.Value).ToList(); 51 51 } 52 52 … … 55 55 if (Content == null) return; 56 56 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()); 57 variablesListView.ItemChecked -= variablesListView_ItemChecked; 58 variablesListView.Items.Clear(); 59 foreach (var variable in Content.VariableItemList) { 60 bool isInputTarget = Content.PreprocessingData.InputVariables.Contains(variable.Value) 61 || Content.PreprocessingData.TargetVariable == variable.Value; 62 variablesListView.Items.Add(new ListViewItem(variable.Value) { 63 Tag = variable, 64 Checked = IsVariableChecked(variable.Value), 65 ForeColor = isInputTarget ? Color.Black : Color.Gray 66 }); 65 67 } 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 } 68 variablesListView.ItemChecked += variablesListView_ItemChecked; 75 69 } 76 70 protected override void RegisterContentEvents() { 77 71 base.RegisterContentEvents(); 78 72 Content.PreprocessingData.Changed += PreprocessingData_Changed; 79 Content. PreprocessingData.SelectionChanged += PreprocessingData_SelctionChanged;73 Content.VariableItemList.CheckedItemsChanged += CheckedItemsChanged; 80 74 } 75 81 76 protected override void DeregisterContentEvents() { 82 77 Content.PreprocessingData.Changed -= PreprocessingData_Changed; 83 Content. PreprocessingData.SelectionChanged -= PreprocessingData_SelctionChanged;78 Content.VariableItemList.CheckedItemsChanged -= CheckedItemsChanged; 84 79 base.DeregisterContentEvents(); 85 80 } 86 81 87 82 protected virtual void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) { 83 // sync listview 84 foreach (var item in checkedItems.Items) 85 variablesListView.Items[item.Index].Checked = Content.VariableItemList.ItemChecked(item.Value); 86 } 87 private void variablesListView_ItemChecked(object sender, ItemCheckedEventArgs e) { 88 // sync checked item list 89 var variable = (StringValue)e.Item.Tag; 90 Content.VariableItemList.SetItemCheckedState(variable, e.Item.Checked); 88 91 } 89 92 … … 109 112 Content.VariableItemList.Add(new StringValue(name)); 110 113 if (!Content.PreprocessingData.InputVariables.Contains(name) && Content.PreprocessingData.TargetVariable != name) { 111 var listViewItem = checkedItemList.ItemsListView.FindItemWithText(name, false, 0, false);114 var listViewItem = variablesListView.FindItemWithText(name, false, 0, false); 112 115 listViewItem.ForeColor = Color.LightGray; 113 116 } … … 118 121 Content.VariableItemList.Remove(stringValue); 119 122 } 120 protected virtual void UpdateVariable(string name) { 121 } 122 protected virtual void ResetAllVariables() { 123 protected virtual void UpdateVariable(string name) { } 124 protected virtual void ResetAllVariables() { } 125 protected virtual void CheckedChangedUpdate() { } 126 127 private void checkInputsTargetButton_Click(object sender, System.EventArgs e) { 128 SuppressCheckedChangedUpdate = true; 129 foreach (var name in Content.VariableItemList) { 130 var isInputTarget = Content.PreprocessingData.InputVariables.Contains(name.Value) || Content.PreprocessingData.TargetVariable == name.Value; 131 Content.VariableItemList.SetItemCheckedState(name, isInputTarget); 132 } 133 SuppressCheckedChangedUpdate = false; 134 CheckedChangedUpdate(); 123 135 } 124 136 125 protected virtual void PreprocessingData_SelctionChanged(object sender, EventArgs e) { 137 private void checkAllButton_Click(object sender, System.EventArgs e) { 138 SuppressCheckedChangedUpdate = true; 139 foreach (var name in Content.VariableItemList) { 140 Content.VariableItemList.SetItemCheckedState(name, true); 141 } 142 SuppressCheckedChangedUpdate = false; 143 CheckedChangedUpdate(); 126 144 } 127 145 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" : ""); 146 private void uncheckAllButton_Click(object sender, System.EventArgs e) { 147 SuppressCheckedChangedUpdate = true; 148 foreach (var name in Content.VariableItemList) { 149 Content.VariableItemList.SetItemCheckedState(name, false); 150 } 151 SuppressCheckedChangedUpdate = false; 152 CheckedChangedUpdate(); 133 153 } 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 }140 }141 }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);146 }147 }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 154 } 160 155 }
Note: See TracChangeset
for help on using the changeset viewer.