Exemplo n.º 1
0
 /// <summary>
 /// If the role object is part of a sticky external constraint shape
 /// object then activate it on a double click. Equivalent to the
 /// 'ActiveRoleSequence' diagram command.
 /// </summary>
 protected override void OnDoubleClick(DiagramPointEventArgs e)
 {
     // Note this looks like a strange place to put this, but this
     // is the mouse action that is active when a role is clicked on.
     if (myAllowDoubleClick)
     {
         ORMDiagram              ormDiagram = Diagram as ORMDiagram;
         IStickyObject           sticky;
         ExternalConstraintShape constraintShape;
         if (null != (sticky = ormDiagram.StickyObject) &&
             null != (constraintShape = sticky as ExternalConstraintShape))
         {
             foreach (Role role in e.DiagramHitTestInfo.HitDiagramItem.RepresentedElements)
             {
                 if (sticky.StickySelectable(role))
                 {
                     IConstraint constraint     = constraintShape.AssociatedConstraint;
                     Role        constraintRole = role;
                     switch (constraint.ConstraintType)
                     {
                     case ConstraintType.ExternalUniqueness:
                     case ConstraintType.Frequency:
                         Role       oppositeRole;
                         ObjectType oppositeRolePlayer;
                         if (null != (oppositeRole = role.OppositeRole as Role) &&
                             null != (oppositeRolePlayer = oppositeRole.RolePlayer) &&
                             oppositeRolePlayer.IsImplicitBooleanValue)
                         {
                             constraintRole = oppositeRole;
                         }
                         break;
                     }
                     foreach (ConstraintRoleSequence sequence in constraintRole.ConstraintRoleSequenceCollection)
                     {
                         if (constraint == sequence.Constraint)
                         {
                             ExternalConstraintConnectAction connectAction = ormDiagram.ExternalConstraintConnectAction;
                             connectAction.ConstraintRoleSequenceToEdit = sequence;
                             connectAction.ChainMouseAction(constraintShape, e.DiagramClientView);
                             e.Handled = true;
                             return;
                         }
                     }
                 }
                 break;
             }
         }
     }
     base.OnDoubleClick(e);
 }
Exemplo n.º 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);
                }
            }
        }