Example #1
0
        private void LoadUsage()
        {
            m_editcon = true;
            this.dataGridViewConceptRules.Rows.Clear();
            this.dataGridViewConceptRules.Columns.Clear();

            if (this.m_conceptroot == null || this.m_conceptleaf == null)// || !this.m_conceptroot.Concepts.Contains(this.m_conceptleaf))
            {
                return;
            }

            LoadInheritance();

            DocTemplateUsage docUsage = (DocTemplateUsage)this.m_conceptleaf;

            if (docUsage.Definition != null)
            {
                this.m_columns = docUsage.Definition.GetParameterRules();
                foreach (DocModelRule rule in this.m_columns)
                {
                    DataGridViewColumn column = new DataGridViewColumn();
                    column.Tag          = rule;
                    column.HeaderText   = rule.Identification;
                    column.ValueType    = typeof(string);//?
                    column.CellTemplate = new DataGridViewTextBoxCell();
                    column.Width        = 200;

                    if (rule.IsCondition())
                    {
                        column.HeaderText += "?";
                    }

                    // override cell template for special cases
                    DocConceptRoot docConceptRoot = (DocConceptRoot)this.m_conceptroot;
                    DocEntity      docEntity      = this.m_project.GetDefinition(docUsage.Definition.Type) as DocEntity;// docConceptRoot.ApplicableEntity;
                    foreach (DocModelRuleAttribute docRule in docUsage.Definition.Rules)
                    {
                        DocAttribute docAttribute = docEntity.ResolveParameterAttribute(docRule, rule.Identification, m_map);
                        if (docAttribute != null)
                        {
                            DocObject docDef = null;
                            if (this.m_map.TryGetValue(docAttribute.DefinedType, out docDef) && docDef is DocDefinition)
                            {
                                if (docDef is DocEnumeration)
                                {
                                    DocEnumeration           docEnum = (DocEnumeration)docDef;
                                    DataGridViewComboBoxCell cell    = new DataGridViewComboBoxCell();
                                    cell.MaxDropDownItems = 32;
                                    cell.DropDownWidth    = 200;
                                    // add blank item
                                    cell.Items.Add(String.Empty);
                                    foreach (DocConstant docConst in docEnum.Constants)
                                    {
                                        cell.Items.Add(docConst.Name);
                                    }
                                    column.CellTemplate = cell;
                                }
                                else if (docDef is DocEntity || docDef is DocSelect)
                                {
                                    // button to launch dialog for picking entity
                                    DataGridViewButtonCell cell = new DataGridViewButtonCell();
                                    cell.Tag            = docDef;
                                    column.CellTemplate = cell;
                                }
                            }
                            else if (docAttribute.DefinedType != null && (docAttribute.DefinedType.Equals("LOGICAL") || docAttribute.DefinedType.Equals("BOOLEAN")))
                            {
                                DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell();
                                cell.MaxDropDownItems = 4;
                                cell.DropDownWidth    = 200;
                                // add blank item
                                cell.Items.Add(String.Empty);
                                cell.Items.Add(Boolean.FalseString);
                                cell.Items.Add(Boolean.TrueString);
                                column.CellTemplate = cell;
                            }
                        }
                    }

                    this.dataGridViewConceptRules.Columns.Add(column);
                }
            }

            // add description column
            DataGridViewColumn coldesc = new DataGridViewColumn();

            coldesc.HeaderText   = "Description";
            coldesc.ValueType    = typeof(string);//?
            coldesc.CellTemplate = new DataGridViewTextBoxCell();
            coldesc.Width        = 400;
            this.dataGridViewConceptRules.Columns.Add(coldesc);

            foreach (DocTemplateItem item in docUsage.Items)
            {
                string[] values = new string[this.dataGridViewConceptRules.Columns.Count];

                if (this.m_columns != null)
                {
                    for (int i = 0; i < this.m_columns.Length; i++)
                    {
                        string parmname = this.m_columns[i].Identification;
                        string val      = item.GetParameterValue(parmname);
                        if (val != null)
                        {
                            values[i] = val;
                        }
                    }
                }

                values[values.Length - 1] = item.Documentation;

                int row = this.dataGridViewConceptRules.Rows.Add(values);
                this.dataGridViewConceptRules.Rows[row].Tag = item;

                if (item.Optional)
                {
                    this.dataGridViewConceptRules.Rows[row].DefaultCellStyle.ForeColor = Color.Gray;
                }
            }

            if (this.dataGridViewConceptRules.SelectedCells.Count > 0)
            {
                this.dataGridViewConceptRules.SelectedCells[0].Selected = false;
            }

            m_editcon = false;
        }
