1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
5 namespace System.Activities.Presentation.Model
8 using System.Activities.Presentation.Services;
10 class CollectionChange : ModelChange
12 public ModelItemCollection Collection { get; set; }
14 public int Index { get; set; }
16 public ModelItem Item { get; set; }
18 public OperationType Operation { get; set; }
20 public ModelTreeManager ModelTreeManager { get; set; }
22 public override string Description
26 return this.Operation == OperationType.Insert ? SR.CollectionAddEditingScopeDescription : SR.CollectionRemoveEditingScopeDescription;
30 public override bool Apply()
32 switch (this.Operation)
34 case OperationType.Insert:
37 case OperationType.Delete:
41 Fx.Assert("Operation should be Insert or Delete");
48 private void ApplyDelete()
50 Fx.Assert(this.ModelTreeManager != null, "ModelTreeManager cannot be null.");
51 Fx.Assert(this.Collection != null, "this.Collection cannot be null.");
55 ((ModelItemCollectionImpl)this.Collection).RemoveAtCore(this.Index);
59 Fx.Assert(this.Index == -1, "-1 must be used to indicate Remove(item)");
60 this.Index = this.Collection.IndexOf(this.Item);
61 ((ModelItemCollectionImpl)this.Collection).RemoveCore(this.Item);
64 ModelChangeInfo changeInfo = ModelChangeInfoImpl.CreateCollectionItemRemoved(this.Collection, this.Item);
65 this.ModelTreeManager.NotifyCollectionRemove(this.Item, changeInfo);
68 private void ApplyInsert()
70 Fx.Assert(this.ModelTreeManager != null, "ModelTreeManager cannot be null.");
71 Fx.Assert(this.Collection != null, "this.Collection cannot be null.");
75 ((ModelItemCollectionImpl)this.Collection).InsertCore(this.Index, this.Item);
79 Fx.Assert(this.Index == -1, "-1 must be used to indicate Add(item)");
80 this.Index = this.Collection.Count;
81 ((ModelItemCollectionImpl)this.Collection).AddCore(this.Item);
84 ModelChangeInfo changeInfo = ModelChangeInfoImpl.CreateCollectionItemAdded(this.Collection, this.Item);
85 this.ModelTreeManager.NotifyCollectionInsert(this.Item, changeInfo);
88 public override Change GetInverse()
90 OperationType reverseOperation = this.Operation == OperationType.Insert ? OperationType.Delete : OperationType.Insert;
91 return new CollectionChange()
93 Collection = this.Collection,
94 Operation = reverseOperation,
96 ModelTreeManager = this.ModelTreeManager,
102 public enum OperationType