Beispiel #1
0
        /// <summary>
        /// Places the focus on the first element with an error.
        /// </summary>
        private void FocusFirstError()
        {
            foreach (Control control in _fields)
            {
                IXmlProperty property = (IXmlProperty)control;

                if (property.IsValid == false)
                {
                    Control firstControl = FormUtils.LowestTabIndex(control);

                    if (firstControl != null)
                    {
                        Debug.Assert(control.Parent.Parent.GetType() == typeof(TabPage));
                        tabControl.SelectedTab = (TabPage)control.Parent.Parent;

                        firstControl.Focus();
                        return;
                    }
                }
            }
        }
Beispiel #2
0
        public void Design(string mode, Microsoft.Office.Interop.Visio.Page page)
        {
            if (_definition == null)
            {
                throw new Exception("Cannot .Design if no definition has ben .Load()'ed.");
            }

            /*
             * Parse definition properties.
             */
            #region Properties

            XmlElement properties = (XmlElement)_definition.SelectSingleNode("/shape/properties", FormsNamespace.NamespaceManager);

            if (properties == null)
            {
                throw new ArgumentException("Missing properties element.", "doc");
            }

            this.Text = properties.Attributes["title"].Value;

            #endregion

            IXmlShape shape = null;
            if (this.Tag is IXmlShape)
            {
                shape = (IXmlShape)this.Tag;
            }

            #region Create Tabs

            XmlNodeList tabNodeList = properties.SelectNodes("tab", FormsNamespace.NamespaceManager);
            foreach (XmlElement tabElement in tabNodeList)
            {
                /*
                 * Iterate through tab list. Please note that since each Control is
                 * being added with Dock.Top, they will visually appear in reverse order.
                 * Therefore, once all have been added, we perform a ReLayout!
                 */

                XmlTabPage tab = new XmlTabPage(tabElement);
                if (tab.IsInvisibleInMode(mode))//Se tab invisível, não é adicionado ao form
                {
                    continue;
                }
                if (tab.IsDisabledInMode(mode))
                {
                    ((Control)tab.TabPage).Enabled = false;
                }

                tabControl.TabPages.Add(tab.TabPage);
                XmlNodeList fieldNodeList = tabElement.SelectNodes("*");

                foreach (XmlElement fieldElement in fieldNodeList)
                {
                    /*
                     * Iterate through each property. Note how we do not include in the _fields
                     * bag controls that are not IXmlProperty!
                     */
                    if (fieldElement.Name == "include")
                    {
                        string   filename, xPath, excludedProperties = null;
                        string[] excludedPropertiesList = null;
                        string   prefix = null;

                        if ((fieldElement.Attributes["file"] != null))
                        {
                            filename = fieldElement.Attributes["file"].Value;
                        }
                        else
                        {
                            throw (new Exception("Element include in shape definition doesn´t have the attribute 'file'!"));
                        }

                        if ((fieldElement.Attributes["xPath"] != null))
                        {
                            xPath = fieldElement.Attributes["xPath"].Value;
                        }
                        else
                        {
                            throw (new Exception("Element include in shape definition doesn´t have the attribute 'xPath'!"));
                        }

                        if ((fieldElement.Attributes["prefix"] != null))
                        {
                            prefix = fieldElement.Attributes["prefix"].Value;
                        }

                        if ((fieldElement.Attributes["excludedProperties"] != null))
                        {
                            excludedProperties     = fieldElement.Attributes["excludedProperties"].Value;
                            excludedPropertiesList = excludedProperties.Replace(" ", "").Split(',');
                        }

                        XmlDocument xdoc = LoadPropertiesFromFile(filename);
                        foreach (XmlElement fieldElem in xdoc.SelectNodes(xPath))
                        {
                            if ((excludedPropertiesList != null) && checkIfExcludedNode(fieldElem.Attributes["id"].Value, excludedPropertiesList))
                            {
                                continue;
                            }

                            if (prefix != null)
                            {
                                fieldElem.Attributes["id"].Value = string.Format("{0}_{1}", prefix, fieldElem.Attributes["id"].Value);
                            }

                            Control      control    = XmlFormFactory.CreateProperty(fieldElem, mode, page);
                            BaseProperty tmpControl = control as BaseProperty;

                            if (control is IXmlProperty)
                            {
                                IXmlProperty property = (IXmlProperty)control;
                                _fields.Add(property);
                            }

                            if (tmpControl != null)
                            {
                                if (tmpControl.IsInvisibleInMode(fieldElem, mode))
                                {
                                    continue;
                                }
                                if (tmpControl.IsDisabledInMode(fieldElem, mode))
                                {
                                    control.Enabled = false;
                                }
                            }

                            if (control.Visible)
                            {
                                tab.AddProperty(control);
                            }

                            if (shape != null && tmpControl != null)
                            {
                                tmpControl.ChangeByConnection(shape.ConnectedTo(), shape.ConnectedFrom());
                            }
                        }
                    }
                    else
                    {
                        Control      control    = XmlFormFactory.CreateProperty(fieldElement, mode, page);
                        BaseProperty tmpControl = control as BaseProperty;

                        if (control is IXmlProperty)
                        {
                            IXmlProperty property = (IXmlProperty)control;
                            _fields.Add(property);
                        }

                        if (tmpControl != null)
                        {
                            if (tmpControl.IsInvisibleInMode(fieldElement, mode))
                            {
                                continue;
                            }
                            if (tmpControl.IsDisabledInMode(fieldElement, mode))
                            {
                                control.Enabled = false;
                            }
                        }

                        if (control.Visible)
                        {
                            tab.AddProperty(control);
                        }

                        if (shape != null && tmpControl != null)
                        {
                            tmpControl.ChangeByConnection(shape.ConnectedTo(), shape.ConnectedFrom());
                        }
                    }
                }

                tab.ReLayout();
            }

            #endregion

            #region Shape Specific AddOns
            if (shape != null)
            {
                shape.Design();
            }
            #endregion
        }