#region License Information
/* HeuristicLab
* Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using HeuristicLab.DataImporter.Data;
using HeuristicLab.DataImporter.Data.CommandBase;
using HeuristicLab.DataImporter.Data.Model;
using HeuristicLab.DataImporter.Command.View;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using System.Drawing;
namespace HeuristicLab.DataImporter.Command {
[StorableClass]
[ViewableCommandInfoAttribute("Search and Remove Rows", 1, ColumnGroupState.ColumnSelected, "Change Values",
Position = 1, OptionsView = typeof(SearchWithMatchOperationCommandView))]
public class DeleteRowsWithGivenValueCommand : SearchWithMatchOperationCommandBase {
private Dictionary deletedRows;
private DeleteRowsWithGivenValueCommand()
: base(null, string.Empty, null) {
deletedRows = new Dictionary();
}
public DeleteRowsWithGivenValueCommand(DataSet dataSet, string columnGroupName, int[] affectedColumns)
: base(dataSet, columnGroupName, affectedColumns) {
deletedRows = new Dictionary();
}
public override string Description {
get { return "Delete rows which match given value"; }
}
public override void Execute() {
base.Execute();
Point[] affectedCells = this.GetAffectedCells();
int[] rows = affectedCells.Select(c => c.Y).Distinct().OrderBy(x => x).Reverse().ToArray();
foreach (int rowIndex in rows) {
deletedRows[rowIndex] = ColumnGroup.GetRow(rowIndex);
ColumnGroup.DeleteRow(rowIndex);
}
ColumnGroup.FireChanged();
ColumnGroup = null;
}
public override void UndoExecute() {
base.UndoExecute();
foreach (KeyValuePair row in deletedRows.OrderBy(x => x.Key))
ColumnGroup.InsertRow(row.Key, row.Value);
deletedRows.Clear();
ColumnGroup.FireChanged();
ColumnGroup = null;
}
}
}