1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Windows.Forms;
|
---|
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 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 | }
|
---|