From: <mcu...@us...> - 2007-08-08 00:38:30
|
Revision: 1079 http://orm.svn.sourceforge.net/orm/?rev=1079&view=rev Author: mcurland Date: 2007-08-07 17:38:27 -0700 (Tue, 07 Aug 2007) Log Message: ----------- Display unary FactType with a unary glyph in the model browser and correctly initialize FactTypeShape for unary dropped off the model browser. Required moving creation of single-role role display order for unaries to OnChildConfiguring. Doing this early eliminates the need for subsequent calls to AutoResize and for the fixup listener. Also made some of the fixup rules more robust for cases where the element is deleted before the shape can be created. refs #296 Modified Paths: -------------- trunk/ORMModel/ObjectModel/ORMModel.cs trunk/ORMModel/ObjectModel/SurveyImplementations/FactTypeAnswers.cs trunk/ORMModel/ShapeModel/FactTypeShape.cs trunk/ORMModel/ShapeModel/ORMDiagram.cs trunk/ORMModel/ShapeModel/ORMShape.DeserializationFixupListeners.cs trunk/ORMModel/ShapeModel/ViewFixupRules.cs trunk/ORMModel/Transforms/SerializationExtensions.xsd Modified: trunk/ORMModel/ObjectModel/ORMModel.cs =================================================================== --- trunk/ORMModel/ObjectModel/ORMModel.cs 2007-08-08 00:31:35 UTC (rev 1078) +++ trunk/ORMModel/ObjectModel/ORMModel.cs 2007-08-08 00:38:27 UTC (rev 1079) @@ -64,7 +64,7 @@ /// <summary> /// Fixup stored presentation elements /// </summary> - ModifyStoredPresentationElements = 700, + ModifyStoredPresentationElements = 600, /// <summary> /// Add any presentation elements that are implicit and not /// serialized with the model. Modified: trunk/ORMModel/ObjectModel/SurveyImplementations/FactTypeAnswers.cs =================================================================== --- trunk/ORMModel/ObjectModel/SurveyImplementations/FactTypeAnswers.cs 2007-08-08 00:31:35 UTC (rev 1078) +++ trunk/ORMModel/ObjectModel/SurveyImplementations/FactTypeAnswers.cs 2007-08-08 00:38:27 UTC (rev 1079) @@ -194,12 +194,14 @@ } else { - switch (RoleCollection.Count) + LinkedElementCollection<RoleBase> roles = RoleCollection; + switch (roles.Count) { case 1: + // This case should not get hit with unary binarization, but it isn't hurting anything return (int)SurveyQuestionGlyph.UnaryFactType; case 2: - return (int)SurveyQuestionGlyph.BinaryFactType; + return GetUnaryRoleIndex(roles).HasValue ? (int)SurveyQuestionGlyph.UnaryFactType : (int)SurveyQuestionGlyph.BinaryFactType; case 3: return (int)SurveyQuestionGlyph.TernaryFactType; default: Modified: trunk/ORMModel/ShapeModel/FactTypeShape.cs =================================================================== --- trunk/ORMModel/ShapeModel/FactTypeShape.cs 2007-08-08 00:31:35 UTC (rev 1078) +++ trunk/ORMModel/ShapeModel/FactTypeShape.cs 2007-08-08 00:38:27 UTC (rev 1079) @@ -578,6 +578,41 @@ return displayRoles; } /// <summary> + /// Standard override + /// </summary> + public override void ConfiguringAsChildOf(NodeShape parent, bool createdDuringViewFixup) + { + /// Make sure the factType shape is prepared to display as a unary + FactType factType; + Role unaryRole; + if (null != (factType = AssociatedFactType) && + null != (unaryRole = factType.UnaryRole)) + { + // Create a RoleDisplayOrder for Unary FactTypes. + LinkedElementCollection<RoleBase> displayRoles = RoleDisplayOrderCollection; + switch (displayRoles.Count) + { + case 0: + // The RoleDisplayOrder is empty, so we don't need to do anything. + break; + case 1: + // We already have only one role in the RoleDisplayOrder, so all + // we have to do is make sure it is the right one. + if (displayRoles[0] != unaryRole) + { + displayRoles[0] = unaryRole; + } + return; + default: + // We have more than one role in the RoleDisplayOrder, so we + // have to clear it. + displayRoles.Clear(); + break; + } + displayRoles.Add(unaryRole); + } + } + /// <summary> /// Retrieve an editable version of the <see cref="DisplayedRoleOrder"/> property. Editing /// DisplayedRoleOrder directly can change the role order in the associated FactType. Using /// this method to retrieve the collection ensures it will only be modified on the shape. @@ -5093,7 +5128,7 @@ FactTypeShape shape = pel as FactTypeShape; if (shape != null) { - // When a binarized Unary Fact is not longer a unary, clear the displayed role orders + // When a binarized Unary Fact is no longer a unary, clear the displayed role orders shape.RoleDisplayOrderCollection.Clear(); shape.AutoResize(); } Modified: trunk/ORMModel/ShapeModel/ORMDiagram.cs =================================================================== --- trunk/ORMModel/ShapeModel/ORMDiagram.cs 2007-08-08 00:31:35 UTC (rev 1078) +++ trunk/ORMModel/ShapeModel/ORMDiagram.cs 2007-08-08 00:38:27 UTC (rev 1079) @@ -255,7 +255,6 @@ int roleCount = roleCollection.Count; for (int i = 0; i < roleCount; ++i) { - //Role role = roleBase.Role; Role role = roleCollection[i].Role; if (!duplicateShape) Modified: trunk/ORMModel/ShapeModel/ORMShape.DeserializationFixupListeners.cs =================================================================== --- trunk/ORMModel/ShapeModel/ORMShape.DeserializationFixupListeners.cs 2007-08-08 00:31:35 UTC (rev 1078) +++ trunk/ORMModel/ShapeModel/ORMShape.DeserializationFixupListeners.cs 2007-08-08 00:38:27 UTC (rev 1079) @@ -37,7 +37,6 @@ yield return new DisplayRoleValueConstraintFixupListener(); yield return new DisplayValueTypeValueConstraintFixupListener(); yield return new DisplayRoleNameFixupListener(); - yield return new DisplayUnaryFactTypeFixupListener(); yield return new DisplayModelNoteLinksFixupListener(); yield return FactTypeShape.FixupListener; } Modified: trunk/ORMModel/ShapeModel/ViewFixupRules.cs =================================================================== --- trunk/ORMModel/ShapeModel/ViewFixupRules.cs 2007-08-08 00:31:35 UTC (rev 1078) +++ trunk/ORMModel/ShapeModel/ViewFixupRules.cs 2007-08-08 00:38:27 UTC (rev 1079) @@ -439,9 +439,9 @@ FactTypeShape shape = pel as FactTypeShape; if (shape != null) { - if (factType.UnaryRole != null) + Role unaryRole = factType.UnaryRole; + if (unaryRole != null) { - Role unaryRole = factType.UnaryRole; LinkedElementCollection<RoleBase> displayOrder = shape.RoleDisplayOrderCollection; if (!displayOrder.Contains(unaryRole)) { @@ -515,49 +515,48 @@ // Make sure the object type, fact type, and link // are displayed on the diagram FactType associatedFact; - if ((associatedFact = link.PlayedRole.FactType) != null) + ObjectType rolePlayer; + ORMModel model; + if (!link.IsDeleted && + null != (associatedFact = link.PlayedRole.FactType) && + null != (model = (rolePlayer = link.RolePlayer).Model)) { - ObjectType rolePlayer = link.RolePlayer; - ORMModel model; - if ((model = rolePlayer.Model) != null) + FactType nestedFact; + if (FactTypeShape.ShouldDrawObjectification(nestedFact = rolePlayer.NestedFactType)) { - FactType nestedFact; - if (FactTypeShape.ShouldDrawObjectification(nestedFact = rolePlayer.NestedFactType)) - { - Diagram.FixUpDiagram(model, nestedFact); - Diagram.FixUpDiagram(nestedFact, rolePlayer); - } - else - { - Diagram.FixUpDiagram(model, rolePlayer); - } - Diagram.FixUpDiagram(model, associatedFact); + Diagram.FixUpDiagram(model, nestedFact); + Diagram.FixUpDiagram(nestedFact, rolePlayer); + } + else + { + Diagram.FixUpDiagram(model, rolePlayer); + } + Diagram.FixUpDiagram(model, associatedFact); - object AllowMultipleShapes; - Dictionary<object, object> topLevelContextInfo; - bool containedAllowMultipleShapes; - if (!(containedAllowMultipleShapes = (topLevelContextInfo = link.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo).ContainsKey(AllowMultipleShapes = MultiShapeUtility.AllowMultipleShapes))) - { - topLevelContextInfo.Add(AllowMultipleShapes, null); - } + object AllowMultipleShapes; + Dictionary<object, object> topLevelContextInfo; + bool containedAllowMultipleShapes; + if (!(containedAllowMultipleShapes = (topLevelContextInfo = link.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo).ContainsKey(AllowMultipleShapes = MultiShapeUtility.AllowMultipleShapes))) + { + topLevelContextInfo.Add(AllowMultipleShapes, null); + } - foreach (PresentationViewsSubject presentationViewsSubject in DomainRoleInfo.GetElementLinks<PresentationViewsSubject>(model, PresentationViewsSubject.SubjectDomainRoleId)) + foreach (PresentationViewsSubject presentationViewsSubject in DomainRoleInfo.GetElementLinks<PresentationViewsSubject>(model, PresentationViewsSubject.SubjectDomainRoleId)) + { + ORMDiagram diagram; + if ((diagram = presentationViewsSubject.Presentation as ORMDiagram) != null) { - ORMDiagram diagram; - if ((diagram = presentationViewsSubject.Presentation as ORMDiagram) != null) + //add a link shape for each fact type shape on the diagram for the played role + foreach (FactTypeShape shapeElement in MultiShapeUtility.FindAllShapesForElement<FactTypeShape>(diagram, associatedFact)) { - //add a link shape for each fact type shape on the diagram for the played role - foreach (FactTypeShape shapeElement in MultiShapeUtility.FindAllShapesForElement<FactTypeShape>(diagram, associatedFact)) - { - diagram.FixUpLocalDiagram(link); - } + diagram.FixUpLocalDiagram(link); } } + } - if (!containedAllowMultipleShapes) - { - topLevelContextInfo.Remove(AllowMultipleShapes); - } + if (!containedAllowMultipleShapes) + { + topLevelContextInfo.Remove(AllowMultipleShapes); } } } @@ -844,45 +843,46 @@ // are displayed on the diagram IFactConstraint ifc = link as IFactConstraint; IConstraint constraint = ifc.Constraint; - FactType factType = ifc.FactType; - if (factType != null) + FactType factType; + ORMModel model; + ModelElement constraintElement = (ModelElement)constraint; + if (!constraintElement.IsDeleted && + null != (factType = ifc.FactType) && + !factType.IsDeleted && + null != (model = factType.Model)) { - ORMModel model = factType.Model; - if (model != null) - { - Debug.Assert(model == constraint.Model); + Debug.Assert(model == constraint.Model); - Diagram.FixUpDiagram(model, constraint as ModelElement); - Diagram.FixUpDiagram(model, factType); + Diagram.FixUpDiagram(model, constraint as ModelElement); + Diagram.FixUpDiagram(model, factType); - object AllowMultipleShapes; - Dictionary<object, object> topLevelContextInfo; - bool containedAllowMultipleShapes; - if (!(containedAllowMultipleShapes = (topLevelContextInfo = link.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo).ContainsKey(AllowMultipleShapes = MultiShapeUtility.AllowMultipleShapes))) - { - topLevelContextInfo.Add(AllowMultipleShapes, null); - } + object AllowMultipleShapes; + Dictionary<object, object> topLevelContextInfo; + bool containedAllowMultipleShapes; + if (!(containedAllowMultipleShapes = (topLevelContextInfo = link.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo).ContainsKey(AllowMultipleShapes = MultiShapeUtility.AllowMultipleShapes))) + { + topLevelContextInfo.Add(AllowMultipleShapes, null); + } - foreach (PresentationViewsSubject presentationViewsSubject in DomainRoleInfo.GetElementLinks<PresentationViewsSubject>(model, PresentationViewsSubject.SubjectDomainRoleId)) + foreach (PresentationViewsSubject presentationViewsSubject in DomainRoleInfo.GetElementLinks<PresentationViewsSubject>(model, PresentationViewsSubject.SubjectDomainRoleId)) + { + ORMDiagram diagram; + if ((diagram = presentationViewsSubject.Presentation as ORMDiagram) != null) { - ORMDiagram diagram; - if ((diagram = presentationViewsSubject.Presentation as ORMDiagram) != null) + //add a link shape for each constraint shape + foreach (ExternalConstraintShape shapeElement in MultiShapeUtility.FindAllShapesForElement<ExternalConstraintShape>(diagram, constraint as ModelElement)) { - //add a link shape for each constraint shape - foreach (ExternalConstraintShape shapeElement in MultiShapeUtility.FindAllShapesForElement<ExternalConstraintShape>(diagram, constraint as ModelElement)) + if (null == diagram.FixUpLocalDiagram(link)) { - if (null == diagram.FixUpLocalDiagram(link)) - { - shapeElement.Delete(); - } + shapeElement.Delete(); } } } + } - if (!containedAllowMultipleShapes) - { - topLevelContextInfo.Remove(AllowMultipleShapes); - } + if (!containedAllowMultipleShapes) + { + topLevelContextInfo.Remove(AllowMultipleShapes); } } } @@ -1016,59 +1016,6 @@ } } #endregion // DisplayRolePlayersFixupListener class - #region DisplayUnaryFactTypeFixupListener class - /// <summary> - /// Processes Unary FactTypes so that they display the correct number of roles - /// </summary> - private sealed class DisplayUnaryFactTypeFixupListener : DeserializationFixupListener<FactType> - { - /// <summary> - /// Create a new DisplayUnaryFactTypeFixupListener - /// </summary> - public DisplayUnaryFactTypeFixupListener() - : base((int)ORMDeserializationFixupPhase.AddImplicitPresentationElements) - { - } - - protected override void ProcessElement(FactType element, Store store, INotifyElementAdded notifyAdded) - { - Role unaryRole = element.UnaryRole; - if (unaryRole != null) - { - foreach (PresentationElement pel in PresentationViewsSubject.GetPresentation(element)) - { - FactTypeShape shape = pel as FactTypeShape; - if (shape != null) - { - // Create a RoleDisplayOrder for Unary FactTypes. - LinkedElementCollection<RoleBase> roles = shape.RoleDisplayOrderCollection; - switch (roles.Count) - { - case 0: - // The RoleDisplayOrder is empty, so we don't need to do anything. - break; - case 1: - // We already have only one role in the RoleDisplayOrder, so all - // we have to do is make sure it is the right one. - if (roles[0] != unaryRole) - { - roles[0] = unaryRole; - } - continue; - default: - // We have more than one role in the RoleDisplayOrder, so we - // have to clear it. - roles.Clear(); - break; - } - roles.Add(unaryRole); - shape.AutoResize(); - } - } - } - } - } - #endregion // DisplayUnaryFactTypeFixupListener class #region ModelNote fixup #region ModelNoteAddedRule /// <summary> Modified: trunk/ORMModel/Transforms/SerializationExtensions.xsd =================================================================== --- trunk/ORMModel/Transforms/SerializationExtensions.xsd 2007-08-08 00:31:35 UTC (rev 1078) +++ trunk/ORMModel/Transforms/SerializationExtensions.xsd 2007-08-08 00:38:27 UTC (rev 1079) @@ -25,6 +25,7 @@ </xs:appinfo> </xs:annotation> + <xs:import namespace="http://schemas.neumont.edu/CodeGeneration/PLiX"/> <xs:simpleType name="ElementWriteStyle"> <xs:annotation> <xs:documentation>How to write and element.</xs:documentation> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |