/// <summary>
        /// 
        /// </summary>
        /// <param name="basetype">DocEntity or DocSelect.</param>
        /// <param name="selection"></param>
        /// <param name="project"></param>
        /// <param name="predefined">Select predefined type.</param>
        public FormSelectEntity(
            DocDefinition basetype, 
            DocDefinition selection, 
            DocProject project,
            SelectDefinitionOptions options)
            : this()
        {
            this.m_basetype = basetype;
            this.m_selection = selection;
            this.m_project = project;
            this.m_options = options;

            this.m_mapAlpha = new Dictionary<DocDefinition, TreeNode>();
            this.m_mapInherit = new Dictionary<DocDefinition, TreeNode>();

            // load subtypes, sort alphabetically
            if (this.m_basetype is DocEntity)
            {
                this.LoadEntity(null, (DocEntity)this.m_basetype);
                this.tabControl1.TabPages.RemoveAt(1);
            }
            else if (this.m_basetype is DocSelect)
            {
                this.LoadSelect(null, (DocSelect)this.m_basetype);
                this.tabControl1.TabPages.RemoveAt(1);
            }
            else if (this.m_basetype != null)
            {
                // add single node for type
                TreeNode tn = new TreeNode();
                tn.Tag = basetype;
                tn.Text = basetype.Name;
                this.treeViewInheritance.Nodes.Add(tn);

                this.tabControl1.TabPages.RemoveAt(1);
            }
            else
            {
                // all entities
                SortedList<string, DocDefinition> sort = new SortedList<string, DocDefinition>();
                SortedList<string, DocDefinition> sortAll = new SortedList<string, DocDefinition>();
                foreach (DocSection docSection in this.m_project.Sections)
                {
                    foreach (DocSchema docSchema in docSection.Schemas)
                    {
                        foreach (DocEntity docEntity in docSchema.Entities)
                        {
                            if (docEntity.BaseDefinition == null)
                            {
                                if(!sort.ContainsKey(docEntity.Name))
                                { 
                                    sort.Add(docEntity.Name, docEntity);
                                }
                            }

                            if (!sortAll.ContainsKey(docEntity.Name))
                            {
                                sortAll.Add(docEntity.Name, docEntity);
                            }
                        }

                        if ((options & SelectDefinitionOptions.Type) != 0)
                        {
                            // temp: all types too; todo: specify parameter
                            foreach (DocType docType in docSchema.Types)
                            {
                                sort.Add(docType.Name, docType);

                                if (!sortAll.ContainsKey(docType.Name))
                                {
                                    sortAll.Add(docType.Name, docType);
                                }
                            }
                        }
                    }
                }

                foreach (DocDefinition docDef in sort.Values)
                {
                    if (docDef is DocEntity)
                    {
                        this.LoadEntity(null, (DocEntity)docDef);
                    }
                    else if (docDef is DocType)
                    {
                        this.LoadType(null, (DocType)docDef);
                    }
                }

                foreach(DocDefinition docDef in sortAll.Values)
                {
                    TreeNode tnAlpha = new TreeNode();
                    tnAlpha.Tag = docDef;
                    tnAlpha.Text = docDef.Name;
                    this.m_mapAlpha.Add(docDef, tnAlpha);
                    this.treeViewAlphabetical.Nodes.Add(tnAlpha);
                }
            }

            if (this.treeViewInheritance.SelectedNode == null && this.treeViewInheritance.Nodes.Count > 0)
            {
                this.treeViewInheritance.SelectedNode = this.treeViewInheritance.Nodes[0];
            }

            this.treeViewInheritance.ExpandAll();
            this.treeViewInheritance.Focus();
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="basetype">DocEntity or DocSelect.</param>
        /// <param name="selection"></param>
        /// <param name="project"></param>
        /// <param name="predefined">Select predefined type.</param>
        public FormSelectEntity(
            DocDefinition basetype,
            DocDefinition selection,
            DocProject project,
            SelectDefinitionOptions options)
            : this()
        {
            this.m_basetype  = basetype;
            this.m_selection = selection;
            this.m_project   = project;
            this.m_options   = options;

            this.m_mapAlpha   = new Dictionary <DocDefinition, TreeNode>();
            this.m_mapInherit = new Dictionary <DocDefinition, TreeNode>();

            // load subtypes, sort alphabetically
            if (this.m_basetype is DocEntity)
            {
                this.LoadEntity(null, (DocEntity)this.m_basetype);
                this.tabControl1.TabPages.RemoveAt(1);
            }
            else if (this.m_basetype is DocSelect)
            {
                this.LoadSelect(null, (DocSelect)this.m_basetype);
                this.tabControl1.TabPages.RemoveAt(1);
            }
            else if (this.m_basetype != null)
            {
                // add single node for type
                TreeNode tn = new TreeNode();
                tn.Tag  = basetype;
                tn.Text = basetype.Name;
                this.treeViewInheritance.Nodes.Add(tn);

                this.tabControl1.TabPages.RemoveAt(1);
            }
            else
            {
                // all entities
                SortedList <string, DocDefinition> sort    = new SortedList <string, DocDefinition>();
                SortedList <string, DocDefinition> sortAll = new SortedList <string, DocDefinition>();
                foreach (DocSection docSection in this.m_project.Sections)
                {
                    foreach (DocSchema docSchema in docSection.Schemas)
                    {
                        foreach (DocEntity docEntity in docSchema.Entities)
                        {
                            if (docEntity.BaseDefinition == null)
                            {
                                if (!sort.ContainsKey(docEntity.Name))
                                {
                                    sort.Add(docEntity.Name, docEntity);
                                }
                            }

                            if (!sortAll.ContainsKey(docEntity.Name))
                            {
                                sortAll.Add(docEntity.Name, docEntity);
                            }
                        }

                        if ((options & SelectDefinitionOptions.Type) != 0)
                        {
                            // temp: all types too; todo: specify parameter
                            foreach (DocType docType in docSchema.Types)
                            {
                                sort.Add(docType.Name, docType);

                                if (!sortAll.ContainsKey(docType.Name))
                                {
                                    sortAll.Add(docType.Name, docType);
                                }
                            }
                        }
                    }
                }

                foreach (DocDefinition docDef in sort.Values)
                {
                    if (docDef is DocEntity)
                    {
                        this.LoadEntity(null, (DocEntity)docDef);
                    }
                    else if (docDef is DocType)
                    {
                        this.LoadType(null, (DocType)docDef);
                    }
                }

                foreach (DocDefinition docDef in sortAll.Values)
                {
                    TreeNode tnAlpha = new TreeNode();
                    tnAlpha.Tag  = docDef;
                    tnAlpha.Text = docDef.Name;
                    this.m_mapAlpha.Add(docDef, tnAlpha);
                    this.treeViewAlphabetical.Nodes.Add(tnAlpha);
                }
            }

            if (this.treeViewInheritance.SelectedNode == null && this.treeViewInheritance.Nodes.Count > 0)
            {
                this.treeViewInheritance.SelectedNode = this.treeViewInheritance.Nodes[0];
            }

            this.treeViewInheritance.ExpandAll();
            this.treeViewInheritance.Focus();
        }