Free cookie consent management tool by TermsFeed Policy Generator

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

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

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

File size: 1.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows.Forms;
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 DeleteColumnCommand : ColumnGroupCommandWithAffectedColumnsBase {
13    private List<ColumnBase> deletedColumns;
14    private List<int> oldSortedColumnIndices;
15
16    private DeleteColumnCommand()
17      : base(null, string.Empty, null) {
18      deletedColumns = new List<ColumnBase>();
19    }
20
21    public DeleteColumnCommand(DataSet dataSet, string columnGroupName, int[] affectedColumns)
22      : base(dataSet, columnGroupName, affectedColumns) {
23      deletedColumns = new List<ColumnBase>();
24    }
25
26    public override void Execute() {
27      base.Execute();
28      this.oldSortedColumnIndices = new List<int>(ColumnGroup.SortedColumnIndexes);
29      ColumnBase column;
30      foreach (int columnIndex in AffectedColumns.Reverse()) {
31        column = ColumnGroup.GetColumn(columnIndex);
32        deletedColumns.Insert(0, column);
33        ColumnGroup.RemoveColumn(column);
34        if (column.SortOrder != SortOrder.None)
35          ColumnGroup.SortedColumnIndexes.Remove(columnIndex);
36      }
37      ColumnGroup.FireChanged();
38      this.ColumnGroup = null;
39    }
40
41    public override void UndoExecute() {
42      base.UndoExecute();
43      for (int i = 0; i < AffectedColumns.Length; i++)
44        ColumnGroup.InsertColumn(AffectedColumns[i], deletedColumns[i]);
45
46      deletedColumns.Clear();
47      ColumnGroup.SortedColumnIndexes = oldSortedColumnIndices;
48      oldSortedColumnIndices = null;
49      ColumnGroup.FireChanged();
50      this.ColumnGroup = null;
51    }
52
53    public override string Description {
54      get { return "Columns deleted"; }
55    }
56  }
57}
Note: See TracBrowser for help on using the repository browser.