コード例 #1
0
        private Element CreateElement(SimpleVirtualElement simpleElementNode)
        {
            EntityToken entityToken = new VirtualElementProviderEntityToken(_context.ProviderName, simpleElementNode.Name);

            Element element = new Element(_context.CreateElementHandle(entityToken))
            {
                TagValue   = simpleElementNode.Tag,
                VisualData = new ElementVisualizedData
                {
                    Label       = StringResourceSystemFacade.ParseString(simpleElementNode.Label),
                    HasChildren = true // fixing refresh problem easy way... was: HasChildren(baseElementNode)
                }
            };



            Action <IEnumerable> collectProviders = null;

            // Recursively searching for attached providers
            var attachedProviders = new List <AttachProviderVirtualElement>();

            collectProviders = currentElements =>
            {
                attachedProviders.AddRange(currentElements.OfType <AttachProviderVirtualElement>());
                currentElements.OfType <SimpleVirtualElement>().ForEach(e => collectProviders(e.Elements));
            };
            collectProviders(simpleElementNode.Elements);


            foreach (var attachedProvider in attachedProviders)
            {
                if (ElementFacade.ContainsLocalizedData(new ElementProviderHandle(attachedProvider.ProviderName)))
                {
                    element.IsLocaleAware = true;
                }
            }


            if (element.VisualData.HasChildren)
            {
                ResourceHandle openHandle  = IconResourceSystemFacade.GetResourceHandle(simpleElementNode.OpenFolderIconName);
                ResourceHandle closeHandle = IconResourceSystemFacade.GetResourceHandle(simpleElementNode.CloseFolderIconName);

                closeHandle = closeHandle ?? openHandle;
                openHandle  = openHandle ?? closeHandle;

                if (openHandle == null)
                {
                    openHandle  = CommonElementIcons.Folder;
                    closeHandle = CommonElementIcons.FolderOpen;
                }

                element.VisualData.Icon       = openHandle;
                element.VisualData.OpenedIcon = closeHandle;
            }
            else
            {
                element.VisualData.Icon = CommonElementIcons.FolderDisabled;
            }


            return(element);
        }