1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Xml;
|
---|
6 | using System.Windows.Forms;
|
---|
7 | using HeuristicLab.DataImporter.Data.CommandBase;
|
---|
8 | using HeuristicLab.DataImporter.Data.Model;
|
---|
9 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
10 |
|
---|
11 | namespace HeuristicLab.DataImporter.Data.Command {
|
---|
12 | [StorableClass]
|
---|
13 | public class ChangeValueCommand : ColumnCommandBase {
|
---|
14 | [Storable]
|
---|
15 | private int position;
|
---|
16 | [Storable]
|
---|
17 | private IComparable newValue;
|
---|
18 |
|
---|
19 | private IComparable oldValue;
|
---|
20 | private ICollection<int> oldSortedColumnIndices;
|
---|
21 | private IEnumerable<SortOrder> oldSortOrder;
|
---|
22 |
|
---|
23 | private ChangeValueCommand()
|
---|
24 | : base(null, string.Empty, -1) {
|
---|
25 | }
|
---|
26 |
|
---|
27 | public ChangeValueCommand(DataSet dataSet, string columnGroupName, int columnIndex, int position, IComparable newValue)
|
---|
28 | : base(dataSet, columnGroupName, columnIndex) {
|
---|
29 | this.position = position;
|
---|
30 | this.newValue = newValue;
|
---|
31 | }
|
---|
32 |
|
---|
33 | public override void Execute() {
|
---|
34 | base.Execute();
|
---|
35 | this.oldValue = Column.GetValue(position);
|
---|
36 | Column.ChangeValueOrNull(position, newValue);
|
---|
37 | oldSortedColumnIndices = new List<int>(ColumnGroup.SortedColumnIndexes);
|
---|
38 | oldSortOrder = ColumnGroup.SortOrdersForColumns.ToList();
|
---|
39 | ColumnGroup.ResetSorting();
|
---|
40 | Column.FireChanged();
|
---|
41 | }
|
---|
42 |
|
---|
43 | public override void UndoExecute() {
|
---|
44 | base.UndoExecute();
|
---|
45 | Column.ChangeValue(position, oldValue);
|
---|
46 | ColumnGroup.SortOrdersForColumns = oldSortOrder;
|
---|
47 | ColumnGroup.SortedColumnIndexes = oldSortedColumnIndices;
|
---|
48 | oldSortedColumnIndices = null;
|
---|
49 | oldSortOrder = null;
|
---|
50 | Column.FireChanged();
|
---|
51 | this.ColumnGroup = null;
|
---|
52 | }
|
---|
53 |
|
---|
54 | public override string Description {
|
---|
55 | get { return "Column value changed"; }
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|