/// <summary>
        ///    Returns a collection of standard values for the data type this type converter is designed for when provided
        ///    with a format context.
        /// </summary>
        /// <returns>
        ///    A <see cref="T:System.ComponentModel.TypeConverter.StandardValuesCollection" /> that holds a standard set of
        ///    valid values, or null if the data type does not support a standard set of values.
        /// </returns>
        /// <param name="context">
        ///    An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context
        ///    that can be used to extract additional information about the environment from which this converter is invoked. This
        ///    parameter or properties of this parameter can be null.
        /// </param>
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            AssociationConnector connector = context.Instance as AssociationConnector;

            if (connector == null)
            {
                return(new StandardValuesCollection(new string[0]));
            }

            Association association = PresentationViewsSubject.GetSubject(connector) as Association;

            if (association == null)
            {
                return(new StandardValuesCollection(new string[0]));
            }

            List <string> result = new List <string>
            {
                $"* (Collection of {association.Source.Name})",
                //$"1..* (Collection of one or more {association.Source.Name})",
                $"0..1 (Zero or one of {association.Source.Name})",
                $"1 (One {association.Source.Name})"
            };

            return(new StandardValuesCollection(result));
        }
        /// <summary>Converts the given value object to the specified type, using the specified context and culture information.</summary>
        /// <returns>An <see cref="T:System.Object" /> that represents the converted value.</returns>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context. </param>
        /// <param name="culture">
        ///    A <see cref="T:System.Globalization.CultureInfo" />. If null is passed, the current culture is
        ///    assumed.
        /// </param>
        /// <param name="value">The <see cref="T:System.Object" /> to convert. </param>
        /// <param name="destinationType">The <see cref="T:System.Type" /> to convert the <paramref name="value" /> parameter to. </param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="destinationType" /> parameter is null. </exception>
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            AssociationConnector connector = context?.Instance as AssociationConnector;

            if (connector != null)
            {
                Association association = PresentationViewsSubject.GetSubject(connector) as Association;

                if (destinationType == typeof(string) && association != null && value is Multiplicity)
                {
                    switch ((Multiplicity)value)
                    {
                    case Multiplicity.One:
                        return($"1 (One {association.Source.Name})");

                    //case Multiplicity.OneMany:
                    //   return $"1..* (Collection of one or more {association.Source.Name})";
                    case Multiplicity.ZeroMany:
                        return($"* (Collection of {association.Source.Name})");

                    case Multiplicity.ZeroOne:
                        return($"0..1 (Zero or one of {association.Source.Name})");
                    }
                }
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
Beispiel #3
0
        public static void UpdateAssociationDisplay(AssociationConnector connector
                                                    , DeleteAction?sourceDeleteAction = null
                                                    , DeleteAction?targetDeleteAction = null)
        {
            if (!(connector?.ModelElement is Association element))
            {
                return;
            }

            ModelRoot modelRoot = element.Store.ElementDirectory.FindElements <ModelRoot>().FirstOrDefault();

            GetEffectiveDeleteAction(element, out DeleteAction? calculatedSourceDeleteAction, out DeleteAction? calculatedTargetDeleteAction);

            sourceDeleteAction = sourceDeleteAction != null && sourceDeleteAction != DeleteAction.Default
                                 ? sourceDeleteAction
                                 : calculatedSourceDeleteAction;

            targetDeleteAction = targetDeleteAction != null && targetDeleteAction != DeleteAction.Default
                                 ? targetDeleteAction
                                 : calculatedTargetDeleteAction;

            bool persistent = element.Persistent;

            bool cascade = modelRoot.ShowCascadeDeletes &&
                           persistent &&
                           (targetDeleteAction == DeleteAction.Cascade ||
                            sourceDeleteAction == DeleteAction.Cascade);

            Color black = Color.FromArgb(255, 113, 111, 110);

            Color lineColor = !persistent
                              ? Color.SlateGray
                              : cascade
                                 ? Color.Red
                                 : black;

            DashStyle lineStyle = cascade
                                  ? DashStyle.Dash
                                  : DashStyle.Solid;

            using (Transaction trans = element.Store.TransactionManager.BeginTransaction("Display associations"))
            {
                SetConnectorWidth(connector);

                if (connector.Color != lineColor)
                {
                    connector.Color = lineColor;
                    element.InvalidateDiagrams();
                }

                if (connector.DashStyle != lineStyle)
                {
                    connector.DashStyle = lineStyle;
                    element.InvalidateDiagrams();
                }

                trans.Commit();
            }
        }
Beispiel #4
0
        private static void SetConnectorWidth(AssociationConnector connector)
        {
            PenSettings settings = connector.StyleSet.GetOverriddenPenSettings(DiagramPens.ConnectionLine) ?? new PenSettings();

            settings.Width = connector.ManuallyRouted
                             ? 0.02f
                             : 0.01f;

            connector.StyleSet.OverridePen(DiagramPens.ConnectionLine, settings);
        }