Example #1
0
 /// <summary>
 /// This method <see cref="IOptionBuilderContext.BindItem(IOptionItem,string)"/> binds the
 /// <see cref="INode.Layout"/> properties to corresponding option items.
 /// </summary>
 /// <param name="context">The context to use.</param>
 protected virtual void BuildLayoutOptions(IOptionBuilderContext context)
 {
     context = context.CreateChildContext(DefaultNodePropertyMapBuilder.LayoutPropertyName);
     context.BindItem(new DoubleOptionItem(DefaultNodePropertyMapBuilder.LayoutXName), DefaultNodePropertyMapBuilder.LayoutXName);
     context.BindItem(new DoubleOptionItem(DefaultNodePropertyMapBuilder.LayoutYName), DefaultNodePropertyMapBuilder.LayoutYName);
     context.BindItem(new DoubleOptionItem(DefaultNodePropertyMapBuilder.LayoutWidthName), DefaultNodePropertyMapBuilder.LayoutWidthName);
     context.BindItem(new DoubleOptionItem(DefaultNodePropertyMapBuilder.LayoutHeightName), DefaultNodePropertyMapBuilder.LayoutHeightName);
 }
Example #2
0
 /// <summary>
 /// Adds <see cref="IOptionItem"/>s that are bound to the label's <see cref="ILabel.LayoutParameter"/>
 /// and the associated <see cref="ILabelModelParameter.Model"/>.
 /// property to the builder.
 /// </summary>
 /// <param name="context">The context to use for building.</param>
 /// <param name="label">The current label instance.</param>
 protected virtual void AddLabelLayoutParameterItems(IOptionBuilderContext context, ILabel label)
 {
     if (label.LayoutParameter != null)
     {
         IOptionBuilder modelBuilder = GetLabelModelOptionBuilder(context, label.LayoutParameter.Model);
         if (modelBuilder != null)
         {
             modelBuilder.AddItems(context.CreateChildContext("Model"), label.LayoutParameter.Model.GetType(), label.LayoutParameter.Model);
         }
     }
 }
Example #3
0
 /// <summary>
 /// Builds the options for the first label of the node instance.
 /// </summary>
 /// <param name="context">The context to use for building.</param>
 /// <param name="subject">The current node instance.</param>
 protected virtual void BuildLabelOptions(IOptionBuilderContext context, ILabelOwner subject)
 {
     if (subject.Labels.Count > 0)
     {
         context = context.CreateChildContext(DefaultNodePropertyMapBuilder.LabelPropertyName);
         ILabel label = subject.Labels[0];
         if (label != null)
         {
             IOptionBuilder builder = GetLabelOptionBuilder(context, label);
             if (builder != null)
             {
                 builder.AddItems(context, typeof(ILabel), label);
             }
         }
     }
 }
