Beispiel #1
0
 /// <summary>
 /// Applys the valid rules to the shape
 /// </summary>
 protected void ApplyChangeShapeRules()
 {
     if (this.Enabled)
     {
         if (this._changeShape != null && this._changeShape.Count > 0)
         {
             if (this.ParentForm != null)
             {
                 IXmlShape shape = (IXmlShape)this.ParentForm.Tag;
                 foreach (XmlElement el in _changeShape)
                 {
                     if (el.Attributes["checkFor"] != null && el.Attributes["checkFor"].Value == GetCheckForValue())
                     {
                         shape.ChangeShapeProperties(el.Attributes["property"].Value, el.Attributes["value"].Value);
                     }
                     if (el.Attributes["checkForDifferentThan"] != null && el.Attributes["checkForDifferentThan"].Value != GetCheckForValue())
                     {
                         shape.ChangeShapeProperties(el.Attributes["property"].Value, el.Attributes["value"].Value);
                     }
                 }
             }
             else
             {
                 //TODO - In validate and export this.ParentForm comes here as null
                 //throw(new Exception);
                 //HAMMER - see why the form comes null or if needs to \
             }
         }
     }
 }
Beispiel #2
0
        public virtual void ChangeByConnection(string connectedTo, string connectedFrom)
        {
            if (this._changeByConnection != null && this._changeByConnection.Count > 0)
            {
                IXmlShape shape = (IXmlShape)this.ParentForm.Tag;
                foreach (XmlElement el in _changeByConnection)
                {
                    string s         = el.Attributes["shape"].Value;
                    string t         = el.Attributes["type"].Value;
                    bool   applyRule = false;
                    switch (t)
                    {
                    case "isConnectedTo":
                        applyRule = (connectedTo != null && s.IndexOf(connectedTo) >= 0);
                        break;

                    case "isNotConnectedTo":
                        applyRule = (connectedTo == null || s.IndexOf(connectedTo) < 0);
                        break;

                    case "isConnectedFrom":
                        applyRule = (connectedFrom != null && s.IndexOf(connectedFrom) >= 0);
                        break;

                    case "isNotConnectedFrom":
                        applyRule = (connectedFrom == null || s.IndexOf(connectedFrom) < 0);
                        break;
                    }
                    if (applyRule)
                    {
                        bool val = (el.Attributes["value"].Value == "false" ? false : true);
                        switch (el.Attributes["property"].Value)
                        {
                        case "enabled": this.Enabled = val; break;

                        case "disabled": this.Enabled = !val; break;

                        case "visible": this.Visible = val; break;

                        case "invisible": this.Visible = !val; break;
                        }
                    }
                }
            }
        }
Beispiel #3
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
        }