Ejemplo n.º 1
0
        /// <summary>
        /// Populates this instance from scratch using a provided selection provider.
        /// </summary>
        /// <remarks>This instance will be cleared, and all constraints on it will be reset.
        /// The builder inspects the first <see cref="IPropertyItemDescriptor{T}"/> from
        /// <paramref name="selectionProvider"/> and creates an <see cref="IOptionBuilder"/> instance
        /// that will <see cref="IOptionBuilder.AddItems"/> to this instance via the builder.
        /// </remarks>
        /// <param name="selectionProvider"></param>
        /// <param name="contextLookup">The lookup tunnel through to the created
        /// <see cref="IOptionBuilderContext"/> that will be used to query the <see cref="IOptionBuilder"/>
        /// instances for recursive sets of properties.</param>
        public virtual void BuildFromSelection <T>(ISelectionProvider <T> selectionProvider, IContextLookup contextLookup)
        {
            StartContentChange();
            try {
                Clear();
                DefaultOptionBuilderContext <T> context;
                context = new DefaultOptionBuilderContext <T>(selectionProvider, this);
                context.ContextLookup = contextLookup;

                ConstraintManager constraintManager = this.Lookup <ConstraintManager>();
                if (constraintManager == null)
                {
                    constraintManager = new ConstraintManager(this);
                    this.SetLookup(typeof(ConstraintManager), constraintManager);
                }
                constraintManager.Clear();
                IEnumerator <IPropertyItemDescriptor <T> > enumerator = selectionProvider.Selection.GetEnumerator();
                if (enumerator.MoveNext())
                {
                    IPropertyItemDescriptor <T> descriptor = enumerator.Current;
                    T item;
                    item = descriptor.Item;
                    IOptionBuilder builder = context.GetOptionBuilder(item);
                    if (builder != null)
                    {
                        builder.AddItems(context, item.GetType(), item);
                    }
                }
            } finally {
                EndContentChange();
            }
        }
Ejemplo n.º 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);
         }
     }
 }
Ejemplo n.º 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);
             }
         }
     }
 }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 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);
                    }
                }
            }
        }
Ejemplo n.º 8
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);
                    }
                }
            }
        }