예제 #1
0
        internal void ParseItems(IXApplication app, IAttributeSet atts, IMetadata[] metadata,
                                 out bool isStatic, out ItemsControlItem[] staticItems, out IMetadata itemsSourceMetadata)
        {
            if (atts.ContextType.IsEnum)
            {
                var items = EnumExtension.GetEnumFields(atts.ContextType);
                staticItems = items.Select(i => new ItemsControlItem()
                {
                    DisplayName = i.Value,
                    Value       = i.Key
                }).ToArray();

                isStatic            = true;
                itemsSourceMetadata = null;
            }
            else
            {
                var customItemsAtt = atts.Get <ItemsSourceControlAttribute>();

                if (customItemsAtt.StaticItems?.Any() == true)
                {
                    staticItems = customItemsAtt
                                  .StaticItems.Select(i => new ItemsControlItem(i)).ToArray();

                    isStatic            = true;
                    itemsSourceMetadata = null;
                }
                else if (customItemsAtt.CustomItemsProvider != null)
                {
                    itemsSourceMetadata = null;

                    if (customItemsAtt.Dependencies?.Any() != true)
                    {
                        var provider = customItemsAtt.CustomItemsProvider;
                        staticItems = provider.ProvideItems(app, new IControl[0]).Select(i => new ItemsControlItem(i)).ToArray();
                        isStatic    = true;
                    }
                    else
                    {
                        isStatic    = false;
                        staticItems = null;
                    }
                }
                else if (customItemsAtt.ItemsSource != null)
                {
                    isStatic            = false;
                    staticItems         = null;
                    itemsSourceMetadata = metadata?.FirstOrDefault(m => object.Equals(m.Tag, customItemsAtt.ItemsSource));

                    if (itemsSourceMetadata == null)
                    {
                        throw new NullReferenceException($"Failed to find the items source metadata property: {customItemsAtt.ItemsSource}");
                    }
                }
                else
                {
                    throw new NotSupportedException("Items source is not specified");
                }
            }
        }
        protected override ItemsControlItem[] GetItems(IAttributeSet atts)
        {
            var items = EnumExtension.GetEnumFields(atts.BoundType);

            return(items.Select(i => new ItemsControlItem()
            {
                DisplayName = i.Value,
                Value = i.Key
            }).ToArray());
        }
        private PropertyManagerPageOptionBox CreateOptionBoxControl(ControlOptionsAttribute opts, IAttributeSet atts,
                                                                    ControlCreatorDelegate creator)
        {
            var options = EnumExtension.GetEnumFields(atts.BoundType);

            var ctrls = new IPropertyManagerPageOption[options.Count];

            for (int i = 0; i < options.Count; i++)
            {
                var name = options.ElementAt(i).Value;
                ctrls[i] = creator.Invoke(atts.Id + i, (short)swPropertyManagerPageControlType_e.swControlType_Option, name,
                                          (short)opts.Align, (short)opts.Options, atts.Description);
            }

            return(new PropertyManagerPageOptionBox(ctrls));
        }
        protected override PropertyManagerPageOptionBoxControl CreateControl(
            PropertyManagerPageOptionBox swCtrl, IAttributeSet atts, SwPropertyManagerPageHandler handler, short height)
        {
            var options = EnumExtension.GetEnumFields(atts.BoundType);

            if (atts.Has <OptionBoxOptionsAttribute>())
            {
                var style = atts.Get <OptionBoxOptionsAttribute>();

                if (style.Style != 0)
                {
                    swCtrl.Style = (int)style.Style;
                }
            }

            return(new PropertyManagerPageOptionBoxControl(atts.Id, atts.Tag, swCtrl, options.Keys.ToList().AsReadOnly(), handler));
        }
        internal ItemsControlItem[] GetItems(IXApplication app, IAttributeSet atts)
        {
            if (atts.ContextType.IsEnum)
            {
                var items = EnumExtension.GetEnumFields(atts.ContextType);
                return(items.Select(i => new ItemsControlItem()
                {
                    DisplayName = i.Value,
                    Value = i.Key
                }).ToArray());
            }
            else
            {
                var customItemsAtt = atts.Get <ItemsSourceControlAttribute>();

                List <object> items = null;

                if (customItemsAtt.StaticItems != null)
                {
                    items = customItemsAtt.StaticItems.ToList();
                }
                else if (customItemsAtt.CustomItemsProvider != null)
                {
                    var provider = customItemsAtt.CustomItemsProvider;

                    var depsCount = customItemsAtt.Dependencies?.Length;

                    //TODO: dependency controls cannot be loaded at this stage as binding is not yet loaded - need to sort this out
                    //Not very critical at this stage as provide items wil be called as part ResolveState for dependent controls
                    //For now just add a note in the documentation for this behavior
                    items = provider.ProvideItems(app, new IControl[depsCount.Value])?.ToList();
                }
                else if (customItemsAtt.ItemsSource != null)
                {
                    //this will be resolved dynamically
                    items = new List <object>();
                }

                if (items == null)
                {
                    items = new List <object>();
                }

                return(items.Select(i => new ItemsControlItem(i)).ToArray());
            }
        }
        protected override PropertyManagerPageComboBoxControl CreateControl(
            IPropertyManagerPageCombobox swCtrl, IAttributeSet atts, SwPropertyManagerPageHandler handler, short height)
        {
            var items = EnumExtension.GetEnumFields(atts.BoundType);

            swCtrl.AddItems(items.Values.ToArray());

            if (height != -1)
            {
                swCtrl.Height = height;
            }

            if (atts.Has <ComboBoxOptionsAttribute>())
            {
                var style = atts.Get <ComboBoxOptionsAttribute>();

                if (style.Style != 0)
                {
                    swCtrl.Style = (int)style.Style;
                }
            }

            return(new PropertyManagerPageComboBoxControl(atts.Id, atts.Tag, swCtrl, items.Keys.ToList().AsReadOnly(), handler));
        }
 protected override PropertyManagerPageOptionBoxControl Create(PropertyManagerPageGroupBase group, IAttributeSet atts, ref int idRange)
 {
     idRange = EnumExtension.GetEnumFields(atts.BoundType).Count;
     return(base.Create(group, atts));
 }
 protected override PropertyManagerPageOptionBoxControl Create(PropertyManagerPagePage page, IAttributeSet atts, IMetadata metadata, ref int idRange)
 {
     idRange = EnumExtension.GetEnumFields(atts.ContextType).Count;
     return(base.Create(page, atts, metadata));
 }
예제 #9
0
 protected override PropertyManagerPageOptionBoxControl Create(PropertyManagerPageGroupBase group, IAttributeSet atts, IMetadata[] metadata, ref int numberOfUsedIds)
 {
     numberOfUsedIds = EnumExtension.GetEnumFields(atts.ContextType).Count;
     return(base.Create(group, atts, metadata, ref numberOfUsedIds));
 }