private static TreeNode BuildDataFolderElementsTreeNode(XElement element, Tree tree)
        {
            XAttribute typeAttribute = element.Attribute("Type");
            XAttribute fieldGroupingNameAttribute = element.Attribute("FieldGroupingName");
            XAttribute dateFormatAttribute        = element.Attribute("DateFormat");
            XAttribute iconAttribute             = element.Attribute("Icon");
            XAttribute rangeAttribute            = element.Attribute("Range");
            XAttribute firstLetterOnlyAttribute  = element.Attribute("FirstLetterOnly");
            XAttribute showForeignItemsAttribute = element.Attribute("ShowForeignItems");
            XAttribute leafDisplayAttribute      = element.Attribute("Display");
            XAttribute sortDirectionAttribute    = element.Attribute("SortDirection");


            if (fieldGroupingNameAttribute == null)
            {
                tree.AddValidationError(element, "TreeValidationError.Common.MissingAttribute", "FieldGroupingName");
                return(null);
            }

            Type interfaceType = null;

            if (typeAttribute != null)
            {
                interfaceType = TypeManager.TryGetType(typeAttribute.Value);
                if (interfaceType == null)
                {
                    tree.AddValidationError(element, "TreeValidationError.Common.UnknownInterfaceType", typeAttribute.Value);
                    return(null);
                }
            }

            bool firstLetterOnly = false;

            if (firstLetterOnlyAttribute != null)
            {
                if (!firstLetterOnlyAttribute.TryGetBoolValue(out firstLetterOnly))
                {
                    tree.AddValidationError(element, "TreeValidationError.Common.WrongAttributeValue", "FirstLetterOnly");
                }
            }

            LeafDisplayMode leafDisplay   = LeafDisplayModeHelper.ParseDisplayMode(leafDisplayAttribute, tree);
            SortDirection   sortDirection = ParseSortDirection(sortDirectionAttribute, tree);

            return(new DataFolderElementsTreeNode
            {
                Tree = tree,
                Id = tree.BuildProcessContext.CreateNewNodeId(),
                InterfaceType = interfaceType,
                Icon = FactoryHelper.GetIcon(iconAttribute.GetValueOrDefault(DefaultDataGroupingFolderResourceName)),
                FieldName = fieldGroupingNameAttribute.Value,
                DateFormat = dateFormatAttribute.GetValueOrDefault(null),
                Range = rangeAttribute.GetValueOrDefault(null),
                FirstLetterOnly = firstLetterOnly,
                ShowForeignItems = showForeignItemsAttribute.GetValueOrDefault("true").ToLowerInvariant() == "true",
                Display = leafDisplay,
                SortDirection = sortDirection
            });
        }
        private static TreeNode BuildDataElementsTreeNode(XElement element, Tree tree)
        {
            XAttribute typeAttribute             = element.Attribute("Type");
            XAttribute labelAttribute            = element.Attribute("Label");
            XAttribute toolTipAttribute          = element.Attribute("ToolTip");
            XAttribute iconAttribute             = element.Attribute("Icon");
            XAttribute openedIconAttribute       = element.Attribute("OpenedIcon");
            XAttribute showForeignItemsAttribute = element.Attribute("ShowForeignItems");
            XAttribute leafDisplayAttribute      = element.Attribute("Display");

            if (typeAttribute == null)
            {
                tree.AddValidationError(element, "TreeValidationError.Common.MissingAttribute", "Type");
                return(null);
            }

            Type interfaceType = TypeManager.TryGetType(typeAttribute.Value);

            if (interfaceType == null)
            {
                tree.AddValidationError(element, "TreeValidationError.Common.UnknownInterfaceType",
                                        typeAttribute.Value);
                return(null);
            }


            LeafDisplayMode leafDisplay = LeafDisplayModeHelper.ParseDisplayMode(leafDisplayAttribute, tree);


            ResourceHandle icon = null;

            if (iconAttribute != null)
            {
                icon = FactoryHelper.GetIcon(iconAttribute.Value);
            }

            ResourceHandle openedIcon = null;

            if (icon != null && openedIconAttribute == null)
            {
                openedIcon = icon;
            }
            else if (openedIconAttribute != null)
            {
                openedIcon = FactoryHelper.GetIcon(openedIconAttribute.Value);
            }

            var dataElementsTreeNode = new DataElementsTreeNode
            {
                Tree             = tree,
                Id               = tree.BuildProcessContext.CreateNewNodeId(),
                InterfaceType    = interfaceType,
                Label            = labelAttribute.GetValueOrDefault(null),
                ToolTip          = toolTipAttribute.GetValueOrDefault(null),
                Icon             = icon,
                OpenedIcon       = openedIcon,
                ShowForeignItems = showForeignItemsAttribute.GetValueOrDefault("true").ToLowerInvariant() == "true",
                Display          = leafDisplay
            };

            List <TreeNode> treeNodes;

            if (tree.BuildProcessContext.DataInteraceToTreeNodes.TryGetValue(interfaceType, out treeNodes) == false)
            {
                treeNodes = new List <TreeNode>();
                tree.BuildProcessContext.DataInteraceToTreeNodes.Add(interfaceType, treeNodes);
            }

            treeNodes.Add(dataElementsTreeNode);

            return(dataElementsTreeNode);
        }