Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Data/Command/DeleteRowsCommand.cs @ 6133

Last change on this file since 6133 was 6133, checked in by gkronber, 13 years ago

#1471: imported generic parts of DataImporter from private code base

File size: 1.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Xml;
6using HeuristicLab.DataImporter.Data.CommandBase;
7using HeuristicLab.DataImporter.Data.Model;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9
10namespace 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}
Note: See TracBrowser for help on using the repository browser.