Example #4
0
        /// <summary>
        /// Adds a <see cref="IOptionItem"/>s that are bound to the port's <see cref="IPort.Style"/>
        /// to the builder.
        /// </summary>
        /// <param name="context">The context to use for building.</param>
        /// <param name="port"></param>
        protected virtual void AddStyleItems(IOptionBuilderContext context, IPort port)
        {
            //style group...
            //retrieve current style...
            IPortStyle style = port.Style;

            if (style != null)
            {
                //retrieve OptionBuilder from style
                IOptionBuilder styleBuilder = GetStyleOptionBuilder(context, style);
                if (styleBuilder != null)
                {
                    styleBuilder.AddItems(context.CreateChildContext(DefaultPortPropertyMapBuilder.StyleProperty), style.GetType(), style);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Builds the options for the style of the edge instance.
        /// </summary>
        /// <param name="context">The context to use for building.</param>
        /// <param name="edge">The current edge instance.</param>
        protected virtual void BuildStyleOptions(IOptionBuilderContext context, IEdge edge)
        {
            context = context.CreateChildContext(StylePropertyName);
            //style group...
            //retrieve current style...
            IEdgeStyle style = edge.Style;

            if (style != null)
            {
                //retrieve OptionBuilder from style
                IOptionBuilder builder = GetStyleOptionBuilder(context, style);
                if (builder != null)
                {
                    builder.AddItems(context, style.GetType(), style);
                }
            }
        }
Example #6
0
        /// <summary>
        /// Builds the options for the style of the node instance.
        /// </summary>
        /// <param name="context">The context to use for building.</param>
        /// <param name="node">The current node instance.</param>
        protected virtual void BuildStyleOptions(IOptionBuilderContext context, INode node)
        {
            context = context.CreateChildContext(DefaultNodePropertyMapBuilder.StylePropertyName);
            context.BindItem(new BoolOptionItem("Shadow"), "Shadow");
            //style group...
            //retrieve current style...
            INodeStyle style = node.Style;

            if (style != null)
            {
                //retrieve OptionBuilder from style
                IOptionBuilder builder = GetStyleOptionBuilder(context, style);
                if (builder != null)
                {
                    builder.AddItems(context, style.GetType(), style);
                }
            }
        }
        /// <inheritdoc/>
        public void AddItems(IOptionBuilderContext context, Type subjectType, object subject)
        {
            Type type1 = subject == null?subjectType:subject.GetType();

            PropertyInfo[] propertyInfos =
                SortProperties(FilterProperties(
                                   type1.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy),
                                   context), context);

            foreach (PropertyInfo descriptor in propertyInfos)
            {
                DisplayNameAttribute displayNameAttribute = GetAttribute <DisplayNameAttribute>(descriptor);
                string propertyName;
                if (displayNameAttribute == null || displayNameAttribute.DisplayName.Length < 1)
                {
                    propertyName = descriptor.Name;
                }
                else
                {
                    propertyName = displayNameAttribute.DisplayName;
                }
                Type   type  = descriptor.PropertyType;
                object value = descriptor.GetGetMethod().Invoke(subject, null);

                IOptionBuilder builder = GetBuilder(descriptor, context, subject, type);

                if (builder != null)
                {
                    IOptionBuilderContext childContext = context.CreateChildContext(propertyName);
                    builder.AddItems(childContext, type, value);
                    ConfigureItem(childContext.Lookup <IOptionGroup>(), descriptor);
                }
                else
                {
                    IOptionItem item = CreateItem(context, descriptor, type, propertyName, value);
                    if (item != null)
                    {
                        context.BindItem(item, propertyName);
                        ConfigureItem(item, descriptor);
                    }
                }
            }
        }
 /// <summary>
 /// This method <see cref="IOptionBuilderContext.BindItem(IOptionItem,string)"/> binds the
 /// <see cref="INode.Layout"/> properties to corresponding option items.
 /// </summary>
 /// <param name="context">The context to use.</param>
 protected virtual void BuildLayoutOptions(IOptionBuilderContext context)
 {
     context = context.CreateChildContext(DefaultNodePropertyMapBuilder.LayoutPropertyName);
     context.BindItem(new OptionItem(DefaultNodePropertyMapBuilder.LayoutXName)
     {
         Value = 0.0d, Type = typeof(double)
     }, DefaultNodePropertyMapBuilder.LayoutXName);
     context.BindItem(new OptionItem(DefaultNodePropertyMapBuilder.LayoutYName)
     {
         Value = 0.0d, Type = typeof(double)
     }, DefaultNodePropertyMapBuilder.LayoutYName);
     context.BindItem(new OptionItem(DefaultNodePropertyMapBuilder.LayoutWidthName)
     {
         Value = 0.0d, Type = typeof(double)
     }, DefaultNodePropertyMapBuilder.LayoutWidthName);
     context.BindItem(new OptionItem(DefaultNodePropertyMapBuilder.LayoutHeightName)
     {
         Value = 0.0d, Type = typeof(double)
     }, DefaultNodePropertyMapBuilder.LayoutHeightName);
 }
Example #9
0
        /// <inheritdoc/>
        public void AddItems(IOptionBuilderContext context, Type subjectType, object subject)
        {
            PropertyInfo[] propertyInfos =
                SortProperties(context, FilterProperties(context, subjectType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy)));

            foreach (PropertyInfo info in propertyInfos)
            {
                DisplayAttribute descriptionAttribute = GetAttribute <DisplayAttribute>(info);
#if UseDataAnnotations
                string description = descriptionAttribute == null ? info.Name : descriptionAttribute.GetName();
#else
                string description = descriptionAttribute == null ? info.Name : descriptionAttribute.DisplayName;
#endif

                object value = subject == null ? null : info.GetValue(subject, null);
                Type   type  = value == null ? info.PropertyType : value.GetType();

                IOptionBuilder builder = GetBuilder(context, info, subject, type);

                if (builder != null)
                {
                    IOptionBuilderContext childContext = context.CreateChildContext(description);
                    builder.AddItems(childContext, type, value);
                    ConfigureItem((IOptionItem)childContext.Lookup(typeof(IOptionGroup)), info);
                }
                else
                {
                    IOptionItem item = CreateItem(context, info, type, description, value);
                    if (item != null)
                    {
                        context.BindItem(item, description);
                        ConfigureItem(item, info);
                    }
                }
            }
        }