Changeset 16057 for branches/2839_HiveProjectManagement/HeuristicLab.DataPreprocessing.Views/3.4/DataGridContentView.cs
- Timestamp:
- 08/06/18 18:15:29 (6 years ago)
- Location:
- branches/2839_HiveProjectManagement
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2839_HiveProjectManagement
- Property svn:mergeinfo changed
-
branches/2839_HiveProjectManagement/HeuristicLab.DataPreprocessing.Views
- Property svn:mergeinfo changed
-
branches/2839_HiveProjectManagement/HeuristicLab.DataPreprocessing.Views/3.4/DataGridContentView.cs
r15110 r16057 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 85 85 base.RegisterContentEvents(); 86 86 Content.Changed += Content_Changed; 87 Content. FilterLogic.FilterChanged += FilterLogic_FilterChanged;87 Content.PreprocessingData.FilterChanged += FilterLogic_FilterChanged; 88 88 } 89 89 … … 91 91 base.DeregisterContentEvents(); 92 92 Content.Changed -= Content_Changed; 93 Content. FilterLogic.FilterChanged -= FilterLogic_FilterChanged;93 Content.PreprocessingData.FilterChanged -= FilterLogic_FilterChanged; 94 94 } 95 95 … … 98 98 searchIterator = null; 99 99 if (findAndReplaceDialog != null && !findAndReplaceDialog.IsDisposed) { 100 if (Content. FilterLogic.IsFiltered) {100 if (Content.PreprocessingData.IsFiltered) { 101 101 findAndReplaceDialog.DisableReplace(); 102 102 } else { … … 104 104 } 105 105 } 106 btnReplace.Enabled = !Content. FilterLogic.IsFiltered;106 btnReplace.Enabled = !Content.PreprocessingData.IsFiltered; 107 107 } 108 108 … … 126 126 string errorMessage; 127 127 if (!String.IsNullOrEmpty(e.FormattedValue.ToString())) { 128 if (dataGridView.IsCurrentCellInEditMode && Content. FilterLogic.IsFiltered) {128 if (dataGridView.IsCurrentCellInEditMode && Content.PreprocessingData.IsFiltered) { 129 129 errorMessage = "A filter is active, you cannot modify data. Press ESC to exit edit mode."; 130 130 } else { … … 167 167 168 168 ReplaceTransaction(() => { 169 Content.Pre ProcessingData.InTransaction(() => {169 Content.PreprocessingData.InTransaction(() => { 170 170 for (int row = containsHeader ? 1 : 0; row < values.GetLength(1); row++) { 171 171 for (int col = 0; col < values.GetLength(0); col++) { … … 177 177 if (string.IsNullOrWhiteSpace(firstRow[i])) 178 178 firstRow[i] = string.Format("<{0}>", i); 179 Content.Pre ProcessingData.RenameColumns(firstRow);179 Content.PreprocessingData.RenameColumns(firstRow); 180 180 } 181 181 }); … … 224 224 if (e.Button == MouseButtons.Middle) { 225 225 int newIndex = e.ColumnIndex >= 0 ? e.ColumnIndex : 0; 226 Content.Pre ProcessingData.InsertColumn<double>(newIndex.ToString(), newIndex);226 Content.PreprocessingData.InsertColumn<double>(newIndex.ToString(), newIndex); 227 227 } else if (e.Button == MouseButtons.Right && Content.SortableView) { 228 228 SortColumn(e.ColumnIndex); … … 235 235 if (e.Button == MouseButtons.Middle) { 236 236 int newIndex = e.RowIndex >= 0 ? e.RowIndex : 0; 237 Content.Pre ProcessingData.InsertRow(newIndex);237 Content.PreprocessingData.InsertRow(newIndex); 238 238 } 239 239 } … … 248 248 } 249 249 250 private void btnApplySort_Click(object sender, System.EventArgs e) {251 Content. ManipulationLogic.ReOrderToIndices(virtualRowIndices);250 private void btnApplySort_Click(object sender, EventArgs e) { 251 Content.ReOrderToIndices(virtualRowIndices); 252 252 OnContentChanged(); 253 253 } … … 271 271 searchIterator = null; 272 272 DataGridView.SelectionChanged += DataGridView_SelectionChanged_FindAndReplace; 273 if (Content. FilterLogic.IsFiltered) {273 if (Content.PreprocessingData.IsFiltered) { 274 274 findAndReplaceDialog.DisableReplace(); 275 275 } … … 405 405 ComparisonOperation comparisonOperation = findAndReplaceDialog.GetComparisonOperation(); 406 406 var foundCells = new Dictionary<int, IList<int>>(); 407 for (int i = 0; i < Content. FilterLogic.PreprocessingData.Columns; i++) {407 for (int i = 0; i < Content.PreprocessingData.Columns; i++) { 408 408 var filters = CreateFilters(match, comparisonOperation, i); 409 409 410 bool[] filteredRows = Content.FilterLogic.GetFilterResult(filters, true);410 bool[] filteredRows = GetFilterResult(filters, true); 411 411 var foundIndices = new List<int>(); 412 412 for (int idx = 0; idx < filteredRows.Length; ++idx) { … … 427 427 } 428 428 429 private bool[] GetFilterResult(IList<IFilter> filters, bool isAndCombination) { 430 IList<IFilter> activeFilters = filters.Where(f => f.Active && f.ConstraintData != null).ToList(); 431 432 if (activeFilters.Count == 0) { 433 return Enumerable.Repeat(false, Content.PreprocessingData.Rows).ToArray(); ; 434 } 435 436 var result = Enumerable.Repeat(!isAndCombination, Content.PreprocessingData.Rows).ToArray(); 437 foreach (IFilter filter in activeFilters) { 438 bool[] filterResult = filter.Check(); 439 for (int row = 0; row < result.Length; ++row) { 440 result[row] = isAndCombination ? result[row] || filterResult[row] : result[row] && filterResult[row]; 441 } 442 } 443 return result; 444 } 445 429 446 private List<IFilter> CreateFilters(string match, ComparisonOperation comparisonOperation, int columnIndex) { 430 IPreprocessingData preprocessingData = Content. FilterLogic.PreprocessingData;447 IPreprocessingData preprocessingData = Content.PreprocessingData; 431 448 IStringConvertibleValue value; 432 449 if (preprocessingData.VariableHasType<double>(columnIndex)) { … … 473 490 switch (findAndReplaceDialog.GetReplaceAction()) { 474 491 case ReplaceAction.Value: 475 Content. ManipulationLogic.ReplaceIndicesByValue(cells, findAndReplaceDialog.GetReplaceText());492 Content.ReplaceIndicesByString(cells, findAndReplaceDialog.GetReplaceText()); 476 493 break; 477 494 case ReplaceAction.Average: 478 Content. ManipulationLogic.ReplaceIndicesByAverageValue(cells, false);495 Content.ReplaceIndicesByMean(cells, false); 479 496 break; 480 497 case ReplaceAction.Median: 481 Content. ManipulationLogic.ReplaceIndicesByMedianValue(cells, false);498 Content.ReplaceIndicesByMedianValue(cells, false); 482 499 break; 483 500 case ReplaceAction.Random: 484 Content. ManipulationLogic.ReplaceIndicesByRandomValue(cells, false);501 Content.ReplaceIndicesByRandomValue(cells, false); 485 502 break; 486 503 case ReplaceAction.MostCommon: 487 Content. ManipulationLogic.ReplaceIndicesByMostCommonValue(cells, false);504 Content.ReplaceIndicesByMode(cells, false); 488 505 break; 489 506 case ReplaceAction.Interpolation: 490 Content. ManipulationLogic.ReplaceIndicesByLinearInterpolationOfNeighbours(cells);507 Content.ReplaceIndicesByLinearInterpolationOfNeighbours(cells); 491 508 break; 492 509 } … … 506 523 507 524 #endregion FindAndReplaceDialog 508 509 525 private void dataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { 510 526 if (Content == null) return; … … 531 547 medianToolStripMenuItem_Selection.Enabled = 532 548 randomToolStripMenuItem_Column.Enabled = 533 randomToolStripMenuItem_Selection.Enabled = !Content.PreProcessingData.AreAllStringColumns(columnIndices); 534 535 smoothingToolStripMenuItem_Column.Enabled = 536 interpolationToolStripMenuItem_Column.Enabled = !dataGridView.SelectedCells.Contains(dataGridView[e.ColumnIndex, 0]) 537 && !dataGridView.SelectedCells.Contains(dataGridView[e.ColumnIndex, Content.Rows - 1]) 538 && !Content.PreProcessingData.AreAllStringColumns(columnIndices); 549 randomToolStripMenuItem_Selection.Enabled = !Content.PreprocessingData.AreAllStringColumns(columnIndices); 539 550 540 551 replaceValueOverColumnToolStripMenuItem.Visible = true; … … 547 558 base.dataGridView_KeyDown(sender, e); 548 559 //data is in read only mode.... 549 if (Content. FilterLogic.IsFiltered) return;560 if (Content.PreprocessingData.IsFiltered) return; 550 561 551 562 if (e.KeyCode == Keys.Delete) { … … 581 592 } 582 593 583 foreach (var selectedCell in dataGridView.SelectedCells) { 584 var cell = (DataGridViewCell)selectedCell; 594 foreach (DataGridViewCell cell in dataGridView.SelectedCells) { 585 595 if (!selectedCells.ContainsKey(cell.ColumnIndex)) 586 selectedCells.Add(cell.ColumnIndex, new List<int>( 1024));596 selectedCells.Add(cell.ColumnIndex, new List<int>()); 587 597 selectedCells[cell.ColumnIndex].Add(cell.RowIndex); 588 598 } … … 591 601 } 592 602 593 private void StartReplacing() {603 private void ReplaceTransaction(Action action) { 594 604 SuspendRepaint(); 595 } 596 597 private void StopReplacing() { 605 action(); 598 606 ResumeRepaint(true); 599 }600 601 private void ReplaceTransaction(Action action) {602 StartReplacing();603 action();604 StopReplacing();605 607 } 606 608 … … 616 618 617 619 #region ContextMenu Events 618 619 620 private void ReplaceWithAverage_Column_Click(object sender, EventArgs e) { 620 621 ReplaceTransaction(() => { 621 Content. ManipulationLogic.ReplaceIndicesByAverageValue(GetSelectedCells(), false);622 Content.ReplaceIndicesByMean(GetSelectedCells(), false); 622 623 }); 623 624 } 624 625 private void ReplaceWithAverage_Selection_Click(object sender, EventArgs e) { 625 626 ReplaceTransaction(() => { 626 Content. ManipulationLogic.ReplaceIndicesByAverageValue(GetSelectedCells(), true);627 Content.ReplaceIndicesByMean(GetSelectedCells(), true); 627 628 }); 628 629 } … … 630 631 private void ReplaceWithMedian_Column_Click(object sender, EventArgs e) { 631 632 ReplaceTransaction(() => { 632 Content. ManipulationLogic.ReplaceIndicesByMedianValue(GetSelectedCells(), false);633 Content.ReplaceIndicesByMedianValue(GetSelectedCells(), false); 633 634 }); 634 635 } 635 636 private void ReplaceWithMedian_Selection_Click(object sender, EventArgs e) { 636 637 ReplaceTransaction(() => { 637 Content. ManipulationLogic.ReplaceIndicesByMedianValue(GetSelectedCells(), true);638 Content.ReplaceIndicesByMedianValue(GetSelectedCells(), true); 638 639 }); 639 640 } … … 641 642 private void ReplaceWithRandom_Column_Click(object sender, EventArgs e) { 642 643 ReplaceTransaction(() => { 643 Content. ManipulationLogic.ReplaceIndicesByRandomValue(GetSelectedCells(), false);644 Content.ReplaceIndicesByRandomValue(GetSelectedCells(), false); 644 645 }); 645 646 } 646 647 private void ReplaceWithRandom_Selection_Click(object sender, EventArgs e) { 647 648 ReplaceTransaction(() => { 648 Content. ManipulationLogic.ReplaceIndicesByRandomValue(GetSelectedCells(), true);649 Content.ReplaceIndicesByRandomValue(GetSelectedCells(), true); 649 650 }); 650 651 } … … 652 653 private void ReplaceWithMostCommon_Column_Click(object sender, EventArgs e) { 653 654 ReplaceTransaction(() => { 654 Content. ManipulationLogic.ReplaceIndicesByMostCommonValue(GetSelectedCells(), false);655 Content.ReplaceIndicesByMode(GetSelectedCells(), false); 655 656 }); 656 657 } 657 658 private void ReplaceWithMostCommon_Selection_Click(object sender, EventArgs e) { 658 659 ReplaceTransaction(() => { 659 Content. ManipulationLogic.ReplaceIndicesByMostCommonValue(GetSelectedCells(), true);660 Content.ReplaceIndicesByMode(GetSelectedCells(), true); 660 661 }); 661 662 } … … 663 664 private void ReplaceWithInterpolation_Column_Click(object sender, EventArgs e) { 664 665 ReplaceTransaction(() => { 665 Content.ManipulationLogic.ReplaceIndicesByLinearInterpolationOfNeighbours(GetSelectedCells()); 666 }); 667 } 668 669 private void ReplaceWithSmoothing_Selection_Click(object sender, EventArgs e) { 670 ReplaceTransaction(() => { 671 Content.ManipulationLogic.ReplaceIndicesBySmoothing(GetSelectedCells()); 666 Content.ReplaceIndicesByLinearInterpolationOfNeighbours(GetSelectedCells()); 672 667 }); 673 668 } … … 675 670 676 671 private void addRowButton_Click(object sender, EventArgs e) { 677 Content.Pre ProcessingData.InsertRow(Content.Rows);672 Content.PreprocessingData.InsertRow(Content.Rows); 678 673 } 679 674 680 675 private void addColumnButton_Click(object sender, EventArgs e) { 681 Content.Pre ProcessingData.InsertColumn<double>(Content.Columns.ToString(), Content.Columns);676 Content.PreprocessingData.InsertColumn<double>(Content.Columns.ToString(), Content.Columns); 682 677 } 683 678 … … 686 681 687 682 if (renameDialog.ShowDialog(this) == DialogResult.OK) { 688 Content.Pre ProcessingData.RenameColumns(renameDialog.ColumnNames);683 Content.PreprocessingData.RenameColumns(renameDialog.ColumnNames); 689 684 } 690 685 } … … 693 688 foreach (DataGridViewColumn column in DataGridView.Columns) { 694 689 var variable = column.HeaderText; 695 bool isInputTarget = Content.Pre ProcessingData.InputVariables.Contains(variable)696 || Content.Pre ProcessingData.TargetVariable == variable;690 bool isInputTarget = Content.PreprocessingData.InputVariables.Contains(variable) 691 || Content.PreprocessingData.TargetVariable == variable; 697 692 column.Visible = isInputTarget; 698 693 } … … 710 705 } 711 706 } 707 708 private void shuffleAllButton_Click(object sender, EventArgs e) { 709 Content.Shuffle(shuffleWithinPartitionsCheckBox.Checked); 710 } 712 711 } 713 712 }
Note: See TracChangeset
for help on using the changeset viewer.