Пример #1
0
        /// <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);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Activate a new role sequence connect action. For a set comparison constraint
        /// this adds a new sequence. For a set constraint it activates the current sequence.
        /// </summary>
        /// <param name="clientView">The active diagram client view. This can be retrieved
        /// from the shape if it is not specified.</param>
        protected void ActivateNewRoleSequenceConnectAction(DiagramClientView clientView)
        {
            ORMDiagram  diagram;
            IConstraint constraint;

            if (null != (diagram = this.Diagram as ORMDiagram) &&
                diagram.StickyObject == this &&
                null != (constraint = this.AssociatedConstraint))
            {
                ExternalConstraintConnectAction connectAction = diagram.ExternalConstraintConnectAction;

                switch (constraint.ConstraintStorageStyle)
                {
                case ConstraintStorageStyle.SetConstraint:
                    connectAction.ConstraintRoleSequenceToEdit = constraint as ConstraintRoleSequence;
                    break;

                case ConstraintStorageStyle.SetComparisonConstraint:
                    int maximum = ConstraintUtility.RoleSequenceCountMaximum(constraint);
                    if (maximum > 0 && ((SetComparisonConstraint)constraint).RoleSequenceCollection.Count >= maximum)
                    {
                        return;
                    }
                    if (constraint.ConstraintType == ConstraintType.Exclusion)
                    {
                        // If this is a subtype connect action already, then give it the first sequence
                        ExclusionConstraint exclusion = (ExclusionConstraint)constraint;
                        foreach (FactType existingFactType in exclusion.FactTypeCollection)
                        {
                            if (existingFactType is SubtypeFact)
                            {
                                connectAction.ConstraintRoleSequenceToEdit = exclusion.RoleSequenceCollection[0];
                                break;
                            }
                        }
                    }
                    break;
                }

                if (!connectAction.IsActive)
                {
                    if (clientView == null)
                    {
                        clientView = diagram.ActiveDiagramView.DiagramClientView;
                    }
                    connectAction.ChainMouseAction(this, clientView);
                }
            }
        }
Пример #3
0
        public void ConstContradictTests_1a(Store store)
        {
            myTestServices.LogValidationErrors("ExclusionContradictsEqualityError exists");

            ORMModel            model      = store.ElementDirectory.FindElements <ORMModel>()[0];
            ExclusionConstraint constraint = (ExclusionConstraint)model.ConstraintsDictionary.GetElement("ExConstraint").FirstElement;

            myTestServices.LogValidationErrors("Removing Exclusion Constraint");

            using (Transaction t = store.TransactionManager.BeginTransaction("Remove Ex Constraint"))
            {
                constraint.Delete();
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error Removed");
        }
Пример #4
0
        /// <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);
        }
Пример #5
0
        /// <summary>
        /// Add a <c>Name</c> property for the associated <see cref="ExclusionConstraint"/> if an
        /// <see cref="ExclusiveOrConstraintCoupler"/> is attached to this <see cref="MandatoryConstraint"/>.
        /// </summary>
        public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            PropertyDescriptorCollection properties          = base.GetProperties(attributes);
            ExclusionConstraint          exclusionConstraint = ModelElement.ExclusiveOrExclusionConstraint;

            if (exclusionConstraint != null)
            {
                DomainPropertyInfo exclusionConstraintNameDomainProperty = exclusionConstraint.GetDomainClass().NameDomainProperty;
                properties.Add(EditorUtility.RedirectPropertyDescriptor(
                                   exclusionConstraint,
                                   new ElementPropertyDescriptor(
                                       exclusionConstraint,
                                       exclusionConstraintNameDomainProperty,
                                       base.GetDomainPropertyAttributes(exclusionConstraintNameDomainProperty)),
                                   typeof(MandatoryConstraint)));
            }
            return(properties);
        }
Пример #6
0
        public void ExclusionMandatoryContra_1b(Store store)
        {
            myTestServices.LogValidationErrors("No Errors Found Initialliy");

            ORMModel            model      = store.ElementDirectory.FindElements <ORMModel>()[0];
            Role                role       = (Role)store.ElementDirectory.GetElement(new Guid("1C424E34-8369-41EC-850F-FD24E7B30C7A"));
            ExclusionConstraint constraint = (ExclusionConstraint)model.ConstraintsDictionary.GetElement("ExclusionConstraint1").SingleElement;

            using (Transaction t = store.TransactionManager.BeginTransaction("Add Mandatory Constraint"))
            {
                role.IsMandatory = true;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error is Introduced");

            using (Transaction t = store.TransactionManager.BeginTransaction("Add Mandatory Constraint"))
            {
                constraint.Delete();
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error is removed upon Removal of Exclusion Constraint");
        }
Пример #7
0
        /// <summary>
        /// Redirect the displayed component name if this <see cref="MandatoryConstraint"/> is part of an
        /// <c>Exclusive Or</c> constraint.
        /// </summary>
        public override string GetComponentName()
        {
            ExclusionConstraint exclusionConstraint = ModelElement.ExclusiveOrExclusionConstraint;

            return((exclusionConstraint != null) ? TypeDescriptor.GetComponentName(exclusionConstraint) : base.GetComponentName());
        }
Пример #8
0
        /// <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());
        }
Пример #9
0
		/// <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();
		}