//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using DslModeling = global::Microsoft.VisualStudio.Modeling;
using DslDesign = global::Microsoft.VisualStudio.Modeling.Design;
using DslDiagrams = global::Microsoft.VisualStudio.Modeling.Diagrams;

[module: global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Scope = "type", Target = "Microsoft.Data.Entity.Design.EntityDesigner.View.EntityDesignerDiagram")]

namespace Microsoft.Data.Entity.Design.EntityDesigner.View
{
	/// <summary>
	/// Double-derived base class for DomainClass EntityDesignerDiagram
	/// </summary>
	[DslDesign::DisplayNameResource("Microsoft.Data.Entity.Design.EntityDesigner.View.EntityDesignerDiagram.DisplayName", typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.MicrosoftDataEntityDesignDomainModel), "Microsoft.Data.Entity.Design.EntityDesigner.GeneratedCode.DomainModelResx")]
	[DslDesign::DescriptionResource("Microsoft.Data.Entity.Design.EntityDesigner.View.EntityDesignerDiagram.Description", typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.MicrosoftDataEntityDesignDomainModel), "Microsoft.Data.Entity.Design.EntityDesigner.GeneratedCode.DomainModelResx")]
	[DslModeling::DomainModelOwner(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.MicrosoftDataEntityDesignDomainModel))]
	[DslModeling::DomainObjectId("3daa738d-a8aa-4f0c-b98b-db1382985264")]
	internal abstract partial class EntityDesignerDiagramBase : DslDiagrams::Diagram
	{
		#region Diagram boilerplate
		private static DslDiagrams::StyleSet classStyleSet;
		private static global::System.Collections.Generic.IList<DslDiagrams::ShapeField> shapeFields;
		/// <summary>
		/// Per-class style set for this shape.
		/// </summary>
		protected override DslDiagrams::StyleSet ClassStyleSet
		{
			get
			{
				if (classStyleSet == null)
				{
					classStyleSet = CreateClassStyleSet();
				}
				return classStyleSet;
			}
		}
		
		/// <summary>
		/// Per-class ShapeFields for this shape
		/// </summary>
		public override global::System.Collections.Generic.IList<DslDiagrams::ShapeField> ShapeFields
		{
			get
			{
				if (shapeFields == null)
				{
					shapeFields = CreateShapeFields();
				}
				return shapeFields;
			}
		}
		#endregion
		#region Toolbox filters
		private static global::System.ComponentModel.ToolboxItemFilterAttribute[] toolboxFilters = new global::System.ComponentModel.ToolboxItemFilterAttribute[] {
					new global::System.ComponentModel.ToolboxItemFilterAttribute(global::Microsoft.Data.Entity.Design.EntityDesigner.MicrosoftDataEntityDesignToolboxHelperBase.ToolboxFilterString, global::System.ComponentModel.ToolboxItemFilterType.Require) };
		
		/// <summary>
		/// Toolbox item filter attributes for this diagram.
		/// </summary>
		public override global::System.Collections.ICollection TargetToolboxItemFilterAttributes
		{
			get
			{
				return toolboxFilters;
			}
		}
		#endregion
		#region Diagram styles
		/// <summary>
		/// Initializes style set resources for this shape type
		/// </summary>
		/// <param name="classStyleSet">The style set for this shape class</param>
		protected override void InitializeResources(DslDiagrams::StyleSet classStyleSet)
		{
			base.InitializeResources(classStyleSet);
			
			// Fill brush settings for this shape.
			DslDiagrams::BrushSettings backgroundBrush = new DslDiagrams::BrushSettings();
			backgroundBrush.Color = global::System.Drawing.Color.FromKnownColor(global::System.Drawing.KnownColor.WhiteSmoke);
			classStyleSet.OverrideBrush(DslDiagrams::DiagramBrushes.DiagramBackground, backgroundBrush);
		
		}
		#endregion
		#region Auto-placement
		/// <summary>
		/// Indicate that child shapes should added through view fixup should be placed automatically.
		/// </summary>
		public override bool ShouldAutoPlaceChildShapes
		{
			get
			{
				return true;
			}
		}
		#endregion
		#region Compartment support
		/// <summary>
		/// Whether compartment items change events are subscribed to.
		/// </summary>
		private bool subscribedCompartmentItemsEvents;
		
		/// <summary>
		/// Subscribe to events fired when compartment items changes.
		/// </summary>
		public void SubscribeCompartmentItemsEvents()
		{
			if (!subscribedCompartmentItemsEvents && this.Store != null)
			{
				subscribedCompartmentItemsEvents = true;
				this.Store.EventManagerDirectory.ElementAdded.Add(new global::System.EventHandler<DslModeling::ElementAddedEventArgs>(this.CompartmentItemAdded));
				this.Store.EventManagerDirectory.ElementDeleted.Add(new global::System.EventHandler<DslModeling::ElementDeletedEventArgs>(this.CompartmentItemDeleted));
				this.Store.EventManagerDirectory.ElementPropertyChanged.Add(new global::System.EventHandler<DslModeling::ElementPropertyChangedEventArgs>(this.CompartmentItemPropertyChanged));
				this.Store.EventManagerDirectory.RolePlayerChanged.Add(new global::System.EventHandler<DslModeling::RolePlayerChangedEventArgs>(this.CompartmentItemRolePlayerChanged));
				this.Store.EventManagerDirectory.RolePlayerOrderChanged.Add(new global::System.EventHandler<DslModeling::RolePlayerOrderChangedEventArgs>(this.CompartmentItemRolePlayerOrderChanged));
			}
		}
		
		/// <summary>
		/// Unsubscribe to events fired when compartment items changes.
		/// </summary>
		public void UnsubscribeCompartmentItemsEvents()
		{
			if (subscribedCompartmentItemsEvents)
			{
				this.Store.EventManagerDirectory.ElementAdded.Remove(new global::System.EventHandler<DslModeling::ElementAddedEventArgs>(this.CompartmentItemAdded));
				this.Store.EventManagerDirectory.ElementDeleted.Remove(new global::System.EventHandler<DslModeling::ElementDeletedEventArgs>(this.CompartmentItemDeleted));
				this.Store.EventManagerDirectory.ElementPropertyChanged.Remove(new global::System.EventHandler<DslModeling::ElementPropertyChangedEventArgs>(this.CompartmentItemPropertyChanged));
				this.Store.EventManagerDirectory.RolePlayerChanged.Remove(new global::System.EventHandler<DslModeling::RolePlayerChangedEventArgs>(this.CompartmentItemRolePlayerChanged));
				this.Store.EventManagerDirectory.RolePlayerOrderChanged.Remove(new global::System.EventHandler<DslModeling::RolePlayerOrderChangedEventArgs>(this.CompartmentItemRolePlayerOrderChanged));
				subscribedCompartmentItemsEvents = false;
			}
		}
		
		#region Event handlers
		/// <summary>
		/// Event for element added.
		/// </summary>
		private void CompartmentItemAdded(object sender, DslModeling::ElementAddedEventArgs e)
		{
			CompartmentItemAddRule.ElementAdded(e, true /* repaint only */);
		}
		/// <summary>
		/// Event for element deleted.
		/// </summary>
		private void CompartmentItemDeleted(object sender, DslModeling::ElementDeletedEventArgs e)
		{
			CompartmentItemDeleteRule.ElementDeleted(e, true /* repaint only */);
		}
		/// <summary>
		/// Event for element property changed.
		/// </summary>
		private void CompartmentItemPropertyChanged(object sender, DslModeling::ElementPropertyChangedEventArgs e)
		{
			CompartmentItemChangeRule.ElementPropertyChanged(e, true /* repaint only */);
		}
		/// <summary>
		/// Event for role-player changed.
		/// </summary>
		private void CompartmentItemRolePlayerChanged(object sender, DslModeling::RolePlayerChangedEventArgs e)
		{
			CompartmentItemRolePlayerChangeRule.RolePlayerChanged(e, true /* repaint only */);
		}
		/// <summary>
		/// Event for role-player order changed.
		/// </summary>
		private void CompartmentItemRolePlayerOrderChanged(object sender, DslModeling::RolePlayerOrderChangedEventArgs e)
		{
			CompartmentItemRolePlayerPositionChangeRule.RolePlayerPositionChanged(e, true /* repaint only */);
		}
		#endregion
		#endregion
		#region Shape mapping
		/// <summary>
		/// Called during view fixup to ask the parent whether a shape should be created for the given child element.
		/// </summary>
		/// <remarks>
		/// Always return true, since we assume there is only one diagram per model file for DSL scenarios.
		/// </remarks>
		protected override bool ShouldAddShapeForElement(DslModeling::ModelElement element)
		{
			return true;
		}
		
		/// <summary>
		/// Called during view fixup to configure the given child element, after it has been created.
		/// </summary>
		/// <remarks>
		/// Custom code for choosing the shapes attached to either end of a connector is called from here.
		/// </remarks>
		protected override void OnChildConfiguring(DslDiagrams::ShapeElement child, bool createdDuringViewFixup)
		{
			DslDiagrams::NodeShape sourceShape;
			DslDiagrams::NodeShape targetShape;
			DslDiagrams::BinaryLinkShape connector = child as DslDiagrams::BinaryLinkShape;
			if(connector == null)
			{
				base.OnChildConfiguring(child, createdDuringViewFixup);
				return;
			}
			this.GetSourceAndTargetForConnector(connector, out sourceShape, out targetShape);
			
			global::System.Diagnostics.Debug.Assert(sourceShape != null && targetShape != null, "Unable to find source and target shapes for connector.");
			connector.Connect(sourceShape, targetShape);
		}
		
		/// <summary>
		/// helper method to find the shapes for either end of a connector, including calling the user's custom code
		/// </summary>
		[global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
		internal void GetSourceAndTargetForConnector(DslDiagrams::BinaryLinkShape connector, out DslDiagrams::NodeShape sourceShape, out DslDiagrams::NodeShape targetShape)
		{
			sourceShape = null;
			targetShape = null;
			
			if (sourceShape == null || targetShape == null)
			{
				DslDiagrams::NodeShape[] endShapes = GetEndShapesForConnector(connector);
				if(sourceShape == null)
				{
					sourceShape = endShapes[0];
				}
				if(targetShape == null)
				{
					targetShape = endShapes[1];
				}
			}
		}
		
		/// <summary>
		/// Helper method to find shapes for either end of a connector by looking for shapes associated with either end of the relationship mapped to the connector.
		/// </summary>
		private DslDiagrams::NodeShape[] GetEndShapesForConnector(DslDiagrams::BinaryLinkShape connector)
		{
			DslModeling::ElementLink link = connector.ModelElement as DslModeling::ElementLink;
			DslDiagrams::NodeShape sourceShape = null, targetShape = null;
			if (link != null)
			{
				global::System.Collections.ObjectModel.ReadOnlyCollection<DslModeling::ModelElement> linkedElements = link.LinkedElements;
				if (linkedElements.Count == 2)
				{
					DslDiagrams::Diagram currentDiagram = this.Diagram;
					DslModeling::LinkedElementCollection<DslDiagrams::PresentationElement> presentationElements = DslDiagrams::PresentationViewsSubject.GetPresentation(linkedElements[0]);
					foreach (DslDiagrams::PresentationElement presentationElement in presentationElements)
					{
						DslDiagrams::NodeShape shape = presentationElement as DslDiagrams::NodeShape;
						if (shape != null && shape.Diagram == currentDiagram)
						{
							sourceShape = shape;
							break;
						}
					}
					
					presentationElements = DslDiagrams::PresentationViewsSubject.GetPresentation(linkedElements[1]);
					foreach (DslDiagrams::PresentationElement presentationElement in presentationElements)
					{
						DslDiagrams::NodeShape shape = presentationElement as DslDiagrams::NodeShape;
						if (shape != null && shape.Diagram == currentDiagram)
						{
							targetShape = shape;
							break;
						}
					}
		
				}
			}
			
			return new DslDiagrams::NodeShape[] { sourceShape, targetShape };
		}
		
		/// <summary>
		/// Creates a new shape for the given model element as part of view fixup
		/// </summary>
		[global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily", Justification = "Generated code.")]
		[global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "Generated code.")]
		protected override DslDiagrams::ShapeElement CreateChildShape(DslModeling::ModelElement element)
		{
			if(element is global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityType)
			{
				global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityTypeShape newShape = new global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityTypeShape(this.Partition);
				if(newShape != null) newShape.Size = newShape.DefaultSize; // set default shape size
				return newShape;
			}
			if(element is global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Association)
			{
				global::Microsoft.Data.Entity.Design.EntityDesigner.View.AssociationConnector newShape = new global::Microsoft.Data.Entity.Design.EntityDesigner.View.AssociationConnector(this.Partition);
				return newShape;
			}
			if(element is global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Inheritance)
			{
				global::Microsoft.Data.Entity.Design.EntityDesigner.View.InheritanceConnector newShape = new global::Microsoft.Data.Entity.Design.EntityDesigner.View.InheritanceConnector(this.Partition);
				return newShape;
			}
			return base.CreateChildShape(element);
		}
		#endregion
		#region Decorator mapping
		/// <summary>
		/// Initialize shape decorator mappings.  This is done here rather than in individual shapes because decorator maps
		/// are defined per diagram type rather than per shape type.
		/// </summary>
		protected override void InitializeShapeFields(global::System.Collections.Generic.IList<DslDiagrams::ShapeField> shapeFields)
		{
			base.InitializeShapeFields(shapeFields);
			global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityTypeShape.DecoratorsInitialized += EntityTypeShapeDecoratorMap.OnDecoratorsInitialized;
			global::Microsoft.Data.Entity.Design.EntityDesigner.View.AssociationConnector.DecoratorsInitialized += AssociationConnectorDecoratorMap.OnDecoratorsInitialized;
		}
		
		/// <summary>
		/// Class containing decorator path traversal methods for EntityTypeShape.
		/// </summary>
		internal static partial class EntityTypeShapeDecoratorMap
		{
			/// <summary>
			/// Event handler called when decorator initialization is complete for EntityTypeShape.  Adds decorator mappings for this shape or connector.
			/// </summary>
			public static void OnDecoratorsInitialized(object sender, global::System.EventArgs e)
			{
				DslDiagrams::ShapeElement shape = (DslDiagrams::ShapeElement)sender;
				DslDiagrams::AssociatedPropertyInfo propertyInfo;
		
				propertyInfo = new DslDiagrams::AssociatedPropertyInfo(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityType.HasBaseTypeDomainPropertyId);
				propertyInfo.FilteringValues.Add("True");
				DslDiagrams::ShapeElement.FindDecorator(shape.Decorators, "BaseTypeIconDecorator").AssociateVisibilityWith(shape.Store, propertyInfo);
				
				propertyInfo = new DslDiagrams::AssociatedPropertyInfo(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityType.BaseTypeNameDomainPropertyId);
				DslDiagrams::ShapeElement.FindDecorator(shape.Decorators, "BaseTypeName").AssociateValueWith(shape.Store, propertyInfo);
		
				propertyInfo = new DslDiagrams::AssociatedPropertyInfo(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityType.HasBaseTypeDomainPropertyId);
				propertyInfo.FilteringValues.Add("True");
				DslDiagrams::ShapeElement.FindDecorator(shape.Decorators, "BaseTypeName").AssociateVisibilityWith(shape.Store, propertyInfo);
				
				propertyInfo = new DslDiagrams::AssociatedPropertyInfo(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.NameableItem.NameDomainPropertyId);
				DslDiagrams::ShapeElement.FindDecorator(shape.Decorators, "Name").AssociateValueWith(shape.Store, propertyInfo);
			}
		}
		
		/// <summary>
		/// Class containing decorator path traversal methods for AssociationConnector.
		/// </summary>
		internal static partial class AssociationConnectorDecoratorMap
		{
			/// <summary>
			/// Event handler called when decorator initialization is complete for AssociationConnector.  Adds decorator mappings for this shape or connector.
			/// </summary>
			public static void OnDecoratorsInitialized(object sender, global::System.EventArgs e)
			{
				DslDiagrams::ShapeElement shape = (DslDiagrams::ShapeElement)sender;
				DslDiagrams::AssociatedPropertyInfo propertyInfo;
				
				propertyInfo = new DslDiagrams::AssociatedPropertyInfo(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Association.SourceMultiplicityDomainPropertyId);
				DslDiagrams::ShapeElement.FindDecorator(shape.Decorators, "SourceEndDisplayText").AssociateValueWith(shape.Store, propertyInfo);
				
				propertyInfo = new DslDiagrams::AssociatedPropertyInfo(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Association.TargetMultiplicityDomainPropertyId);
				DslDiagrams::ShapeElement.FindDecorator(shape.Decorators, "TargetEndDisplayText").AssociateValueWith(shape.Store, propertyInfo);
			}
		}
		
		#endregion
		
		#region Connect actions
		private bool changingMouseAction;
		private global::Microsoft.Data.Entity.Design.EntityDesigner.AssociationToolConnectAction associationToolConnectAction;
		private global::Microsoft.Data.Entity.Design.EntityDesigner.InheritanceToolConnectAction inheritanceToolConnectAction;
		/// <summary>
		/// Virtual method to provide a filter when to select the mouse action
		/// </summary>
		/// <param name="activeView">Currently active view</param>
		/// <param name="filter">filter string used to filter the toolbox items</param>
		protected virtual bool SelectedToolboxItemSupportsFilterString(DslDiagrams::DiagramView activeView, string filter)
		{
			return activeView.SelectedToolboxItemSupportsFilterString(filter);
		}
		/// <summary>
		/// Override to provide the right mouse action when trying
		/// to create links on the diagram
		/// </summary>
		/// <param name="pointArgs"></param>
		public override void OnViewMouseEnter(DslDiagrams::DiagramPointEventArgs pointArgs)
		{
			if (pointArgs  == null) throw new global::System.ArgumentNullException("pointArgs");
		
			DslDiagrams::DiagramView activeView = this.ActiveDiagramView;
			if(activeView != null)
			{
				DslDiagrams::MouseAction action = null;
				if (SelectedToolboxItemSupportsFilterString(activeView, global::Microsoft.Data.Entity.Design.EntityDesigner.MicrosoftDataEntityDesignToolboxHelper.AssociationToolFilterString))
				{
					if (this.associationToolConnectAction == null)
					{
						this.associationToolConnectAction = new global::Microsoft.Data.Entity.Design.EntityDesigner.AssociationToolConnectAction(this);
						this.associationToolConnectAction.MouseActionDeactivated += new DslDiagrams::MouseAction.MouseActionDeactivatedEventHandler(OnConnectActionDeactivated);
					}
					action = this.associationToolConnectAction;
				} 
				else if (SelectedToolboxItemSupportsFilterString(activeView, global::Microsoft.Data.Entity.Design.EntityDesigner.MicrosoftDataEntityDesignToolboxHelper.InheritanceToolFilterString))
				{
					if (this.inheritanceToolConnectAction == null)
					{
						this.inheritanceToolConnectAction = new global::Microsoft.Data.Entity.Design.EntityDesigner.InheritanceToolConnectAction(this);
						this.inheritanceToolConnectAction.MouseActionDeactivated += new DslDiagrams::MouseAction.MouseActionDeactivatedEventHandler(OnConnectActionDeactivated);
					}
					action = this.inheritanceToolConnectAction;
				} 
				else
				{
					action = null;
				}
				
				if (pointArgs.DiagramClientView.ActiveMouseAction != action)
				{
					try
					{
						this.changingMouseAction = true;
						pointArgs.DiagramClientView.ActiveMouseAction = action;
					}
					finally
					{
						this.changingMouseAction = false;
					}
				}
			}
		}
		
		/// <summary>
		/// Snap toolbox selection back to regular pointer after using a custom connect action.
		/// </summary>
		private void OnConnectActionDeactivated(object sender, DslDiagrams::DiagramEventArgs e)
		{
			OnMouseActionDeactivated();
		}
		
		/// <summary>
		/// Overridable method to manage the mouse deactivation. The default implementation snap stoolbox selection back to regular pointer 
		/// after using a custom connect action.
		/// </summary>
		protected virtual void OnMouseActionDeactivated()
		{
			DslDiagrams::DiagramView activeView = this.ActiveDiagramView;
		
			if (activeView != null && activeView.Toolbox != null)
			{
				// If we're not changing mouse action due to changing toolbox selection change,
				// reset toolbox selection.
				if (!this.changingMouseAction)
				{
					activeView.Toolbox.SelectedToolboxItemUsed();
				}
			}
		}
		#endregion
		
		/// <summary>
		/// Dispose of connect actions.
		/// </summary>
		protected override void Dispose(bool disposing)
		{
			try
			{
				if(disposing)
				{
					if(this.associationToolConnectAction != null)
					{
						this.associationToolConnectAction.Dispose();
						this.associationToolConnectAction = null;
					}
					if(this.inheritanceToolConnectAction != null)
					{
						this.inheritanceToolConnectAction.Dispose();
						this.inheritanceToolConnectAction = null;
					}
					this.UnsubscribeCompartmentItemsEvents();
				}
			}
			finally
			{
				base.Dispose(disposing);
			}
		}
		#region Constructors, domain class Id
	
		/// <summary>
		/// EntityDesignerDiagram domain class Id.
		/// </summary>
		public static readonly new global::System.Guid DomainClassId = new global::System.Guid(0x3daa738d, 0xa8aa, 0x4f0c, 0xb9, 0x8b, 0xdb, 0x13, 0x82, 0x98, 0x52, 0x64);
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="partition">Partition where new element is to be created.</param>
		/// <param name="propertyAssignments">List of domain property id/value pairs to set once the element is created.</param>
		protected EntityDesignerDiagramBase(DslModeling::Partition partition, DslModeling::PropertyAssignment[] propertyAssignments)
			: base(partition, propertyAssignments)
		{
		}
		#endregion
		#region Title domain property code
		
		/// <summary>
		/// Title domain property Id.
		/// </summary>
		public static readonly global::System.Guid TitleDomainPropertyId = new global::System.Guid(0x83fe8dc3, 0xd17f, 0x471c, 0x8b, 0xf7, 0x12, 0x87, 0x99, 0x39, 0x9a, 0xf3);
		
		/// <summary>
		/// Storage for Title
		/// </summary>
		private global::System.String titlePropertyStorage = string.Empty;
		
		/// <summary>
		/// Gets or sets the value of Title domain property.
		/// Description for
		/// Microsoft.Data.Entity.Design.EntityDesigner.View.EntityDesignerDiagram.Title
		/// </summary>
		[DslDesign::DisplayNameResource("Microsoft.Data.Entity.Design.EntityDesigner.View.EntityDesignerDiagram/Title.DisplayName", typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.MicrosoftDataEntityDesignDomainModel), "Microsoft.Data.Entity.Design.EntityDesigner.GeneratedCode.DomainModelResx")]
		[DslDesign::DescriptionResource("Microsoft.Data.Entity.Design.EntityDesigner.View.EntityDesignerDiagram/Title.Description", typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.MicrosoftDataEntityDesignDomainModel), "Microsoft.Data.Entity.Design.EntityDesigner.GeneratedCode.DomainModelResx")]
		[DslModeling::DomainObjectId("83fe8dc3-d17f-471c-8bf7-128799399af3")]
		public global::System.String Title
		{
			[global::System.Diagnostics.DebuggerStepThrough]
			get
			{
				return titlePropertyStorage;
			}
			[global::System.Diagnostics.DebuggerStepThrough]
			set
			{
				TitlePropertyHandler.Instance.SetValue(this, value);
			}
		}
		/// <summary>
		/// Value handler for the EntityDesignerDiagram.Title domain property.
		/// </summary>
		internal sealed partial class TitlePropertyHandler : DslModeling::DomainPropertyValueHandler<EntityDesignerDiagramBase, global::System.String>
		{
			private TitlePropertyHandler() { }
		
			/// <summary>
			/// Gets the singleton instance of the EntityDesignerDiagram.Title domain property value handler.
			/// </summary>
			public static readonly TitlePropertyHandler Instance = new TitlePropertyHandler();
		
			/// <summary>
			/// Gets the Id of the EntityDesignerDiagram.Title domain property.
			/// </summary>
			public sealed override global::System.Guid DomainPropertyId
			{
				[global::System.Diagnostics.DebuggerStepThrough]
				get
				{
					return TitleDomainPropertyId;
				}
			}
			
			/// <summary>
			/// Gets a strongly-typed value of the property on specified element.
			/// </summary>
			/// <param name="element">Element which owns the property.</param>
			/// <returns>Property value.</returns>
			public override sealed global::System.String GetValue(EntityDesignerDiagramBase element)
			{
				if (element == null) throw new global::System.ArgumentNullException("element");
				return element.titlePropertyStorage;
			}
		
			/// <summary>
			/// Sets property value on an element.
			/// </summary>
			/// <param name="element">Element which owns the property.</param>
			/// <param name="newValue">New property value.</param>
			public override sealed void SetValue(EntityDesignerDiagramBase element, global::System.String newValue)
			{
				if (element == null) throw new global::System.ArgumentNullException("element");
		
				global::System.String oldValue = GetValue(element);
				if (newValue != oldValue)
				{
					ValueChanging(element, oldValue, newValue);
					element.titlePropertyStorage = newValue;
					ValueChanged(element, oldValue, newValue);
				}
			}
		}
		
		#endregion
	}
	/// <summary>
	/// DomainClass EntityDesignerDiagram
	/// </summary>
			
	internal partial class EntityDesignerDiagram : EntityDesignerDiagramBase
	{
		#region Constructors
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="store">Store where new element is to be created.</param>
		/// <param name="propertyAssignments">List of domain property id/value pairs to set once the element is created.</param>
		public EntityDesignerDiagram(DslModeling::Store store, params DslModeling::PropertyAssignment[] propertyAssignments)
			: this(store != null ? store.DefaultPartitionForClass(DomainClassId) : null, propertyAssignments)
		{
		}
		
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="partition">Partition where new element is to be created.</param>
		/// <param name="propertyAssignments">List of domain property id/value pairs to set once the element is created.</param>
		public EntityDesignerDiagram(DslModeling::Partition partition, params DslModeling::PropertyAssignment[] propertyAssignments)
			: base(partition, propertyAssignments)
		{
		}
		#endregion
	}
}
namespace Microsoft.Data.Entity.Design.EntityDesigner.View
{
	
