///--------------------------------------------------------------------------------
        /// <summary>This method loads templates from each unique specification directory
        /// in the specification sources.</summary>
        ///--------------------------------------------------------------------------------
        public void LoadSpecDirectories()
        {
            NameObjectCollection directories = new NameObjectCollection();

            Items.Clear();
            foreach (DatabaseSource source in Solution.DatabaseSourceList)
            {
                source.Solution = Solution;
                if (!String.IsNullOrEmpty(source.TemplatePath) && !String.IsNullOrEmpty(Directory.GetParent(source.TemplateAbsolutePath).FullName))
                {
                    directories[Directory.GetParent(source.TemplateAbsolutePath).FullName] = Directory.GetParent(source.TemplateAbsolutePath).FullName;
                }
            }
            foreach (XmlSource source in Solution.XmlSourceList)
            {
                source.Solution = Solution;
                if (!String.IsNullOrEmpty(source.TemplatePath) && !String.IsNullOrEmpty(Directory.GetParent(source.TemplateAbsolutePath).FullName))
                {
                    directories[Directory.GetParent(source.TemplateAbsolutePath).FullName] = Directory.GetParent(source.TemplateAbsolutePath).FullName;
                }
            }
            for (int i = 0; i < directories.Count; i++)
            {
                if (Directory.Exists(directories[i].ToString()) == true)
                {
                    string folderName           = (directories[i].ToString()).Substring(directories[i].ToString().LastIndexOf("\\") + 1);
                    SpecTemplatesViewModel spec = new SpecTemplatesViewModel(Solution, SpecModelContextTypeCode.SpecificationSource.ToString(), directories[i].ToString(), folderName);
                    Items.Add(spec);
                }
                else
                {
                    ShowIssue(String.Format(DisplayValues.Issue_SpecTemplateDirectoryNotFound, directories[i].ToString()));
                }
            }
            Items.Sort("Name", SortDirection.Ascending);
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This method adds a template to the view models (and tree).</summary>
        ///
        /// <param name="template">The template to add.</param>
        /// <param name="refresh">Flag whether to refresh view.</param>
        ///--------------------------------------------------------------------------------
        public void AddSpecTemplate(SpecTemplateViewModel template, bool refresh = true)
        {
            string templateName = String.Empty;
            ModelContextTypeCode modelContextTypeEnum = ModelContextTypeCode.None;

            Enum.TryParse <ModelContextTypeCode>(template.SpecTemplate.TemplateType, out modelContextTypeEnum);
            switch (modelContextTypeEnum)
            {
            case ModelContextTypeCode.AuditProperty:
                templateName = Resources.DisplayValues.NodeName_Templates_AuditProperty;
                break;

            case ModelContextTypeCode.Collection:
                templateName = Resources.DisplayValues.NodeName_Templates_Collection;
                break;

            case ModelContextTypeCode.Entity:
                templateName = Resources.DisplayValues.NodeName_Templates_Entity;
                break;

            case ModelContextTypeCode.EntityReference:
                templateName = Resources.DisplayValues.NodeName_Templates_EntityReference;
                break;

            case ModelContextTypeCode.Feature:
                templateName = Resources.DisplayValues.NodeName_Templates_Feature;
                break;

            case ModelContextTypeCode.Index:
                templateName = Resources.DisplayValues.NodeName_Templates_Index;
                break;

            case ModelContextTypeCode.IndexProperty:
                templateName = Resources.DisplayValues.NodeName_Templates_IndexProperty;
                break;

            case ModelContextTypeCode.Method:
                templateName = Resources.DisplayValues.NodeName_Templates_Method;
                break;

            case ModelContextTypeCode.Parameter:
                templateName = Resources.DisplayValues.NodeName_Templates_Parameter;
                break;

            case ModelContextTypeCode.Property:
                templateName = Resources.DisplayValues.NodeName_Templates_Property;
                break;

            case ModelContextTypeCode.PropertyReference:
                templateName = Resources.DisplayValues.NodeName_Templates_PropertyReference;
                break;

            case ModelContextTypeCode.Relationship:
                templateName = Resources.DisplayValues.NodeName_Templates_Relationship;
                break;

            case ModelContextTypeCode.RelationshipProperty:
                templateName = Resources.DisplayValues.NodeName_Templates_RelationshipProperty;
                break;

            case ModelContextTypeCode.Workflow:
                templateName = Resources.DisplayValues.NodeName_Templates_Workflow;
                break;

            case ModelContextTypeCode.Stage:
                templateName = Resources.DisplayValues.NodeName_Templates_Stage;
                break;

            case ModelContextTypeCode.StageTransition:
                templateName = Resources.DisplayValues.NodeName_Templates_StageTransition;
                break;

            case ModelContextTypeCode.Step:
                templateName = Resources.DisplayValues.NodeName_Templates_Step;
                break;

            case ModelContextTypeCode.StepTransition:
                templateName = Resources.DisplayValues.NodeName_Templates_StepTransition;
                break;

            case ModelContextTypeCode.StateModel:
                templateName = Resources.DisplayValues.NodeName_Templates_StateModel;
                break;

            case ModelContextTypeCode.State:
                templateName = Resources.DisplayValues.NodeName_Templates_State;
                break;

            case ModelContextTypeCode.StateTransition:
                templateName = Resources.DisplayValues.NodeName_Templates_StateTransition;
                break;

            default:
                SpecModelContextTypeCode specModelContextTypeEnum = SpecModelContextTypeCode.None;
                Enum.TryParse <SpecModelContextTypeCode>(template.SpecTemplate.TemplateType, out specModelContextTypeEnum);
                switch (specModelContextTypeEnum)
                {
                case SpecModelContextTypeCode.SqlColumn:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlColumn;
                    break;

                case SpecModelContextTypeCode.SqlDatabase:
                    Name = Resources.DisplayValues.NodeName_Templates_SqlDatabase;
                    break;

                case SpecModelContextTypeCode.SqlExtendedProperty:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlExtendedProperty;
                    break;

                case SpecModelContextTypeCode.SqlForeignKey:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlForeignKey;
                    break;

                case SpecModelContextTypeCode.SqlForeignKeyColumn:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlForeignKeyColumn;
                    break;

                case SpecModelContextTypeCode.SqlIndex:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlIndex;
                    break;

                case SpecModelContextTypeCode.SqlIndexedColumn:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlIndexedColumn;
                    break;

                case SpecModelContextTypeCode.SqlProperty:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlProperty;
                    break;

                case SpecModelContextTypeCode.SqlTable:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlTable;
                    break;

                case SpecModelContextTypeCode.SqlView:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlView;
                    break;

                case SpecModelContextTypeCode.SqlViewProperty:
                    templateName = Resources.DisplayValues.NodeName_Templates_SqlViewProperty;
                    break;

                case SpecModelContextTypeCode.XmlAttribute:
                    templateName = Resources.DisplayValues.NodeName_Templates_XmlAttribute;
                    break;

                case SpecModelContextTypeCode.XmlDocument:
                    templateName = Resources.DisplayValues.NodeName_Templates_XmlDocument;
                    break;

                case SpecModelContextTypeCode.XmlNode:
                    templateName = Resources.DisplayValues.NodeName_Templates_XmlNode;
                    break;

                default:
                    templateName = Resources.DisplayValues.NodeName_SpecTemplates;
                    break;
                }
                break;
            }
            if (template.SpecTemplate.TemplateType == SpecModelContextTypeCode.SpecificationSource.ToString())
            {
                if (String.IsNullOrEmpty(template.SpecTemplate.CategoryName))
                {
                    Items.Add(template);
                    template.Updated += new EventHandler(Children_Updated);
                    if (refresh == true)
                    {
                        Items.Sort("Name", SortDirection.Ascending);
                    }
                }
                else
                {
                    bool foundCategory = false;
                    foreach (SpecTemplatesViewModel folder in Items.OfType <SpecTemplatesViewModel>())
                    {
                        if (folder.Name == template.SpecTemplate.CategoryName)
                        {
                            folder.AddTemplate(template, refresh);
                            foundCategory = true;
                        }
                    }
                    if (foundCategory == false)
                    {
                        SpecTemplatesViewModel folder = new SpecTemplatesViewModel(Solution, ModelContextTypeCode.None.ToString(), SpecificationDirectory);
                        folder.Name = template.SpecTemplate.CategoryName;
                        folder.AddTemplate(template, refresh);
                        Items.Add(folder);
                        folder.Updated += new EventHandler(Children_Updated);
                        if (refresh == true)
                        {
                            Items.Sort("Name", SortDirection.Ascending);
                        }
                    }
                }
            }
            else
            {
                bool foundFolder = false;
                foreach (SpecTemplatesViewModel folder in Items.OfType <SpecTemplatesViewModel>())
                {
                    if (folder.Name == templateName)
                    {
                        folder.AddTemplate(template, refresh);
                        foundFolder = true;
                    }
                }
                if (foundFolder == false)
                {
                    SpecTemplatesViewModel folder = new SpecTemplatesViewModel(Solution, template.SpecTemplate.TemplateType, SpecificationDirectory);
                    folder.Name = templateName;
                    folder.AddTemplate(template, refresh);
                    Items.Add(folder);
                    folder.Updated += new EventHandler(Children_Updated);
                    if (refresh == true)
                    {
                        Items.Sort("Name", SortDirection.Ascending);
                    }
                }
            }
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This method adds a template to the view models (and tree).</summary>
        ///
        /// <param name="template">The template to add.</param>
        /// <param name="refresh">Flag whether to refresh view.</param>
        ///--------------------------------------------------------------------------------
        public void AddTemplate(SpecTemplateViewModel template, bool refresh = true)
        {
            switch (TemplateModelNode)
            {
            case "Solution":
                bool folderFound = false;
                foreach (SpecTemplatesViewModel view in Items.OfType <SpecTemplatesViewModel>())
                {
                    if (view.SpecificationDirectory == template.SpecTemplate.SpecificationDirectory)
                    {
                        view.AddTemplate(template, refresh);
                        folderFound = true;
                        break;
                    }
                }
                if (folderFound == false)
                {
                    AddSpecTemplate(template, refresh);
                }
                break;

            case "SpecificationSource":
                AddSpecTemplate(template, refresh);
                break;

            default:
                if (String.IsNullOrEmpty(template.SpecTemplate.CategoryName) || template.SpecTemplate.CategoryName == Name)
                {
                    Items.Add(template);
                    template.Updated += new EventHandler(Children_Updated);
                    if (refresh == true)
                    {
                        Items.Sort("Name", SortDirection.Ascending);
                    }
                }
                else
                {
                    bool foundCategory = false;
                    foreach (SpecTemplatesViewModel folder in Items.OfType <SpecTemplatesViewModel>())
                    {
                        if (folder.Name == template.SpecTemplate.CategoryName)
                        {
                            folder.AddTemplate(template, refresh);
                            foundCategory = true;
                        }
                    }
                    if (foundCategory == false)
                    {
                        SpecTemplatesViewModel folder = new SpecTemplatesViewModel(Solution, template.SpecTemplate.TemplateType, SpecificationDirectory);
                        folder.Name = template.SpecTemplate.CategoryName;
                        folder.AddTemplate(template, refresh);
                        Items.Add(folder);
                        folder.Updated += new EventHandler(Children_Updated);
                        if (refresh == true)
                        {
                            Items.Sort("Name", SortDirection.Ascending);
                        }
                    }
                }
                break;
            }
        }