57cd1bbeadb16d8f6d6aac51c09ee5746e2e39fe
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Model / FakeModelItemImpl.cs
1 //-----------------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //-----------------------------------------------------------------------------
4
5 namespace System.Activities.Presentation.Model
6 {
7
8     /// <summary>
9     /// FakeModelItemImpl - purpose of this class is to allow full model editing expirience, without need to participate within model tree operations
10     /// If you use this class, even though it contains reference to ModelTreeManager, you are not affecting actual model tree. Any changes made to the 
11     /// model, do not result in any undo/redo operations
12     /// see aslo DesignObjectWrapper class for more usage details
13     /// </summary>
14     sealed class FakeModelItemImpl : ModelItemImpl
15     {
16         public FakeModelItemImpl(ModelTreeManager modelTreeManager, Type itemType, object instance, FakeModelItemImpl parent) 
17             : base(modelTreeManager, itemType, instance, parent)
18         {
19         }
20
21         public override ModelItem Root
22         {
23             get 
24             {
25                 if (this.Parent == null)
26                 {
27                     return this;
28                 }
29                 else
30                 {
31                     return this.Parent.Root;
32                 }
33             }
34         }
35
36         protected override void OnPropertyChanged(string propertyName)
37         {
38             IModelTreeItem modelTreeItem = (IModelTreeItem)this;
39             ModelItem currentValue;
40             //if property value has changed - remove existing value, so the ModelPropertyImplementation will 
41             //force reading the value from the underlying object
42             if (modelTreeItem.ModelPropertyStore.TryGetValue(propertyName, out currentValue))
43             {
44                 IModelTreeItem valueAsTreeItem = (IModelTreeItem)currentValue;
45                 //cleanup references
46                 valueAsTreeItem.RemoveParent(this);
47                 valueAsTreeItem.RemoveSource(this.Properties[propertyName]);
48                 //remove from store
49                 modelTreeItem.ModelPropertyStore.Remove(propertyName);
50             }
51             base.OnPropertyChanged(propertyName);
52         }
53     }
54 }