[corlib] Update ValueTuple implementation
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / View / TreeView / TreeViewItemModelPropertyViewModel.cs
1 //----------------------------------------------------------------
2 // <copyright company="Microsoft Corporation">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //----------------------------------------------------------------
6
7 namespace System.Activities.Presentation.View.TreeView
8 {
9     using System;
10     using System.Activities.Presentation.Internal.PropertyEditing;
11     using System.Activities.Presentation.Model;
12     using System.Activities.Presentation.View.OutlineView;
13     using System.Runtime;
14
15     internal sealed class TreeViewItemModelPropertyViewModel : TreeViewItemViewModel<ModelProperty>
16     {
17         public TreeViewItemModelPropertyViewModel(TreeViewItemViewModel parent, ModelProperty property)
18             : base(parent)
19         {
20             Fx.Assert(property != null, "property cannot be null");
21             this.Value = property;
22             this.VisualValue = property;
23             if (property != null && property.Parent != null)
24             {
25                 this.GetTracker(property);
26             }
27
28             this.UpdateState();
29             if (this.HasChildren)
30             {
31                 this.InternalChildren.Add(TreeViewItemViewModel.DummyNode);
32             }
33         }
34
35         internal override ChangeNotificationTracker GetTracker(ModelProperty modelProperty, bool createNew)
36         {
37             ChangeNotificationTracker tracker = base.GetTracker(modelProperty, createNew);
38             if (createNew)
39             {
40                 Fx.Assert(this.Value == modelProperty, "The modelProperty should be the same as this.Value.");
41                 tracker.Add(modelProperty.Parent, modelProperty);
42                 ShowInOutlineViewAttribute viewVisible = ExtensibilityAccessor.GetAttribute<ShowInOutlineViewAttribute>(modelProperty);
43                 if (viewVisible != null && !string.IsNullOrWhiteSpace(viewVisible.PromotedProperty))
44                 {
45                     ModelProperty promotedProperty = modelProperty.Value.Properties.Find(viewVisible.PromotedProperty);
46                     tracker.Add(promotedProperty.Parent, promotedProperty);
47                 }
48             }
49
50             return tracker;
51         }
52
53         internal override void UpdateChildren(ChangeNotificationTracker tracker, EventArgs e)
54         {
55             if (this.PerfEventProvider != null)
56             {
57                 this.PerfEventProvider.DesignerTreeViewUpdateStart();
58             }
59
60             // 
61             base.UpdateChildren(tracker, e);
62             tracker.CleanUp();
63             this.InternalChildren.Clear();
64
65             this.LoadChildren();
66
67             if (this.PerfEventProvider != null)
68             {
69                 this.PerfEventProvider.DesignerTreeViewUpdateEnd();
70             }
71         }
72
73         internal override void LoadChildren()
74         {
75             if (this.PerfEventProvider != null)
76             {
77                 this.PerfEventProvider.DesignerTreeViewLoadChildrenStart();
78             }
79
80             base.LoadChildren();
81
82             if (this.Value.IsCollection)
83             {
84                 ModelItemCollection mc = this.Value.Value as ModelItemCollection;
85                 TreeViewItemViewModel.AddModelItemCollection(this, mc, this.Value);
86             }
87             else if (this.Value.IsDictionary)
88             {
89                 ModelItemDictionary dictionary = this.Value.Dictionary;
90                 TreeViewItemViewModel.AddModelItemDictionary(this, dictionary, this.Value);
91             }
92             else if (this.Value.Value != null)
93             {
94                 TreeViewItemViewModel.AddChild(this, this.Value.Value, this.Value.Value, this.DuplicatedNodeVisible, string.Empty, this.Value);
95             }
96
97             if (this.PerfEventProvider != null)
98             {
99                 this.PerfEventProvider.DesignerTreeViewLoadChildrenEnd();
100             }
101         }
102
103         internal override void UpdateState()
104         {
105             if (this.Value.Value != null || (this.Value.IsCollection && this.Value.Collection.Count > 0) ||
106                 (this.Value.IsDictionary && this.Value.Dictionary.Count > 0))
107             {
108                 this.State = TreeViewItemState.HasChildren;
109             }
110
111             base.UpdateState();
112         }
113
114         protected override EditingContext GetEditingContext()
115         {
116             if (this.Value != null && this.Value.Parent != null)
117             {
118                 return this.Value.Parent.GetEditingContext();
119             }
120             else
121             {
122                 return base.GetEditingContext();
123             }
124         }
125     }
126 }