Changeset 15865 for branches/2906_Transformations/HeuristicLab.DataPreprocessing.Views/3.4/TransformationListView.cs
- Timestamp:
- 03/27/18 15:46:12 (6 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/2906_Transformations/HeuristicLab.DataPreprocessing.Views/3.4/TransformationListView.cs
r15864 r15865 20 20 #endregion 21 21 22 using System; 23 using System.Drawing; 22 24 using System.Linq; 23 25 using System.Windows.Forms; 26 using HeuristicLab.Collections; 24 27 using HeuristicLab.Core; 25 28 using HeuristicLab.Core.Views; 26 29 using HeuristicLab.Data; 27 30 using HeuristicLab.MainForm; 28 using HeuristicLab.Problems.DataAnalysis;29 31 30 32 namespace HeuristicLab.DataPreprocessing.Views { 31 [View(" CheckedTransformationList View")]32 [Content(typeof(I CheckedItemList<IDataAnalysisTransformation>), false)]33 public partial class CheckedTransformationListView : CheckedItemListView<IDataAnalysisTransformation> {33 [View("TransformationList View")] 34 [Content(typeof(IItemList<PreprocessingTransformation>), false)] 35 public partial class TransformationListView : ItemListView<PreprocessingTransformation> { 34 36 35 37 internal IFilteredPreprocessingData PreprocessingData { get; set; } 36 38 37 public CheckedTransformationListView() {39 public TransformationListView() { 38 40 InitializeComponent(); 39 41 itemsGroupBox.Text = "Transformations"; 40 42 } 41 43 42 protected override IDataAnalysisTransformation CreateItem() { 43 var newTransformation = new DataAnalysisTransformation(PreprocessingData.VariableNames.Select(x => new StringValue(x))); 44 protected override PreprocessingTransformation CreateItem() { 45 var variableNames = PreprocessingData.VariableNames.Select(x => new StringValue(x)) 46 .Concat(Content.Select(x => new StringValue(x.TransformedVariable))).Distinct(); 47 48 var newTransformation = new PreprocessingTransformation(variableNames); 44 49 newTransformation.TransformedVariableParameter.ValidValues.Add(new StringValue("<New Variable>")); 45 50 return newTransformation; 46 //if (typeSelectorDialog == null) {47 // typeSelectorDialog = new TypeSelectorDialog();48 // typeSelectorDialog.Caption = "Select Transformation";49 // typeSelectorDialog.TypeSelector.Caption = "Available Transformations";50 // typeSelectorDialog.TypeSelector.Configure(typeof(IDataAnalysisTransformation), showNotInstantiableTypes: true, showGenericTypes: false, typeCondition: CanInstanciateTransformation);51 //}52 53 //if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {54 // try {55 // // TODO: Avoid accessing parent view56 // var transformationView = (TransformationView)Parent;57 // var columnNames = transformationView.Content.PreprocessingData.VariableNames;58 59 // return (IDataAnalysisTransformation)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType(new[] { columnNames });60 // } catch (Exception ex) {61 // ErrorHandling.ShowErrorDialog(this, ex);62 // }63 //}64 //return null;65 51 } 66 52 67 //private bool CanInstanciateTransformation(Type type) { 68 // foreach (ConstructorInfo ctor in type.GetConstructors(BindingFlags.Public | BindingFlags.Instance)) { 69 // ParameterInfo[] parameters = ctor.GetParameters(); 70 // if (parameters.Length == 1 && parameters[0].ParameterType == typeof(IEnumerable<string>)) return true; 71 // } 72 // return false; 73 //} 53 protected override void OnContentChanged() { 54 base.OnContentChanged(); 55 56 if (Content == null) return; 57 58 int i = 0; 59 foreach (ListViewItem item in ItemsListView.Items) { 60 var transformation = PreprocessingData.Transformations[i]; 61 62 item.ForeColor = transformation.IsApplied ? Color.Black : Color.Gray; 63 i++; 64 } 65 UpdateButtonsState(); 66 } 67 68 protected override void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<PreprocessingTransformation>> e) { 69 base.Content_ItemsAdded(sender, e); 70 71 foreach (var transformation in e.Items) { 72 UpdateListViewItemsColor(transformation.Value); 73 } 74 } 75 76 protected override void RegisterItemEvents(PreprocessingTransformation item) { 77 base.RegisterItemEvents(item); 78 item.PropertyChanged += Item_PropertyChanged; 79 } 80 protected override void DeregisterItemEvents(PreprocessingTransformation item) { 81 item.PropertyChanged -= Item_PropertyChanged; 82 base.DeregisterItemEvents(item); 83 } 84 85 private void Item_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { 86 if (sender is PreprocessingTransformation transformation) 87 UpdateListViewItemsColor(transformation); 88 } 89 90 protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) { 91 base.itemsListView_SelectedIndexChanged(sender, e); 92 93 UpdateButtonsState(); 94 } 95 96 private void UpdateListViewItemsColor(PreprocessingTransformation transformation) { 97 foreach (ListViewItem item in itemListViewItemMapping[transformation]) { 98 item.ForeColor = transformation.IsApplied ? Color.Black : Color.Gray; 99 } 100 } 101 102 private void UpdateButtonsState() { 103 if (itemsListView.SelectedItems.Count != 1) return; 104 int selectedIndex = itemsListView.SelectedIndices[0]; 105 106 // TODO: do not move/remove already applied transformations 107 // TODO: general disalow of movement? 108 if (Content[selectedIndex].IsApplied) { 109 moveUpButton.Enabled = selectedIndex > 0 && Content[selectedIndex - 1].IsApplied; 110 moveDownButton.Enabled = false; 111 removeButton.Enabled = false; 112 } 113 } 74 114 } 75 115 }
Note: See TracChangeset
for help on using the changeset viewer.