1: using System;
2: using Microsoft.VisualStudio.Modeling;
3: using Microsoft.VisualStudio.Modeling.Diagrams;
4:
5: namespace MyModel
6: {
7: /// <summary>
8: /// Defines a change rule for the ModuleReference domain class.
9: /// </summary>
10: [RuleOn(typeof(Primavera.Athena.Models.Reporting.ModuleReference), FireTime = TimeToFire.TopLevelCommit)]
11: public class ModuleReferenceChangeRule : ChangeRule
12: {
13: #region Public Methods
14:
15: /// <summary>
16: /// Alerts listeners that a property for an element has changed.
17: /// </summary>
18: /// <param name="e">Provides data for the ElementPropertyChanged event.</param>
19: public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
20: {
21: // Validations
22:
23: if (e == null)
24: {
25: throw new ArgumentNullException("e");
26: }
27:
28: if (e.DomainProperty.Id.Equals(ModuleReference.MainDomainPropertyId))
29: {
30: HandleMainChanged(e);
31: }
32:
33: // Default behavior
34:
35: base.ElementPropertyChanged(e);
36: }
37:
38: #endregion
39:
40: #region Private Methods
41:
42: /// <summary>
43: /// Handles changes in Main.
44: /// </summary>
45: /// <param name="e">The <see cref="Microsoft.VisualStudio.Modeling.ElementPropertyChangedEventArgs"/> instance containing the event data.</param>
46: [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
47: private void HandleMainChanged(ElementPropertyChangedEventArgs e)
48: {
49: // Something changed?
50:
51: if (!e.OldValue.Equals(e.NewValue))
52: {
53: // Get the current shape
54:
55: ModuleReference moduleReference = e.ModelElement as ModuleReference;
56: if (moduleReference != null)
57: {
58: // Update all entities colors
59:
60: foreach (Entity entity in moduleReference.Entities)
61: {
62: LinkedElementCollection<PresentationElement> presentations =
63: PresentationViewsSubject.GetPresentation(entity);
64: EntityShape entityShape = null;
65:
66: if (presentations.Count > 0)
67: {
68: entityShape = presentations[0] as EntityShape;
69: }
70:
71: if (entityShape != null)
72: {
73: entityShape.UpdateMainModuleReferencePresentation((bool)e.NewValue);
74: }
75: }
76: }
77: }
78: }
79:
80: #endregion
81: }
82: }