/// <summary> /// DeleteRule: typeof(ORMSolutions.ORMArchitect.Core.ObjectModel.ExclusiveOrConstraintCoupler), FireTime=TopLevelCommit, Priority=DiagramFixupConstants.AddShapeRulePriority; /// Split a single shape into two shapes when a exclusion constraint /// is decoupled from a mandatory constraint /// </summary> private static void ExclusiveOrCouplerDeletedRule(ElementDeletedEventArgs e) { ExclusiveOrConstraintCoupler link = e.ModelElement as ExclusiveOrConstraintCoupler; MandatoryConstraint mandatory = link.MandatoryConstraint; ExclusionConstraint exclusion = link.ExclusionConstraint; if (!mandatory.IsDeleted && !exclusion.IsDeleted) { LinkedElementCollection <PresentationElement> pels = PresentationViewsSubject.GetPresentation(mandatory); int pelCount = pels.Count; for (int i = 0; i < pelCount; ++i) { ExternalConstraintShape shape = pels[i] as ExternalConstraintShape; if (shape != null) { ORMDiagram diagram = (ORMDiagram)shape.Diagram; RectangleD bounds = shape.AbsoluteBounds; double width = bounds.Width; bounds.Offset(-width / 2, 0); bounds = diagram.BoundsRules.GetCompliantBounds(shape, bounds); shape.AbsoluteBounds = bounds; bounds.Offset(width, 0); diagram.PlaceORMElementOnDiagram(null, exclusion, bounds.Location, ORMPlacementOption.None, null, null); } } } }
/// <summary> /// AddRule: typeof(ORMSolutions.ORMArchitect.Core.ObjectModel.ExclusiveOrConstraintCoupler), FireTime=TopLevelCommit, Priority=DiagramFixupConstants.AddShapeRulePriority; /// Remove shapes associated with the exclusion constraint /// when exclusion and mandatory constraints are coupled. /// </summary> private static void ExclusiveOrCouplerAddedRule(ElementAddedEventArgs e) { ExclusiveOrConstraintCoupler link = e.ModelElement as ExclusiveOrConstraintCoupler; MandatoryConstraint mandatory = link.MandatoryConstraint; ExclusionConstraint exclusion = link.ExclusionConstraint; LinkedElementCollection <PresentationElement> pels = PresentationViewsSubject.GetPresentation(exclusion); for (int i = pels.Count - 1; i >= 0; --i) { ExternalConstraintShape shape = pels[i] as ExternalConstraintShape; if (shape != null) { shape.Delete(); } } InvalidateAssociatedDisplay(mandatory); }
/// <summary> /// Add a <c>Name</c> property for the associated <see cref="MandatoryConstraint"/> if an /// <see cref="ExclusiveOrConstraintCoupler"/> is attached to this <see cref="ExclusionConstraint"/>. /// </summary> public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) { PropertyDescriptorCollection properties = base.GetProperties(attributes); MandatoryConstraint mandatoryConstraint = ModelElement.ExclusiveOrMandatoryConstraint; if (mandatoryConstraint != null) { DomainPropertyInfo mandatoryConstraintNameDomainProperty = mandatoryConstraint.GetDomainClass().NameDomainProperty; properties.Add(EditorUtility.RedirectPropertyDescriptor( mandatoryConstraint, new ElementPropertyDescriptor( mandatoryConstraint, mandatoryConstraintNameDomainProperty, base.GetDomainPropertyAttributes(mandatoryConstraintNameDomainProperty)), typeof(ExclusionConstraint))); } return(properties); }
public void MandatoryMandatory_1a(Store store) { myTestServices.LogValidationErrors("Start with no Error"); ORMModel model = store.ElementDirectory.FindElements <ORMModel>()[0]; Role role_A = (Role)store.ElementDirectory.GetElement(new Guid("FA2156EE-8612-47F3-8DB8-861814BAD997")); Role role_B = (Role)store.ElementDirectory.GetElement(new Guid("7DD25522-062E-4134-8B7A-F453FD979281")); MandatoryConstraint constraint = (MandatoryConstraint)model.ConstraintsDictionary.GetElement("InclusiveOrConstraint1").SingleElement; myTestServices.LogMessage("Introducing error via creating additional implied mandatory constraint"); using (Transaction t = store.TransactionManager.BeginTransaction("Add Mandatory Costraint")) { role_A.IsMandatory = true; t.Commit(); } myTestServices.LogValidationErrors("Error Received. Proceed to removal via removing the other Mandatory Constraint"); using (Transaction t = store.TransactionManager.BeginTransaction("Remove a Mandatory Costraint")) { constraint.Delete(); t.Commit(); } myTestServices.LogValidationErrors("Error is removed."); }
public void MandatoryMandatory_1b(Store store) { myTestServices.LogValidationErrors("Start with one Implication Error"); ORMModel model = store.ElementDirectory.FindElements <ORMModel>()[0]; MandatoryConstraint constraint_1 = (MandatoryConstraint)model.ConstraintsDictionary.GetElement("InclusiveOrConstraint1").SingleElement; MandatoryConstraint constraint_2 = (MandatoryConstraint)model.ConstraintsDictionary.GetElement("InclusiveOrConstraint2").SingleElement; using (Transaction t = store.TransactionManager.BeginTransaction("Remove a Mandatory Costraint")) { constraint_1.Delete(); t.Commit(); } myTestServices.LogValidationErrors("Error is removed with removal of a Constraint"); myTestServices.LogValidationErrors("Undo to bring to initial condition"); store.UndoManager.Undo(); myTestServices.LogValidationErrors("Proceed to remove the other Mandatory Constraint"); using (Transaction t = store.TransactionManager.BeginTransaction("Remove a Mandatory Costraint")) { constraint_2.Delete(); t.Commit(); } myTestServices.LogValidationErrors("All Errors Removed"); }
/// <summary>See <see cref="ORMShapeToolboxHelperBase.CreateElementToolPrototype"/>.</summary> protected sealed override ElementGroupPrototype CreateElementToolPrototype(Store store, Guid domainClassId) { // WARNING: This method is _extremely_ order-sensitive. If the order that the toolbox items are listed // in the .dsl file changes, or if the DSL Tools text template that is used to generate ORMShapeModelToolboxHelperBase // changes, this method will most likely need to be changed as well. ElementGroup group = null; bool unknownItem = false; if (domainClassId.Equals(ObjectType.DomainClassId)) { group = new ElementGroup(store); ObjectType objectType = new ObjectType(store); group.AddGraph(objectType, true); switch (myObjectTypeCount++) { case 0: // EntityType - We don't need to do anything else... break; case 1: // ValueType // Do not try to set the IsValueType property here. IsValueType picks // up the default data type for the model, which can only be done // when the model is known. Instead, flag the element so that it // can be set during MergeRelate on the model. group.UserData = ORMModel.ValueTypeUserDataKey; break; case 2: // ObjectifiedFactType group.AddGraph(new Objectification(objectType, AddFactType(store, group, 2)), false); break; default: unknownItem = true; break; } } else if (domainClassId.Equals(FactType.DomainClassId)) { group = new ElementGroup(store); Debug.Assert(myFactTypeCount < 3); AddFactType(store, group, ++myFactTypeCount); } else if (domainClassId.Equals(ExclusiveOrConstraintCoupler.DomainClassId)) { group = new ElementGroup(store); MandatoryConstraint mandatory = new MandatoryConstraint(store, null); group.AddGraph(mandatory, true); ExclusionConstraint exclusion = new ExclusionConstraint(store, null); group.AddGraph(exclusion, true); group.AddGraph(new ExclusiveOrConstraintCoupler(mandatory, exclusion), false); } else if (domainClassId.Equals(UniquenessConstraint.DomainClassId)) { group = new ElementGroup(store); if (myUniquenessConstraintCount == 0) { // Add this here so that we can distinguish between internal and external uniqueness // constraints without unpacking the model. We want to merge internals into a fact // and externals into the model. group.UserData = ORMModel.InternalUniquenessConstraintUserDataKey; group.AddGraph(UniquenessConstraint.CreateInternalUniquenessConstraint(store.DefaultPartition), true); } else { Debug.Assert(myUniquenessConstraintCount == 1); group.AddGraph(new UniquenessConstraint(store), true); } myUniquenessConstraintCount++; } return((group == null || unknownItem) ? base.CreateElementToolPrototype(store, domainClassId) : group.CreatePrototype()); }
/// <summary>See <see cref="ORMShapeToolboxHelperBase.CreateElementToolPrototype"/>.</summary> protected sealed override ElementGroupPrototype CreateElementToolPrototype(Store store, Guid domainClassId) { // WARNING: This method is _extremely_ order-sensitive. If the order that the toolbox items are listed // in the .dsl file changes, or if the DSL Tools text template that is used to generate ORMShapeModelToolboxHelperBase // changes, this method will most likely need to be changed as well. ElementGroup group = null; bool unknownItem = false; if (domainClassId.Equals(ObjectType.DomainClassId)) { group = new ElementGroup(store); ObjectType objectType = new ObjectType(store); group.AddGraph(objectType, true); switch (myObjectTypeCount++) { case 0: // EntityType - We don't need to do anything else... break; case 1: // ValueType // Do not try to set the IsValueType property here. IsValueType picks // up the default data type for the model, which can only be done // when the model is known. Instead, flag the element so that it // can be set during MergeRelate on the model. group.UserData = ORMModel.ValueTypeUserDataKey; break; case 2: // ObjectifiedFactType group.AddGraph(new Objectification(objectType, AddFactType(store, group, 2)), false); break; default: unknownItem = true; break; } } else if (domainClassId.Equals(FactType.DomainClassId)) { group = new ElementGroup(store); Debug.Assert(myFactTypeCount < 3); AddFactType(store, group, ++myFactTypeCount); } else if (domainClassId.Equals(ExclusiveOrConstraintCoupler.DomainClassId)) { group = new ElementGroup(store); MandatoryConstraint mandatory = new MandatoryConstraint(store, null); group.AddGraph(mandatory, true); ExclusionConstraint exclusion = new ExclusionConstraint(store, null); group.AddGraph(exclusion, true); group.AddGraph(new ExclusiveOrConstraintCoupler(mandatory, exclusion), false); } else if (domainClassId.Equals(UniquenessConstraint.DomainClassId)) { group = new ElementGroup(store); if (myUniquenessConstraintCount == 0) { // Add this here so that we can distinguish between internal and external uniqueness // constraints without unpacking the model. We want to merge internals into a fact // and externals into the model. group.UserData = ORMModel.InternalUniquenessConstraintUserDataKey; group.AddGraph(UniquenessConstraint.CreateInternalUniquenessConstraint(store), true); } else { Debug.Assert(myUniquenessConstraintCount == 1); group.AddGraph(new UniquenessConstraint(store), true); } myUniquenessConstraintCount++; } return (group == null || unknownItem) ? base.CreateElementToolPrototype(store, domainClassId) : group.CreatePrototype(); }