[10778] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15583] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[10778] | 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 |
|
---|
[15865] | 22 | using System;
|
---|
| 23 | using System.Drawing;
|
---|
[15846] | 24 | using System.Linq;
|
---|
[10778] | 25 | using System.Windows.Forms;
|
---|
[15865] | 26 | using HeuristicLab.Collections;
|
---|
[10778] | 27 | using HeuristicLab.Core;
|
---|
| 28 | using HeuristicLab.Core.Views;
|
---|
[15846] | 29 | using HeuristicLab.Data;
|
---|
[10778] | 30 | using HeuristicLab.MainForm;
|
---|
| 31 |
|
---|
| 32 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
[15865] | 33 | [View("TransformationList View")]
|
---|
| 34 | [Content(typeof(IItemList<PreprocessingTransformation>), false)]
|
---|
| 35 | public partial class TransformationListView : ItemListView<PreprocessingTransformation> {
|
---|
[15846] | 36 |
|
---|
| 37 | internal IFilteredPreprocessingData PreprocessingData { get; set; }
|
---|
| 38 |
|
---|
[15865] | 39 | public TransformationListView() {
|
---|
[10778] | 40 | InitializeComponent();
|
---|
| 41 | itemsGroupBox.Text = "Transformations";
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[15865] | 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);
|
---|
[15846] | 49 | newTransformation.TransformedVariableParameter.ValidValues.Add(new StringValue("<New Variable>"));
|
---|
| 50 | return newTransformation;
|
---|
[15865] | 51 | }
|
---|
[10778] | 52 |
|
---|
[15865] | 53 | protected override void OnContentChanged() {
|
---|
| 54 | base.OnContentChanged();
|
---|
[10806] | 55 |
|
---|
[15865] | 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();
|
---|
[11068] | 66 | }
|
---|
[10778] | 67 |
|
---|
[15865] | 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 | }
|
---|
[10778] | 114 | }
|
---|
| 115 | }
|
---|