/// <summary> /// DeleteRule: typeof(FactSetConstraint), FireTime=LocalCommit, Priority=ORMCoreDomainModel.BeforeDelayValidateRulePriority; /// Block internal constraints from being removed from a subtype /// after it is included in a model. /// </summary> private static void LimitSubtypeConstraintsDeleteRule(ElementDeletedEventArgs e) { FactSetConstraint link = (FactSetConstraint)e.ModelElement; SubtypeFact subtypeFact; if (link.SetConstraint.Constraint.ConstraintIsInternal && null != (subtypeFact = link.FactType as SubtypeFact) && !subtypeFact.IsDeleted && subtypeFact.ResolvedModel != null) { // Allow before adding to model, not afterwards ThrowPatternModifiedException(subtypeFact.Store); } }
/// <summary> /// AddRule: typeof(FactSetConstraint) /// Block internal constraints from being added to a subtype /// after it is included in a model. /// </summary> private static void LimitSubtypeConstraintsAddRule(ElementAddedEventArgs e) { FactSetConstraint link = (FactSetConstraint)e.ModelElement; SubtypeFact subtypeFact; Store store; if (link.SetConstraint.Constraint.ConstraintIsInternal && null != (subtypeFact = link.FactType as SubtypeFact) && subtypeFact.ResolvedModel != null && CopyMergeUtility.GetIntegrationPhase(store = link.Store) == CopyClosureIntegrationPhase.None) { // Allow before adding to model, not afterwards, // unless there is an active copy operation. ThrowPatternModifiedException(store); } }
/// <summary> /// Set this mouse action as the active action on the /// diagram of the given shape. /// </summary> /// <param name="attachToShape">The shape the constraint is being attached to.</param> /// <param name="constraint">The constraint being connected.</param> /// <param name="clientView">The active DiagramClientView</param> public void ChainMouseAction(FactTypeShape attachToShape, UniquenessConstraint constraint, DiagramClientView clientView) { DiagramView activeView = Diagram.ActiveDiagramView; if (activeView != null) { // Move on to the selection action clientView.ActiveMouseAction = this; // Now emulate a mouse click in the middle of the added constraint. The click // actions provide a starting point for the connect action, so a mouse move // provides a drag line. Point emulateClickPoint = clientView.WorldToDevice(attachToShape.GetAbsoluteConstraintAttachPoint(constraint, FactSetConstraint.GetLink(constraint, attachToShape.AssociatedFactType))); DiagramMouseEventArgs mouseEventArgs = new DiagramMouseEventArgs(new MouseEventArgs(MouseButtons.Left, 1, emulateClickPoint.X, emulateClickPoint.Y, 0), clientView); MouseDown(mouseEventArgs); Click(new DiagramPointEventArgs(emulateClickPoint.X, emulateClickPoint.Y, PointRelativeTo.Client, clientView)); MouseUp(mouseEventArgs); attachToShape.Invalidate(true); // An extra move lets us chain when the mouse is not on the design surface, // such as when we are being activated via the task list. MouseMove(mouseEventArgs); ORMDiagram.SelectToolboxItem(activeView, ResourceStrings.ToolboxInternalUniquenessConstraintItemId); FactTypeShape.ActiveInternalUniquenessConstraintConnectAction = this; } }