1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Xml;
|
---|
6 | using HeuristicLab.DataImporter.Data.CommandBase;
|
---|
7 | using HeuristicLab.DataImporter.Data.Model;
|
---|
8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
9 |
|
---|
10 | namespace HeuristicLab.DataImporter.Data.Command {
|
---|
11 | [StorableClass]
|
---|
12 | public class DeleteRowsCommand : ColumnGroupCommandBase {
|
---|
13 | [Storable]
|
---|
14 | private List<int> rowIndexes;
|
---|
15 |
|
---|
16 | private List<IComparable[]> oldrows;
|
---|
17 |
|
---|
18 | private DeleteRowsCommand()
|
---|
19 | : base(null, string.Empty) {
|
---|
20 | this.oldrows = new List<IComparable[]>();
|
---|
21 | }
|
---|
22 |
|
---|
23 | public DeleteRowsCommand(DataSet dataSet, string columnGroupName, IEnumerable<int> rowIndexes)
|
---|
24 | : base(dataSet, columnGroupName) {
|
---|
25 | this.rowIndexes = new List<int>(rowIndexes);
|
---|
26 | this.oldrows = new List<IComparable[]>();
|
---|
27 | }
|
---|
28 |
|
---|
29 | public override void Execute() {
|
---|
30 | base.Execute();
|
---|
31 | foreach (int pos in this.rowIndexes.Reverse<int>()) {
|
---|
32 | oldrows.Insert(0, ColumnGroup.GetRow(pos));
|
---|
33 | ColumnGroup.DeleteRow(pos);
|
---|
34 | }
|
---|
35 | ColumnGroup.FireChanged();
|
---|
36 | this.ColumnGroup = null;
|
---|
37 | }
|
---|
38 |
|
---|
39 | public override void UndoExecute() {
|
---|
40 | base.UndoExecute();
|
---|
41 | for (int i = 0; i < rowIndexes.Count; i++)
|
---|
42 | ColumnGroup.InsertRow(this.rowIndexes[i], this.oldrows[i]);
|
---|
43 | oldrows.Clear();
|
---|
44 | ColumnGroup.FireChanged();
|
---|
45 | this.ColumnGroup = null;
|
---|
46 | }
|
---|
47 |
|
---|
48 | public override string Description {
|
---|
49 | get { return "Delete Rows"; }
|
---|
50 | }
|
---|
51 | }
|
---|
52 | }
|
---|