From: <mcu...@us...> - 2008-10-17 15:32:27
|
Revision: 1326 http://orm.svn.sourceforge.net/orm/?rev=1326&view=rev Author: mcurland Date: 2008-10-17 15:32:09 +0000 (Fri, 17 Oct 2008) Log Message: ----------- Add role player change rule to automatically set the ExpandRefMode property as needed. fixes #373 Modified Paths: -------------- trunk/ORMModel/ShapeModel/ORMShape.AttachRules.cs trunk/ORMModel/ShapeModel/ORMShape.AttachRules.xml trunk/ORMModel/ShapeModel/ObjectTypeShape.cs Modified: trunk/ORMModel/ShapeModel/ORMShape.AttachRules.cs =================================================================== --- trunk/ORMModel/ShapeModel/ORMShape.AttachRules.cs 2008-09-05 00:45:22 UTC (rev 1325) +++ trunk/ORMModel/ShapeModel/ORMShape.AttachRules.cs 2008-10-17 15:32:09 UTC (rev 1326) @@ -70,6 +70,7 @@ typeof(ObjectTypeShape).GetNestedType("PreferredIdentifierShortenedRuleClass", BindingFlags.Public | BindingFlags.NonPublic), typeof(ObjectTypeShape).GetNestedType("RolePlayerAddedRuleClass", BindingFlags.Public | BindingFlags.NonPublic), typeof(ObjectTypeShape).GetNestedType("RolePlayerDeleteRuleClass", BindingFlags.Public | BindingFlags.NonPublic), + typeof(ObjectTypeShape).GetNestedType("RolePlayerRolePlayerChangedRuleClass", BindingFlags.Public | BindingFlags.NonPublic), typeof(ORMBaseBinaryLinkShape).GetNestedType("LinkChangeRuleClass", BindingFlags.Public | BindingFlags.NonPublic), typeof(ORMBaseShape).GetNestedType("AbsoluteBoundsChangedRuleClass", BindingFlags.Public | BindingFlags.NonPublic), typeof(ORMBaseShape).GetNestedType("ModelErrorAddedRuleClass", BindingFlags.Public | BindingFlags.NonPublic), @@ -144,7 +145,7 @@ { Microsoft.VisualStudio.Modeling.RuleManager ruleManager = store.RuleManager; Type[] disabledRuleTypes = ORMShapeDomainModel.CustomDomainModelTypes; - for (int i = 0; i < 77; ++i) + for (int i = 0; i < 78; ++i) { ruleManager.EnableRule(disabledRuleTypes[i]); } @@ -1120,6 +1121,32 @@ Neumont.Tools.Modeling.Diagnostics.TraceUtility.TraceRuleEnd(e.ModelElement.Store, "Neumont.Tools.ORM.ShapeModel.ObjectTypeShape.RolePlayerDeleteRule"); } } + [Microsoft.VisualStudio.Modeling.RuleOn(typeof(Neumont.Tools.ORM.ObjectModel.ObjectTypePlaysRole), Priority=Neumont.Tools.Modeling.FrameworkDomainModel.InlineRulePriority)] + private sealed class RolePlayerRolePlayerChangedRuleClass : Microsoft.VisualStudio.Modeling.RolePlayerChangeRule + { + [System.Diagnostics.DebuggerStepThrough()] + public RolePlayerRolePlayerChangedRuleClass() + { + base.IsEnabled = false; + } + /// <summary> + /// Provide the following method in class: + /// Neumont.Tools.ORM.ShapeModel.ObjectTypeShape + /// /// <summary> + /// /// RolePlayerChangeRule: typeof(Neumont.Tools.ORM.ObjectModel.ObjectTypePlaysRole) + /// /// </summary> + /// private static void RolePlayerRolePlayerChangedRule(RolePlayerChangedEventArgs e) + /// { + /// } + /// </summary> + [System.Diagnostics.DebuggerStepThrough()] + public override void RolePlayerChanged(Microsoft.VisualStudio.Modeling.RolePlayerChangedEventArgs e) + { + Neumont.Tools.Modeling.Diagnostics.TraceUtility.TraceRuleStart(e.ElementLink.Store, "Neumont.Tools.ORM.ShapeModel.ObjectTypeShape.RolePlayerRolePlayerChangedRule"); + ObjectTypeShape.RolePlayerRolePlayerChangedRule(e); + Neumont.Tools.Modeling.Diagnostics.TraceUtility.TraceRuleEnd(e.ElementLink.Store, "Neumont.Tools.ORM.ShapeModel.ObjectTypeShape.RolePlayerRolePlayerChangedRule"); + } + } } #endregion // Rule classes for ObjectTypeShape #region Rule classes for ORMBaseBinaryLinkShape Modified: trunk/ORMModel/ShapeModel/ORMShape.AttachRules.xml =================================================================== --- trunk/ORMModel/ShapeModel/ORMShape.AttachRules.xml 2008-09-05 00:45:22 UTC (rev 1325) +++ trunk/ORMModel/ShapeModel/ORMShape.AttachRules.xml 2008-10-17 15:32:09 UTC (rev 1326) @@ -139,6 +139,9 @@ <arg:DeleteRule methodName="RolePlayerDeleteRule"> <arg:RuleOn targetType="ObjectTypePlaysRole" targetTypeQualifier="Neumont.Tools.ORM.ObjectModel" fireTime="TopLevelCommit" priority="DiagramFixupConstants.ResizeParentRulePriority"/> </arg:DeleteRule> + <arg:RolePlayerChangeRule methodName="RolePlayerRolePlayerChangedRule"> + <arg:RuleOn targetType="ObjectTypePlaysRole" targetTypeQualifier="Neumont.Tools.ORM.ObjectModel"/> + </arg:RolePlayerChangeRule> </arg:RuleContainer> <arg:RuleContainer class="ORMBaseBinaryLinkShape"> <arg:ChangeRule methodName="LinkChangeRule"> Modified: trunk/ORMModel/ShapeModel/ObjectTypeShape.cs =================================================================== --- trunk/ORMModel/ShapeModel/ObjectTypeShape.cs 2008-09-05 00:45:22 UTC (rev 1325) +++ trunk/ORMModel/ShapeModel/ObjectTypeShape.cs 2008-10-17 15:32:09 UTC (rev 1326) @@ -718,6 +718,76 @@ } } } + /// <summary> + /// RolePlayerChangeRule: typeof(Neumont.Tools.ORM.ObjectModel.ObjectTypePlaysRole) + /// Changing the identifying role player of a FactType that participates in the refmode + /// pattern needs to appropriately update the ExpandRefMode property and to resize + /// shapes for the identified object types. + /// </summary> + private static void RolePlayerRolePlayerChangedRule(RolePlayerChangedEventArgs e) + { + ObjectTypePlaysRole link = e.ElementLink as ObjectTypePlaysRole; + if (e.DomainRole.Id == ObjectTypePlaysRole.RolePlayerDomainRoleId) + { + bool newPlayerIsValueType = link.RolePlayer.IsValueType; + bool oldPlayerIsValueType = ((ObjectType)e.OldRolePlayer).IsValueType; + if ((newPlayerIsValueType || oldPlayerIsValueType) && + (newPlayerIsValueType != oldPlayerIsValueType)) + { + LinkedElementCollection<ConstraintRoleSequence> sequences = link.PlayedRole.ConstraintRoleSequenceCollection; + int constraintsCount = sequences.Count; + for (int i = 0; i < constraintsCount; ++i) + { + UniquenessConstraint iuc = sequences[i] as UniquenessConstraint; + if (iuc != null && iuc.IsInternal) + { + ObjectType preferredFor = iuc.PreferredIdentifierFor; + if (preferredFor != null) + { + if (newPlayerIsValueType) + { + EnsureRefModeExpanded(iuc, preferredFor); + } + else + { + ResizeAssociatedShapes(preferredFor); + } + } + } + } + } + } + else + { + // This can add an expanded reference mode for an object type associated with the new + // role player and remove the reference mode for the old player + if (link.RolePlayer.IsValueType) + { + LinkedElementCollection<ConstraintRoleSequence> sequences = link.PlayedRole.ConstraintRoleSequenceCollection; + int constraintsCount = sequences.Count; + for (int i = 0; i < constraintsCount; ++i) + { + UniquenessConstraint iuc = sequences[i] as UniquenessConstraint; + if (iuc != null && iuc.IsInternal) + { + ObjectType preferredFor = iuc.PreferredIdentifierFor; + if (preferredFor != null) + { + EnsureRefModeExpanded(iuc, preferredFor); + } + } + } + foreach (ConstraintRoleSequence sequence in ((Role)e.OldRolePlayer).ConstraintRoleSequenceCollection) + { + UniquenessConstraint iuc = sequence as UniquenessConstraint; + if (iuc != null && iuc.IsInternal) + { + ResizeAssociatedShapes(iuc.PreferredIdentifierFor); + } + } + } + } + } #endregion // Shape display update rules #region Store Event Handlers /// <summary> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |