Free cookie consent management tool by TermsFeed Policy Generator

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