/// Return whether the instance is OK to be the source of a link, in its current state.
 /// </summary>
 /// <param name="shape"></param>
 /// <returns></returns>
 public override bool IsValidSourceInstance(ShapeElement shape)
 {
     if (!SourceShapeTypes.Contains(ConnectorConnectAction.TopLevelShape(shape).GetType()))
     {
         return(false);
     }
     return(base.IsValidSourceInstance(shape));
 }
        public override bool CanCreateConnection(ShapeElement sourceShapeElement, ShapeElement targetShapeElement, ref string connectionWarning)
        {
            ShapeElement realSource    = ConnectorConnectAction.TopLevelShape(sourceShapeElement);
            ShapeElement realTarget    = ConnectorConnectAction.TopLevelShape(targetShapeElement);
            ModelElement sourceElement = realSource.ModelElement;
            ModelElement targetElement = realTarget.ModelElement;

            if (realSource == null || realTarget == null)
            {
                return(false);
            }

            else if (realSource == realTarget)
            {
                connectionWarning = String.Format(System.Globalization.CultureInfo.CurrentCulture,
                                                  "No Self-Connections");
                return(false);
            }

            else if (targetElement.GetType() == typeof(ISpySoft.FeatureModelLanguage.DomainModel.RootFeature))
            {
                connectionWarning = String.Format(System.Globalization.CultureInfo.CurrentCulture,
                                                  "Connection to RootFeature not allowed");
                return(false);
            }


            else if (targetElement.GetType() == typeof(ISpySoft.FeatureModelLanguage.DomainModel.FeatureSet))
            {
                connectionWarning = String.Format(System.Globalization.CultureInfo.CurrentCulture,
                                                  "Cannot connect FeatureSet with this Connector");
                return(false);
            }


            else if (targetElement.GetElementLinks().Count > 2)
            {
                if (NavigationHelper.HasParentShape(targetElement))
                {
                    connectionWarning = String.Format(System.Globalization.CultureInfo.CurrentCulture,
                                                      "Cannot connect a Shape which has already a parent Shape");
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            else
            {
                return(true);
            }
        }
        public override bool CanCreateConnection(ShapeElement sourceShapeElement, ShapeElement targetShapeElement, ref string connectionWarning)
        {
            if (!base.CanCreateConnection(sourceShapeElement, targetShapeElement, ref connectionWarning))
            {
                return(false);
            }

            ShapeElement realSource    = ConnectorConnectAction.TopLevelShape(sourceShapeElement);
            ShapeElement realTarget    = ConnectorConnectAction.TopLevelShape(targetShapeElement);
            ModelElement sourceElement = realSource.ModelElement;
            ModelElement targetElement = realTarget.ModelElement;



            if (realSource == null || realTarget == null)
            {
                return(false);
            }


            if (realSource == realTarget)
            {
                connectionWarning = String.Format(System.Globalization.CultureInfo.CurrentCulture,
                                                  "No Self-Connections");
                return(false);
            }

            if (targetElement.GetElementLinks().Count > 2)
            {
                if (NavigationHelper.HasParentShape(targetElement))
                {
                    connectionWarning = String.Format(System.Globalization.CultureInfo.CurrentCulture,
                                                      "Cannot connect a Shape which has already a parent Shape");
                    return(false);
                }
            }

            return(true);
        } // CanCreateConnection()
        public override bool CanCreateConnection(ShapeElement sourceShape, ShapeElement targetShape, ref string connectionWarning)
        {
            if (sourceShape is IDecorator)
            {
                sourceShape = ConnectorConnectAction.TopLevelShape(sourceShape);
            }

            if (targetShape is IDecorator)
            {
                targetShape = ConnectorConnectAction.TopLevelShape(targetShape);
            }

            if ((sourceShape.ModelElement as Activity) != null && (targetShape.ModelElement as ViewPoint) != null)
            {
                connectionWarning = String.Format(System.Globalization.CultureInfo.CurrentCulture, "Connection not allowed");
                return(false);
            }
            else if ((sourceShape.ModelElement as Activity) != null && (targetShape.ModelElement as Activity) != null)
            {
                connectionWarning = String.Format(System.Globalization.CultureInfo.CurrentCulture, "Connection not allowed");
                return(false);
            }
            else if ((sourceShape.ModelElement as Activity) != null && (targetShape.ModelElement as Mapping) != null)
            {
                connectionWarning = String.Format(System.Globalization.CultureInfo.CurrentCulture, "Connection not allowed");
                return(false);
            }
            else if ((sourceShape.ModelElement as ISpySoft.SFSchemaLanguage.DomainModel.Artifact) != null && (targetShape.ModelElement as ISpySoft.SFSchemaLanguage.DomainModel.Artifact) != null)
            {
                connectionWarning = String.Format(System.Globalization.CultureInfo.CurrentCulture, "Connection not allowed");
                return(false);
            }
            else if ((sourceShape.ModelElement as ISpySoft.SFSchemaLanguage.DomainModel.Artifact) != null && (targetShape.ModelElement as Activity) != null)
            {
                connectionWarning = String.Format(System.Globalization.CultureInfo.CurrentCulture, "Connection not allowed");
                return(false);
            }
            else if ((sourceShape.ModelElement as ISpySoft.SFSchemaLanguage.DomainModel.Artifact) != null && (targetShape.ModelElement as Mapping) != null)
            {
                connectionWarning = String.Format(System.Globalization.CultureInfo.CurrentCulture, "Connection not allowed");
                return(false);
            }
            else if ((sourceShape.ModelElement as ISpySoft.SFSchemaLanguage.DomainModel.Artifact) != null && (targetShape.ModelElement as ViewPoint) != null)
            {
                connectionWarning = String.Format(System.Globalization.CultureInfo.CurrentCulture, "Connection not allowed");
                return(false);
            }
            else if ((sourceShape.ModelElement as Mapping) != null && (targetShape.ModelElement as Mapping) != null)
            {
                connectionWarning = String.Format(System.Globalization.CultureInfo.CurrentCulture, "Connection not allowed");
                return(false);
            }
            else if ((sourceShape.ModelElement as Mapping) != null && (targetShape.ModelElement as Activity) != null)
            {
                connectionWarning = String.Format(System.Globalization.CultureInfo.CurrentCulture, "Connection not allowed");
                return(false);
            }
            else if ((sourceShape.ModelElement as Mapping) != null && (targetShape.ModelElement as ISpySoft.SFSchemaLanguage.DomainModel.Artifact) != null)
            {
                connectionWarning = String.Format(System.Globalization.CultureInfo.CurrentCulture, "Connection not allowed");
                return(false);
            }
            else if ((sourceShape.ModelElement as ViewPoint) != null && (targetShape.ModelElement as ViewPoint) != null)
            {
                connectionWarning = String.Format(System.Globalization.CultureInfo.CurrentCulture, "Connection not allowed");
                return(false);
            }
            else if ((sourceShape.ModelElement as ViewPoint) != null && (targetShape.ModelElement as Mapping) != null)
            {
                connectionWarning = String.Format(System.Globalization.CultureInfo.CurrentCulture, "Connection not allowed");
                return(false);
            }

            else
            if (ConnectionValidator.MaxNumbersOfConnectionsReached(sourceShape, targetShape) == true)
            {
                connectionWarning = String.Format(System.Globalization.CultureInfo.CurrentCulture, "Maximum number of connections reached");
                return(false);
            }
            else
            {
                return(true);
            }
        }