From: <mcu...@us...> - 2008-08-13 00:32:31
|
Revision: 1314 http://orm.svn.sourceforge.net/orm/?rev=1314&view=rev Author: mcurland Date: 2008-08-13 00:32:41 +0000 (Wed, 13 Aug 2008) Log Message: ----------- Display and respect role order for internal uniqueness constraint editing. fixes #369 Modified Paths: -------------- trunk/ORMModel/ShapeModel/FactTypeShape.cs trunk/ORMModel/ShapeModel/InternalConstraintConnectAction.cs trunk/ORMModel/Shell/ORMDocView.cs Modified: trunk/ORMModel/ShapeModel/FactTypeShape.cs =================================================================== --- trunk/ORMModel/ShapeModel/FactTypeShape.cs 2008-06-10 01:17:49 UTC (rev 1313) +++ trunk/ORMModel/ShapeModel/FactTypeShape.cs 2008-08-13 00:32:41 UTC (rev 1314) @@ -2385,7 +2385,20 @@ Pen pen = styleSet.GetPen(FactTypeShape.RoleBoxResource); int activeRoleIndex; ExternalConstraintConnectAction activeExternalAction = ActiveExternalConstraintConnectAction; + UniquenessConstraint activeInternalUniqueness = null; + LinkedElementCollection<Role> activeInternalUniquenessRoles = null; InternalUniquenessConstraintConnectAction activeInternalAction = ActiveInternalUniquenessConstraintConnectAction; + if (activeInternalAction != null) + { + if (activeInternalAction.SourceShape != parentFactShape) + { + activeInternalAction = null; + } + else + { + activeInternalUniqueness = activeInternalAction.ActiveConstraint; + } + } ORMDiagram currentDiagram = parentFactShape.Diagram as ORMDiagram; StringFormat stringFormat = null; Font connectActionFont = null; @@ -2419,8 +2432,10 @@ g.FillRectangle(roleCenterBrush, roleBounds.Left, roleBounds.Top, roleBounds.Width, roleBounds.Height); // There is an active ExternalConstraintConnectAction, and this role is currently in the action's role set. - if (activeExternalAction != null && - -1 != (activeRoleIndex = activeExternalAction.GetActiveRoleIndex(currentRole))) + if ((activeExternalAction != null && + -1 != (activeRoleIndex = activeExternalAction.GetActiveRoleIndex(currentRole))) || + (activeInternalAction != null && + -1 != (activeRoleIndex = activeInternalAction.GetActiveRoleIndex(currentRole)))) { // There is an active ExternalConstraintConnectAction, and this role is currently in the action's role set. DrawHighlight(g, styleSet, roleBounds, highlightThisRole); @@ -2459,11 +2474,11 @@ g.Restore(state); } } - // There is an active InternalUniquenessConstraintConnectAction, and this role is currently in the action's role set. - else if (activeInternalAction != null && -1 != (activeRoleIndex = activeInternalAction.GetActiveRoleIndex(currentRole))) + // There is an active InternalUniquenessConstraintConnectAction, and this role is removed from an existing constraint. + else if (activeInternalUniqueness != null && + (activeInternalUniquenessRoles ?? (activeInternalUniquenessRoles = activeInternalUniqueness.RoleCollection)).Contains(currentRole)) { - // There is an active InternalUniquenessConstraintConnectAction, and this role is currently in the action's role set. - DrawHighlight(g, styleSet, roleBounds, highlightThisRole); + parentFactShape.DrawHighlight(g, roleBounds, true, highlightThisRole); } else if (null != currentDiagram) { @@ -2487,22 +2502,10 @@ parentFactShape.DrawHighlight(g, roleBounds, true, highlightThisRole); SetComparisonConstraint mcec; SetConstraint scec; - bool drawIndexNumbers = false; string indexString = null; - if (activeExternalAction == null) + if (activeExternalAction == null || !activeExternalAction.InitialRoles.Contains(currentRole)) { - drawIndexNumbers = true; - } - else - { - if (activeExternalAction.InitialRoles.IndexOf(currentRole) < 0) - { - drawIndexNumbers = true; - } - } - if (drawIndexNumbers) - { if (null != (mcec = stickyConstraint as SetComparisonConstraint)) { LinkedElementCollection<SetComparisonConstraintRoleSequence> sequenceCollection = mcec.RoleSequenceCollection; Modified: trunk/ORMModel/ShapeModel/InternalConstraintConnectAction.cs =================================================================== --- trunk/ORMModel/ShapeModel/InternalConstraintConnectAction.cs 2008-06-10 01:17:49 UTC (rev 1313) +++ trunk/ORMModel/ShapeModel/InternalConstraintConnectAction.cs 2008-08-13 00:32:41 UTC (rev 1314) @@ -122,34 +122,38 @@ if (null != (iuConstraint = constraint as UniquenessConstraint) && iuConstraint.IsInternal) { - // The single-column constraint is its own role set, just add the roles + // Keep the collection ordered, this ends up as constraint order on objectified FactTypes LinkedElementCollection<Role> roles = iuConstraint.RoleCollection; - int currentCount = roles.Count; - int removedCount = 0; - for (int i = currentCount - 1; i >= 0; --i) + int existingRolesCount = roles.Count; + for (int i = existingRolesCount - 1; i >= 0; --i) { - Role currentRole = roles[i]; - int index = selectedRoles.IndexOf(currentRole); - if (index == -1) + Role testRole = roles[i]; + if (!selectedRoles.Contains(testRole)) { - roles.Remove(currentRole); + roles.Remove(testRole); + --existingRolesCount; } - else - { - selectedRoles[index] = null; - ++removedCount; - } } - if (removedCount < rolesCount) + for (int i = 0; i < rolesCount; ++i) { - for (int i = 0; i < rolesCount; ++i) + Role selectedRole = selectedRoles[i]; + int existingIndex = roles.IndexOf(selectedRole); + if (existingIndex == -1) { - Role r = selectedRoles[i]; - if (r != null) + if (i < existingRolesCount) { - roles.Add(r); + roles.Insert(i, selectedRole); } + else if (!roles.Contains(selectedRole)) + { + roles.Add(selectedRole); + } + ++existingRolesCount; } + else if (existingIndex != i) + { + roles.Move(existingIndex, i); + } } } } Modified: trunk/ORMModel/Shell/ORMDocView.cs =================================================================== --- trunk/ORMModel/Shell/ORMDocView.cs 2008-06-10 01:17:49 UTC (rev 1313) +++ trunk/ORMModel/Shell/ORMDocView.cs 2008-08-13 00:32:41 UTC (rev 1314) @@ -2351,7 +2351,8 @@ LinkedElementCollection<Role> constraintRoles = null; bool abort = false; IList selectedElements = SelectedElements; - for (int i = selectedElements.Count - 1; i >= 0; i--) + int selectedElementCount = selectedElements.Count; + for (int i = 0; i < selectedElementCount; ++i) { Role role = selectedElements[i] as Role; if (role != null) @@ -2362,13 +2363,14 @@ parentFact = testFact; UniquenessConstraint iuc = UniquenessConstraint.CreateInternalUniquenessConstraint(parentFact); constraintRoles = iuc.RoleCollection; + constraintRoles.Add(role); } else if (testFact != parentFact) { abort = true; // Transaction will rollback when it disposes if we don't commit break; } - if (!constraintRoles.Contains(role)) + else if (!constraintRoles.Contains(role)) { constraintRoles.Add(role); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |