Ejemplo n.º 1
0
        /// <summary>
        /// Determines whether the user can add a new instance of the given info.
        /// </summary>
        /// <returns>
        /// <c>true</c> if the user can add a new instance; otherwise, <c>false</c>.
        /// </returns>
        protected virtual bool CanAddNewInstance(IPatternElementInfo info)
        {
            // Only show menu for elements/collections
            var abstractElementInfo = info as IAbstractElementInfo;

            if (abstractElementInfo != null)
            {
                if (abstractElementInfo.IsVisible && abstractElementInfo.AllowAddNew)
                {
                    var cardinality = abstractElementInfo.Cardinality;
                    switch (cardinality)
                    {
                    case Cardinality.OneToMany:
                    case Cardinality.ZeroToMany:
                        return(true);

                    default:
                        //case Cardinality.OneToOne:
                        //case Cardinality.ZeroToOne:
                        return(this.ElementContainerData.Elements.Count(e => e.Info == abstractElementInfo) == 0);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
 private static IElement NewElement(IElementContainer parent, IPatternElementInfo info, string name)
 {
     return(parent.CreateElement(e =>
     {
         e.DefinitionId = info.Id;
         e.InstanceName = name;
     }));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Determines if the customizable setting for the DefaultValue property of a customizable element is enabled.
        /// </summary>
        public bool IsPropertyDefaultValueCustomizationEnabled(IPatternElementInfo property)
        {
            Guard.NotNull(() => property, property);

            var defaultValueProperty = Reflector <IPropertySchema> .GetProperty(prop => prop.RawDefaultValue).Name;

            return(property.Policy.Settings
                   .Any(setting => setting.PropertyId == defaultValueProperty && setting.IsEnabled));
        }
Ejemplo n.º 4
0
            private static IProduct NewExtension(IElementContainer parent, IPatternElementInfo info, string name)
            {
                var productInfo = (IPatternInfo)info;

                return(parent.CreateExtension(e =>
                {
                    e.DefinitionId = productInfo.Id;
                    e.InstanceName = name;
                    e.ExtensionId = productInfo.ExtensionId;
                }));
            }
Ejemplo n.º 5
0
        /// <summary>
        /// Determines whether an 'Add' menu can be created for the element info
        /// </summary>
        /// <returns>
        /// <c>true</c> if the menu can be created; otherwise <c>false</c>.
        /// </returns>
        protected virtual bool CanCreateAddMenu(IPatternElementInfo info)
        {
            // Only hide for elements/collections
            var abstractElementInfo = info as IAbstractElementInfo;

            if (abstractElementInfo != null)
            {
                return(abstractElementInfo.IsVisible && abstractElementInfo.AllowAddNew);
            }

            return(true);
        }
Ejemplo n.º 6
0
        private static IEnumerable <IPatternElementInfo> FindDescendants(this IPatternElementInfo element)
        {
            var container = element as IElementInfoContainer;

            if (container != null)
            {
                return(container.Elements.Concat(container.Elements.SelectMany(e => e.FindDescendants())));
            }
            else
            {
                return(Enumerable.Empty <IPatternElementInfo>());
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AddNewNodeViewModel"/> class.
        /// </summary>
        /// <param name="siblings">The sibilings.</param>
        /// <param name="info">The info.</param>
        /// <param name="userMessageService">The user message service.</param>
        public AddNewNodeViewModel(
            IEnumerable<IProductElement> siblings,
            IPatternElementInfo info,
            IUserMessageService userMessageService)
        {
            Guard.NotNull(() => siblings, siblings);
            Guard.NotNull(() => info, info);
            Guard.NotNull(() => userMessageService, userMessageService);

            this.info = info;
            this.sibilings = siblings;
            this.instanceName = siblings.GetNewUniqueName(info.DisplayName);
            this.userMessageService = userMessageService;
            this.InitializeCommands();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AddNewNodeViewModel"/> class.
        /// </summary>
        /// <param name="siblings">The sibilings.</param>
        /// <param name="info">The info.</param>
        /// <param name="userMessageService">The user message service.</param>
        public AddNewNodeViewModel(
            IEnumerable <IProductElement> siblings,
            IPatternElementInfo info,
            IUserMessageService userMessageService)
        {
            Guard.NotNull(() => siblings, siblings);
            Guard.NotNull(() => info, info);
            Guard.NotNull(() => userMessageService, userMessageService);

            this.info               = info;
            this.sibilings          = siblings;
            this.instanceName       = siblings.GetNewUniqueName(info.DisplayName);
            this.userMessageService = userMessageService;
            this.InitializeCommands();
        }
Ejemplo n.º 9
0
 private void AddProductElement(IPatternElementInfo info)
 {
     tracer.ShieldUI(() =>
     {
         var instanceName = AddNewElement(info);
         if (!String.IsNullOrEmpty(instanceName))
         {
             using (new MouseCursor(System.Windows.Input.Cursors.Wait))
             {
                 var element = Factory.CreateElement(this.ElementContainerData, info, instanceName);
                 this.Select(element);
             }
         }
     }, Resources.ProductElementViewModel_ElementCreationFailed, info.DisplayName);
 }
Ejemplo n.º 10
0
        public static IEnumerable <IPatternElementInfo> FindAllChildren(this IPatternElementInfo info)
        {
            Guard.NotNull(() => info, info);

            if (info is IPatternInfo)
            {
                var productInfo = info as IPatternInfo;
                return(productInfo.Views
                       .SelectMany(viewInfo => viewInfo.Elements));
            }
            else
            {
                var containerInfo = info as IElementInfoContainer;
                return(containerInfo.Elements);
            }
        }
Ejemplo n.º 11
0
        public string AddNewElement(IPatternElementInfo info)
        {
            var instanceName = string.Empty;

            tracer.ShieldUI(() =>
            {
                var viewModel = this.CreateNewNodeViewModel(info);
                var view      = this.Context.NewNodeDialogFactory(viewModel);
                if (view.ShowDialog().GetValueOrDefault())
                {
                    instanceName = viewModel.InstanceName;
                }
            }, Resources.ProductElementViewModel_ElementCreationFailed, info.DisplayName);

            return(instanceName);
        }
Ejemplo n.º 12
0
        public static IEnumerable <TInfo> FindAllDescendants <TInfo>(this IPatternElementInfo info) where TInfo : IPatternElementInfo
        {
            var infos = new List <TInfo>();

            Guard.NotNull(() => info, info);

            if (info is IPatternInfo)
            {
                var productInfo = info as IPatternInfo;
                foreach (var viewInfo in productInfo.Views)
                {
                    infos.AddRange(viewInfo.Elements.OfType <TInfo>());
                    foreach (var abstractElementInfo in viewInfo.Elements)
                    {
                        infos.AddRange(abstractElementInfo.FindAllDescendants <TInfo>());
                    }
                }
            }
            else
            {
                if (info is IElementInfoContainer)
                {
                    var containerInfo = info as IElementInfoContainer;
                    infos.AddRange(containerInfo.Elements.OfType <TInfo>());
                    foreach (var elementInfo in containerInfo.Elements)
                    {
                        infos.AddRange(elementInfo.FindAllDescendants <TInfo>());
                    }
                    infos.AddRange(containerInfo.ExtensionPoints.OfType <TInfo>());
                    foreach (var extensionPointInfo in containerInfo.ExtensionPoints)
                    {
                        infos.AddRange(extensionPointInfo.FindAllDescendants <TInfo>());
                    }
                }
            }

            return(infos);
        }
Ejemplo n.º 13
0
            internal static IProductElement CreateElement(IElementContainer parent, IPatternElementInfo info, string name)
            {
                var factory = FindFactory(info);

                return(factory(parent, info, name));
            }
 public string AddNewElement(IPatternElementInfo info)
 {
     return null;
 }
Ejemplo n.º 15
0
 public string AddNewElement(IPatternElementInfo info)
 {
     return(null);
 }
 protected override bool CanCreateAddMenu(IPatternElementInfo info)
 {
     return(base.CanCreateAddMenu(info));
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Creates a new instance of the given child element with an optional instance name.
        /// </summary>
        public static IAbstractElement CreateChildElement(this IProductElement parentElement, IPatternElementInfo childElementInfo, string instanceName = "", bool raiseInstantiateEvents = true)
        {
            Guard.NotNull(() => parentElement, parentElement);
            Guard.NotNull(() => childElementInfo, childElementInfo);

            // Ensure correct container
            var productContainer = parentElement as IProduct;
            var containerElement = parentElement as IElementContainer;

            if (containerElement == null)
            {
                if (productContainer != null)
                {
                    // Redirect to the 'current' view
                    containerElement = productContainer.CurrentView;
                }
                else
                {
                    return(null);
                }
            }

            if (String.IsNullOrEmpty(instanceName))
            {
                instanceName = childElementInfo.DisplayName;
            }

            var uniqueInstanceName = containerElement.GetNewUniqueName(instanceName, false);

            if (childElementInfo is ICollectionInfo)
            {
                return(containerElement.CreateCollection(c =>
                {
                    c.DefinitionId = childElementInfo.Id;
                    c.InstanceName = uniqueInstanceName;
                }, raiseInstantiateEvents));
            }
            else if (childElementInfo is IElementInfo)
            {
                return(containerElement.CreateElement(e =>
                {
                    e.DefinitionId = childElementInfo.Id;
                    e.InstanceName = uniqueInstanceName;
                }, raiseInstantiateEvents));
            }
            else
            {
                throw new NotImplementedException(Resources.ProductElementExtensions_CreateChildElement_InvalidType);
            }
        }
 protected override bool CanAddNewInstance(IPatternElementInfo info)
 {
     return(base.CanAddNewInstance(info));
 }
 internal bool CanCreateAddMenuInternal(IPatternElementInfo info)
 {
     return(CanCreateAddMenu(info));
 }
Ejemplo n.º 20
0
 private static Func <IElementContainer, IPatternElementInfo, string, IProductElement> FindFactory(IPatternElementInfo info)
 {
     return(elementFactories.Where(f => f.Key.IsAssignableFrom(info.GetType())).Select(f => f.Value).First());
 }
Ejemplo n.º 21
0
 private AddNewNodeViewModel CreateNewNodeViewModel(IPatternElementInfo info)
 {
     return(new AddNewNodeViewModel(this.ChildNodes.Select(x => x.Data), info, this.Context.UserMessageService));
 }
 internal bool CanAddNewInstanceInternal(IPatternElementInfo info)
 {
     return(CanAddNewInstance(info));
 }