Example #2
0
        private void LoadUsage()
        {
            m_editcon = true;
            this.dataGridViewConceptRules.Rows.Clear();
            this.dataGridViewConceptRules.Columns.Clear();

            if (this.m_conceptroot == null)
            {
                return;
            }

            LoadInheritance();

            List <DocTemplateItem> listItems   = null;
            DocTemplateDefinition  docTemplate = null;

            if (this.m_conceptleaf != null)
            {
                docTemplate = this.m_conceptleaf.Definition;
                if (docTemplate.Uuid == DocTemplateDefinition.guidTemplatePropertyBounded || docTemplate.Uuid == DocTemplateDefinition.guidTemplatePropertyEnumerated ||
                    docTemplate.Uuid == DocTemplateDefinition.guidTemplatePropertyList || docTemplate.Uuid == DocTemplateDefinition.guidTemplatePropertyReference ||
                    docTemplate.Uuid == DocTemplateDefinition.guidTemplatePropertySingle || docTemplate.Uuid == DocTemplateDefinition.guidTemplatePropertyTable)
                {
                    listItems = new List <DocTemplateItem>();
                    foreach (DocTemplateUsage concept in ((DocTemplateItem)this.ConceptItem).Concepts)
                    {
                        if (concept.Items.Count != 0 && concept.Definition.Equals(docTemplate))
                        {
                            listItems.Add(concept.Items[0]);
                        }
                    }
                }
                else
                {
                    listItems = this.m_conceptleaf.Items;
                }
            }
            else
            {
                docTemplate = this.m_conceptroot.ApplicableTemplate;
                listItems   = this.m_conceptroot.ApplicableItems;
            }

            // add usage column
            DataGridViewColumn colflag = new DataGridViewColumn();

            colflag.HeaderText = "Usage";
            DataGridViewComboBoxCell cellflag = new DataGridViewComboBoxCell();

            colflag.CellTemplate      = cellflag;
            colflag.Width             = 80;
            cellflag.MaxDropDownItems = 32;
            cellflag.DropDownWidth    = 80;
            cellflag.Items.Add("Key");
            cellflag.Items.Add("Reference");
            cellflag.Items.Add("Required");
            cellflag.Items.Add("Optional");
            cellflag.Items.Add("Calculated");
            cellflag.Items.Add("System");
            this.dataGridViewConceptRules.Columns.Add(colflag);

            if (docTemplate != null)
            {
                this.m_columns = docTemplate.GetParameterRules();
                foreach (DocModelRule rule in this.m_columns)
                {
                    DataGridViewColumn column = new DataGridViewColumn();
                    column.Tag          = rule;
                    column.HeaderText   = rule.Identification;
                    column.ValueType    = typeof(string);                 //?
                    column.CellTemplate = new DataGridViewTextBoxCell();
                    column.Width        = 200;

                    if (rule.IsCondition())
                    {
                        column.HeaderText += "?";
                    }

                    // override cell template for special cases
                    DocConceptRoot docConceptRoot = (DocConceptRoot)this.m_conceptroot;
                    DocEntity      docEntity      = this.m_project.GetDefinition(docTemplate.Type) as DocEntity;          // docConceptRoot.ApplicableEntity;
                    foreach (DocModelRuleAttribute docRule in docTemplate.Rules)
                    {
                        if (docEntity != null)
                        {
                            DocAttribute docAttribute = docEntity.ResolveParameterAttribute(docRule, rule.Identification, m_map);
                            if (docAttribute == null && docConceptRoot.ApplicableEntity != null)
                            {
                                // try on type itself, e.g. PredefinedType
                                docAttribute = docConceptRoot.ApplicableEntity.ResolveParameterAttribute(docRule, rule.Identification, m_map);
                            }
                            if (docAttribute != null)
                            {
                                DocObject docDef = null;
                                if (this.m_map.TryGetValue(docAttribute.DefinedType, out docDef) && docDef is DocDefinition)
                                {
                                    if (docDef is DocEnumeration)
                                    {
                                        DocEnumeration           docEnum = (DocEnumeration)docDef;
                                        DataGridViewComboBoxCell cell    = new DataGridViewComboBoxCell();
                                        cell.MaxDropDownItems = 32;
                                        cell.DropDownWidth    = 200;
                                        // add blank item
                                        cell.Items.Add(String.Empty);
                                        foreach (DocConstant docConst in docEnum.Constants)
                                        {
                                            cell.Items.Add(docConst.Name);
                                        }
                                        column.CellTemplate = cell;
                                    }
                                    else if (docDef is DocEntity || docDef is DocSelect)
                                    {
                                        // button to launch dialog for picking entity
                                        DataGridViewButtonCell cell = new DataGridViewButtonCell();
                                        cell.Tag            = docDef;
                                        column.CellTemplate = cell;
                                    }
                                }
                                else if (docAttribute.DefinedType != null && (docAttribute.DefinedType.Equals("LOGICAL") || docAttribute.DefinedType.Equals("BOOLEAN")))
                                {
                                    DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell();
                                    cell.MaxDropDownItems = 4;
                                    cell.DropDownWidth    = 200;
                                    // add blank item
                                    cell.Items.Add(String.Empty);
                                    cell.Items.Add(Boolean.FalseString);
                                    cell.Items.Add(Boolean.TrueString);
                                    column.CellTemplate = cell;
                                }
                            }
                        }
                    }

                    this.dataGridViewConceptRules.Columns.Add(column);
                }
            }

            // add description column
            DataGridViewColumn coldesc = new DataGridViewColumn();

            coldesc.HeaderText   = "Description";
            coldesc.ValueType    = typeof(string);         //?
            coldesc.CellTemplate = new DataGridViewTextBoxCell();
            coldesc.Width        = 400;
            this.dataGridViewConceptRules.Columns.Add(coldesc);

            foreach (DocTemplateItem item in listItems)
            {
                string[] values = new string[this.dataGridViewConceptRules.Columns.Count];

                values[0] = item.GetUsage();

                if (this.m_columns != null)
                {
                    for (int i = 0; i < this.m_columns.Length; i++)
                    {
                        string parmname = this.m_columns[i].Identification;
                        string val      = item.GetParameterValue(parmname);
                        if (val != null)
                        {
                            values[i + 1] = val;
                        }
                    }
                }

                values[values.Length - 1] = item.Documentation;

                int row = this.dataGridViewConceptRules.Rows.Add(values);
                this.dataGridViewConceptRules.Rows[row].Tag = item;
                this.dataGridViewConceptRules.Rows[row].DefaultCellStyle.BackColor = item.GetColor();
            }

            if (this.dataGridViewConceptRules.SelectedCells.Count > 0)
            {
                this.dataGridViewConceptRules.SelectedCells[0].Selected = false;
            }

            ToolStripButtonVisibility();

            m_editcon = false;
        }