		/// <summary>
		/// Double derived implementation for the rule that initiates view fixup when an element that has an associated shape is added to the model.
		/// This now enables the DSL author to everride the SkipFixUp() method 
		/// </summary>
		internal partial class FixUpDiagramBase : DslModeling::AddRule
		{
			protected virtual bool SkipFixup(DslModeling::ModelElement childElement)
			{
				return childElement.IsDeleted;
			}
		}
	
		/// <summary>
		/// Rule that initiates view fixup when an element that has an associated shape is added to the model. 
		/// </summary>
		[DslModeling::RuleOn(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityType), FireTime = DslModeling::TimeToFire.TopLevelCommit, Priority = DslDiagrams::DiagramFixupConstants.AddShapeParentExistRulePriority, InitiallyDisabled=true)]
		[DslModeling::RuleOn(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Inheritance), FireTime = DslModeling::TimeToFire.TopLevelCommit, Priority = DslDiagrams::DiagramFixupConstants.AddConnectionRulePriority, InitiallyDisabled=true)]
		[DslModeling::RuleOn(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Association), FireTime = DslModeling::TimeToFire.TopLevelCommit, Priority = DslDiagrams::DiagramFixupConstants.AddConnectionRulePriority, InitiallyDisabled=true)]
		internal sealed partial class FixUpDiagram : FixUpDiagramBase
		{
			[global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
			public override void ElementAdded(DslModeling::ElementAddedEventArgs e)
			{
				if(e == null) throw new global::System.ArgumentNullException("e");
			
				DslModeling::ModelElement childElement = e.ModelElement;
				if (this.SkipFixup(childElement))
					return;
				DslModeling::ModelElement parentElement;
				if(childElement is DslModeling::ElementLink)
				{
					parentElement = GetParentForRelationship((DslModeling::ElementLink)childElement);
				} else
				if(childElement is global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityType)
				{
					parentElement = GetParentForEntityType((global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityType)childElement);
				} else
				{
					parentElement = null;
				}
				
				if(parentElement != null)
				{
					DslDiagrams::Diagram.FixUpDiagram(parentElement, childElement);
				}
			}
			public static global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityDesignerViewModel GetParentForEntityType( global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityType root )
			{
				// Segments 0 and 1
				global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityDesignerViewModel result = root.EntityDesignerViewModel;
				if ( result == null ) return null;
				return result;
			}
			private static DslModeling::ModelElement GetParentForRelationship(DslModeling::ElementLink elementLink)
			{
				global::System.Collections.ObjectModel.ReadOnlyCollection<DslModeling::ModelElement> linkedElements = elementLink.LinkedElements;
	
				if (linkedElements.Count == 2)
				{
					DslDiagrams::ShapeElement sourceShape = linkedElements[0] as DslDiagrams::ShapeElement;
					DslDiagrams::ShapeElement targetShape = linkedElements[1] as DslDiagrams::ShapeElement;
	
					if(sourceShape == null)
					{
						DslModeling::LinkedElementCollection<DslDiagrams::PresentationElement> presentationElements = DslDiagrams::PresentationViewsSubject.GetPresentation(linkedElements[0]);
						foreach (DslDiagrams::PresentationElement presentationElement in presentationElements)
						{
							DslDiagrams::ShapeElement shape = presentationElement as DslDiagrams::ShapeElement;
							if (shape != null)
							{
								sourceShape = shape;
								break;
							}
						}
					}
					
					if(targetShape == null)
					{
						DslModeling::LinkedElementCollection<DslDiagrams::PresentationElement> presentationElements = DslDiagrams::PresentationViewsSubject.GetPresentation(linkedElements[1]);
						foreach (DslDiagrams::PresentationElement presentationElement in presentationElements)
						{
							DslDiagrams::ShapeElement shape = presentationElement as DslDiagrams::ShapeElement;
							if (shape != null)
							{
								targetShape = shape;
								break;
							}
						}
					}
					
					if(sourceShape == null || targetShape == null)
					{
						global::System.Diagnostics.Debug.Fail("Unable to find source and/or target shape for view fixup.");
						return null;
					}
	
					DslDiagrams::ShapeElement sourceParent = sourceShape.ParentShape;
					DslDiagrams::ShapeElement targetParent = targetShape.ParentShape;
	
					while (sourceParent != targetParent && sourceParent != null)
					{
						DslDiagrams::ShapeElement curParent = targetParent;
						while (sourceParent != curParent && curParent != null)
						{
							curParent = curParent.ParentShape;
						}
	
						if(sourceParent == curParent)
						{
							break;
						}
						else
						{
							sourceParent = sourceParent.ParentShape;
						}
					}
	
					while (sourceParent != null)
					{
						// ensure that the parent can parent connectors (i.e., a diagram or a swimlane).
						if(sourceParent is DslDiagrams::Diagram || sourceParent is DslDiagrams::SwimlaneShape)
						{
							break;
						}
						else
						{
							sourceParent = sourceParent.ParentShape;
						}
					}
	
					global::System.Diagnostics.Debug.Assert(sourceParent != null && sourceParent.ModelElement != null, "Unable to find common parent for view fixup.");
					return sourceParent.ModelElement;
				}
	
				return null;
			}
		}
		
		/// <summary>
		/// Rule to update compartments when an item is added to the list
		/// </summary>
		[DslModeling::RuleOn(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasNavigationProperties), FireTime=DslModeling::TimeToFire.TopLevelCommit, InitiallyDisabled=true)]
		[DslModeling::RuleOn(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasProperties), FireTime=DslModeling::TimeToFire.TopLevelCommit, InitiallyDisabled=true)]
		internal sealed class CompartmentItemAddRule : DslModeling::AddRule
		{
			/// <summary>
			/// Called when an element is added. 
			/// </summary>
			/// <param name="e"></param>
			public override void ElementAdded(DslModeling::ElementAddedEventArgs e)
			{
				ElementAdded(e, false);
			}
	
			internal static void ElementAdded(DslModeling::ElementAddedEventArgs e, bool repaintOnly)
			{
				if(e==null) throw new global::System.ArgumentNullException("e");
				if (e.ModelElement.IsDeleted)
					return;
				if(e.ModelElement is global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasNavigationProperties)
				{
					global::System.Collections.IEnumerable elements = GetEntityTypeForEntityTypeShapeNavigationFromLastLink((global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasNavigationProperties)e.ModelElement);
					UpdateCompartments(elements, typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityTypeShape), "Navigation", repaintOnly);
				}
				if(e.ModelElement is global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasProperties)
				{
					global::System.Collections.IEnumerable elements = GetEntityTypeForEntityTypeShapePropertiesFromLastLink((global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasProperties)e.ModelElement);
					UpdateCompartments(elements, typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityTypeShape), "Properties", repaintOnly);
				}
			}
			
			#region static DomainPath traversal methods to get the list of compartments to update
			internal static global::System.Collections.ICollection GetEntityTypeForEntityTypeShapeNavigationFromLastLink(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasNavigationProperties root)
			{
				// Segment 0
				global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityType result = root.EntityType;
				if ( result == null ) return new DslModeling::ModelElement[0];
				return new DslModeling::ModelElement[] {result};
			}
			internal static global::System.Collections.ICollection GetEntityTypeForEntityTypeShapeNavigation(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.NavigationProperty root)
			{
				// Segments 1 and 0
				global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityType result = root.EntityType;
				if ( result == null ) return new DslModeling::ModelElement[0];
				return new DslModeling::ModelElement[] {result};
			}
			internal static global::System.Collections.ICollection GetEntityTypeForEntityTypeShapePropertiesFromLastLink(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasProperties root)
			{
				// Segment 0
				global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityType result = root.EntityType;
				if ( result == null ) return new DslModeling::ModelElement[0];
				return new DslModeling::ModelElement[] {result};
			}
			internal static global::System.Collections.ICollection GetEntityTypeForEntityTypeShapeProperties(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Property root)
			{
				// Segments 1 and 0
				global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityType result = root.EntityType;
				if ( result == null ) return new DslModeling::ModelElement[0];
				return new DslModeling::ModelElement[] {result};
			}
			#endregion
	
			#region helper method to update compartments 
			/// <summary>
			/// Updates the compartments for the shapes associated to the given list of model elements
			/// </summary>
			/// <param name="elements">List of model elements</param>
			/// <param name="shapeType">The type of shape that needs updating</param>
			/// <param name="compartmentName">The name of the compartment to update</param>
			/// <param name="repaintOnly">If true, the method will only invalidate the shape for a repaint, without re-initializing the shape.</param>
			internal static void UpdateCompartments(global::System.Collections.IEnumerable elements, global::System.Type shapeType, string compartmentName, bool repaintOnly)
			{
				foreach (DslModeling::ModelElement element in elements)
				{
					DslModeling::LinkedElementCollection<DslDiagrams::PresentationElement> pels = DslDiagrams::PresentationViewsSubject.GetPresentation(element);
					foreach (DslDiagrams::PresentationElement pel in pels)
					{
						DslDiagrams::CompartmentShape compartmentShape = pel as DslDiagrams::CompartmentShape;
						if (compartmentShape != null && shapeType.IsAssignableFrom(compartmentShape.GetType()))
						{
							if (repaintOnly)
							{
								compartmentShape.Invalidate();
							}
							else
							{
								foreach(DslDiagrams::CompartmentMapping mapping in compartmentShape.GetCompartmentMappings())
								{
									if(mapping.CompartmentId==compartmentName)
									{
										mapping.InitializeCompartmentShape(compartmentShape);
										break;
									}
								}
							}
						}
					}
				}
			}
			#endregion
		}
		
		/// <summary>
		/// Rule to update compartments when an items is removed from the list
		/// </summary>
		[DslModeling::RuleOn(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasNavigationProperties), FireTime=DslModeling::TimeToFire.TopLevelCommit, InitiallyDisabled=true)]
		[DslModeling::RuleOn(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasProperties), FireTime=DslModeling::TimeToFire.TopLevelCommit, InitiallyDisabled=true)]
		internal sealed class CompartmentItemDeleteRule : DslModeling::DeleteRule
		{
			/// <summary>
			/// Called when an element is deleted
			/// </summary>
			/// <param name="e"></param>
			public override void ElementDeleted(DslModeling::ElementDeletedEventArgs e)
			{
				ElementDeleted(e, false);
			}
			
			internal static void ElementDeleted(DslModeling::ElementDeletedEventArgs e, bool repaintOnly)
			{
				if(e==null) throw new global::System.ArgumentNullException("e");
				if(e.ModelElement is global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasNavigationProperties)
				{
					global::System.Collections.ICollection elements = CompartmentItemAddRule.GetEntityTypeForEntityTypeShapeNavigationFromLastLink((global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasNavigationProperties)e.ModelElement);
					CompartmentItemAddRule.UpdateCompartments(elements, typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityTypeShape), "Navigation", repaintOnly);
				}
				if(e.ModelElement is global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasProperties)
				{
					global::System.Collections.ICollection elements = CompartmentItemAddRule.GetEntityTypeForEntityTypeShapePropertiesFromLastLink((global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasProperties)e.ModelElement);
					CompartmentItemAddRule.UpdateCompartments(elements, typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityTypeShape), "Properties", repaintOnly);
				}
			}
		}
		
		/// <summary>
		/// Rule to update compartments when the property on an item being displayed changes.
		/// </summary>
		[DslModeling::RuleOn(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.NavigationProperty), FireTime=DslModeling::TimeToFire.TopLevelCommit, InitiallyDisabled=true)]
		[DslModeling::RuleOn(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Property), FireTime=DslModeling::TimeToFire.TopLevelCommit, InitiallyDisabled=true)]
		internal sealed class CompartmentItemChangeRule : DslModeling::ChangeRule 
		{
			/// <summary>
			/// Called when an element is changed
			/// </summary>
			/// <param name="e"></param>
			public override void ElementPropertyChanged(DslModeling::ElementPropertyChangedEventArgs e)
			{
				ElementPropertyChanged(e, false);
			}
			
			internal static void ElementPropertyChanged(DslModeling::ElementPropertyChangedEventArgs e, bool repaintOnly)
			{
				if(e==null) throw new global::System.ArgumentNullException("e");
				if(e.ModelElement is global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.NavigationProperty && e.DomainProperty.Id == global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.NavigationProperty.NameDomainPropertyId)
				{
					global::System.Collections.IEnumerable elements = CompartmentItemAddRule.GetEntityTypeForEntityTypeShapeNavigation((global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.NavigationProperty)e.ModelElement);
					CompartmentItemAddRule.UpdateCompartments(elements, typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityTypeShape), "Navigation", repaintOnly);
				}
				if(e.ModelElement is global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Property && e.DomainProperty.Id == global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Property.NameDomainPropertyId)
				{
					global::System.Collections.IEnumerable elements = CompartmentItemAddRule.GetEntityTypeForEntityTypeShapeProperties((global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Property)e.ModelElement);
					CompartmentItemAddRule.UpdateCompartments(elements, typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityTypeShape), "Properties", repaintOnly);
				}
			}
		}
		
		/// <summary>
		/// Rule to update compartments when a roleplayer change happens
		/// </summary>
		[DslModeling::RuleOn(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasNavigationProperties), FireTime=DslModeling::TimeToFire.TopLevelCommit, InitiallyDisabled=true)]
		[DslModeling::RuleOn(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasProperties), FireTime=DslModeling::TimeToFire.TopLevelCommit, InitiallyDisabled=true)]
		internal sealed class CompartmentItemRolePlayerChangeRule : DslModeling::RolePlayerChangeRule 
		{
			/// <summary>
			/// Called when the roleplayer on a link changes.
			/// </summary>
			/// <param name="e"></param>
			public override void RolePlayerChanged(DslModeling::RolePlayerChangedEventArgs e)
			{
				RolePlayerChanged(e, false);
			}
			
			internal static void RolePlayerChanged(DslModeling::RolePlayerChangedEventArgs e, bool repaintOnly)
			{
				if(e==null) throw new global::System.ArgumentNullException("e");
				if(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasNavigationProperties).IsAssignableFrom(e.DomainRelationship.ImplementationClass))
				{
					if(e.DomainRole.IsSource)
					{
						//global::System.Collections.IEnumerable oldElements = CompartmentItemAddRule.GetEntityTypeForEntityTypeShapeNavigationFromLastLink((global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.NavigationProperty)e.OldRolePlayer);
						//foreach(DslModeling::ModelElement element in oldElements)
						//{
						//	DslModeling::LinkedElementCollection<DslDiagrams::PresentationElement> pels = DslDiagrams::PresentationViewsSubject.GetPresentation(element);
						//	foreach(DslDiagrams::PresentationElement pel in pels)
						//	{
						//		global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityTypeShape compartmentShape = pel as global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityTypeShape;
						//		if(compartmentShape != null)
						//		{
						//			compartmentShape.GetCompartmentMappings()[0].InitializeCompartmentShape(compartmentShape);
						//		}
						//	}
						//}
						
						global::System.Collections.IEnumerable elements = CompartmentItemAddRule.GetEntityTypeForEntityTypeShapeNavigationFromLastLink((global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasNavigationProperties)e.ElementLink);
						CompartmentItemAddRule.UpdateCompartments(elements, typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityTypeShape), "Navigation", repaintOnly);
					}
					else 
					{
						global::System.Collections.IEnumerable elements = CompartmentItemAddRule.GetEntityTypeForEntityTypeShapeNavigation((global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.NavigationProperty)e.NewRolePlayer);
						CompartmentItemAddRule.UpdateCompartments(elements, typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityTypeShape), "Navigation", repaintOnly);
					}
				}
				if(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasProperties).IsAssignableFrom(e.DomainRelationship.ImplementationClass))
				{
					if(e.DomainRole.IsSource)
					{
						//global::System.Collections.IEnumerable oldElements = CompartmentItemAddRule.GetEntityTypeForEntityTypeShapePropertiesFromLastLink((global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Property)e.OldRolePlayer);
						//foreach(DslModeling::ModelElement element in oldElements)
						//{
						//	DslModeling::LinkedElementCollection<DslDiagrams::PresentationElement> pels = DslDiagrams::PresentationViewsSubject.GetPresentation(element);
						//	foreach(DslDiagrams::PresentationElement pel in pels)
						//	{
						//		global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityTypeShape compartmentShape = pel as global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityTypeShape;
						//		if(compartmentShape != null)
						//		{
						//			compartmentShape.GetCompartmentMappings()[1].InitializeCompartmentShape(compartmentShape);
						//		}
						//	}
						//}
						
						global::System.Collections.IEnumerable elements = CompartmentItemAddRule.GetEntityTypeForEntityTypeShapePropertiesFromLastLink((global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasProperties)e.ElementLink);
						CompartmentItemAddRule.UpdateCompartments(elements, typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityTypeShape), "Properties", repaintOnly);
					}
					else 
					{
						global::System.Collections.IEnumerable elements = CompartmentItemAddRule.GetEntityTypeForEntityTypeShapeProperties((global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Property)e.NewRolePlayer);
						CompartmentItemAddRule.UpdateCompartments(elements, typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityTypeShape), "Properties", repaintOnly);
					}
				}
			}
		}
	
		/// <summary>
		/// Rule to update compartments when the order of items in the list changes.
		/// </summary>
		[DslModeling::RuleOn(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasNavigationProperties), FireTime=DslModeling::TimeToFire.TopLevelCommit, InitiallyDisabled=true)]
		[DslModeling::RuleOn(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasProperties), FireTime=DslModeling::TimeToFire.TopLevelCommit, InitiallyDisabled=true)]
		internal sealed class CompartmentItemRolePlayerPositionChangeRule : DslModeling::RolePlayerPositionChangeRule 
		{
			/// <summary>
			/// Called when the order of a roleplayer in a relationship changes
			/// </summary>
			/// <param name="e"></param>
			public override void RolePlayerPositionChanged(DslModeling::RolePlayerOrderChangedEventArgs e)
			{
				RolePlayerPositionChanged(e, false);
			}
			
			internal static void RolePlayerPositionChanged(DslModeling::RolePlayerOrderChangedEventArgs e, bool repaintOnly)
			{
				if(e==null) throw new global::System.ArgumentNullException("e");
				if(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasNavigationProperties).IsAssignableFrom(e.DomainRelationship.ImplementationClass))
				{
					if(!e.CounterpartDomainRole.IsSource)
					{
						global::System.Collections.IEnumerable elements = CompartmentItemAddRule.GetEntityTypeForEntityTypeShapeNavigation((global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.NavigationProperty)e.CounterpartRolePlayer);
						CompartmentItemAddRule.UpdateCompartments(elements, typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityTypeShape), "Navigation", repaintOnly);
					}
				}
				if(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityTypeHasProperties).IsAssignableFrom(e.DomainRelationship.ImplementationClass))
				{
					if(!e.CounterpartDomainRole.IsSource)
					{
						global::System.Collections.IEnumerable elements = CompartmentItemAddRule.GetEntityTypeForEntityTypeShapeProperties((global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Property)e.CounterpartRolePlayer);
						CompartmentItemAddRule.UpdateCompartments(elements, typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityTypeShape), "Properties", repaintOnly);
					}
				}
			}
		}
	
		/// <summary>
		/// A rule which fires when data mapped to outer text decorators has changed,
		/// so we can update the decorator host's bounds.
		/// </summary>
		[DslModeling::RuleOn(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Association), InitiallyDisabled=true)]
		internal sealed class DecoratorPropertyChanged : DslModeling::ChangeRule
		{
			[global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Generated code.")]
			public override void ElementPropertyChanged(DslModeling::ElementPropertyChangedEventArgs e)
			{
				if(e == null) throw new global::System.ArgumentNullException("e");
				
				if (e.DomainProperty.Id == global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Association.SourceMultiplicityDomainPropertyId)
				{
					DslDiagrams::Decorator decorator = global::Microsoft.Data.Entity.Design.EntityDesigner.View.AssociationConnector.FindAssociationConnectorDecorator("SourceEndDisplayText");
					if(decorator != null)
					{
						decorator.UpdateDecoratorHostShapes(e.ModelElement, global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Association.DomainClassId);
					}
				}
				else if (e.DomainProperty.Id == global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Association.TargetMultiplicityDomainPropertyId)
				{
					DslDiagrams::Decorator decorator = global::Microsoft.Data.Entity.Design.EntityDesigner.View.AssociationConnector.FindAssociationConnectorDecorator("TargetEndDisplayText");
					if(decorator != null)
					{
						decorator.UpdateDecoratorHostShapes(e.ModelElement, global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Association.DomainClassId);
					}
				}
			}
		}
	
		/// <summary>
		/// Reroute a connector when the role players of its underlying relationship change
		/// </summary>
		[DslModeling::RuleOn(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Association), FireTime = DslModeling::TimeToFire.TopLevelCommit, Priority = DslDiagrams::DiagramFixupConstants.AddConnectionRulePriority, InitiallyDisabled=true)]
		[DslModeling::RuleOn(typeof(global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.Inheritance), FireTime = DslModeling::TimeToFire.TopLevelCommit, Priority = DslDiagrams::DiagramFixupConstants.AddConnectionRulePriority, InitiallyDisabled=true)]
		internal sealed class ConnectorRolePlayerChanged : DslModeling::RolePlayerChangeRule
		{
			/// <summary>
			/// Reroute a connector when the role players of its underlying relationship change
			/// </summary>
			public override void RolePlayerChanged(DslModeling::RolePlayerChangedEventArgs e)
			{
				if (e == null) throw new global::System.ArgumentNullException("e");
	
				global::System.Collections.ObjectModel.ReadOnlyCollection<DslDiagrams::PresentationViewsSubject> connectorLinks = DslDiagrams::PresentationViewsSubject.GetLinksToPresentation(e.ElementLink);
				foreach (DslDiagrams::PresentationViewsSubject connectorLink in connectorLinks)
				{
					// Fix up any binary link shapes attached to the element link.
					DslDiagrams::BinaryLinkShape linkShape = connectorLink.Presentation as DslDiagrams::BinaryLinkShape;
					if (linkShape != null)
					{
						global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityDesignerDiagram diagram = linkShape.Diagram as global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityDesignerDiagram;
						if (diagram != null)
						{
							if (e.NewRolePlayer != null)
							{
								DslDiagrams::NodeShape fromShape;
								DslDiagrams::NodeShape toShape;
								diagram.GetSourceAndTargetForConnector(linkShape, out fromShape, out toShape);
								if (fromShape != null && toShape != null)
								{
									if (!object.Equals(fromShape, linkShape.FromShape))
									{
										linkShape.FromShape = fromShape;
									}
									if (!object.Equals(linkShape.ToShape, toShape))
									{
										linkShape.ToShape = toShape;
									}
								}
								else
								{
									// delete the connector if we cannot find an appropriate target shape.
									linkShape.Delete();
								}
							}
							else
							{
								// delete the connector if the new role player is null.
								linkShape.Delete();
							}
						}
					}
				}
			}
		}
	}
