Beispiel #1
0
 // Constructor
 protected Item(XmlNode xsdNode, GroupItem parent = null, bool isFunction = false)
 {
     if (!isFunction)
         _id = ++_count;
     XsdNode = xsdNode;
     IsFunction = isFunction;
     Parent = parent;
     IsRequired = XsdParser.IsRequired(xsdNode);
     Name = XsdParser.GetName(xsdNode);
     Help = XsdParser.GetHelp(xsdNode);
     IsGroupItem = XsdParser.IsGroupItem(xsdNode);
     IsElementItem = XsdParser.IsElementItem(xsdNode);
 }
Beispiel #2
0
        // Constructor
        /// <summary> Creates a child ElementItem from the XSD file. </summary>
        /// <param name="xsdNode"> The XmlNode from the XSD Functions file that represents this item. </param>
        /// <param name="parent"> The parent of this item. </param>
        /// <param name="isFunction"> [Optional] Note if this is a Function. </param>
        public ElementItem(XmlNode xsdNode, GroupItem parent, bool isFunction = false)
            : base(xsdNode, parent, isFunction)
        {
            // Check
            Debug.Assert(XsdParser.HasAttributes(xsdNode), "XSD Node '" + Name + "' had no attributes.");
            Debug.Assert(XsdParser.HasType(xsdNode), "XSD Node '" + Name + "' had no type.");

            _complexType = Structure.CreateComplexType(XsdParser.GetType(xsdNode));

            // Check
            Debug.Assert(_complexType != null, "Alternative: Structure.FindComplexType(xsdNode) Failed!");

            // Set the (default) selected type.
            SelectType(_complexType);

            // Create this item's control
            CreateGeneralControl(_complexType);
        }
Beispiel #3
0
        // Constructor
        /// <summary> Creates a child GroupItem from the XSD Functions file. </summary>
        /// <param name="xsdNode"> A XmlNode from the XSD Functions file. </param>
        /// <param name="parent"> The parent of this item. </param>
        /// <param name="isFunction"> Note if this is a Function. </param>
        public GroupItem(XmlNode xsdNode, GroupItem parent = null, bool isFunction = false)
            : base(xsdNode, parent, isFunction)
        {
            // Can exist multiple times?
            IsMultiple = XsdParser.IsMupltiple(xsdNode);

            // Can the user do Right-Click actions on this element?
            HasRightClickActions = XsdParser.HasRightClickActions(xsdNode);

            // Create the TreeNode of TreeViewer.
            Tnode = new TreeNode(Name) {Tag = this, ToolTipText = Help};

            SetParent(parent);

            // Children
            Children = XsdParser.CreateChildren(xsdNode, this, isFunction);

            // Create the Controls for this ElementItem with the gathered information
            Control = new GeneralControl(Name, IsRequired, Help);
        }
Beispiel #4
0
        public void SetParent(GroupItem parent)
        {
            if (parent == null) return;

            Parent = parent;

            if(IsGroupItem)
                parent.Tnode.Nodes.Add(((GroupItem)this).Tnode);
        }
Beispiel #5
0
        /* PUBLIC METHODS */
        public Item DuplicateStructure()
        {
            Item clone = null;

            // Duplicate via constructor.
            if (IsGroupItem)
                clone = new GroupItem(XsdNode, null, IsFunction);
            else if (IsElementItem)
                clone = new ElementItem(XsdNode, null, IsFunction);

            return clone;
        }
Beispiel #6
0
        /// <summary>
        /// Creates all the children of the given item and returns them as a list of items.
        ///  Includes inner children too (recursive through GroupItem constructors).
        /// </summary>
        /// <param name="inXsdNode"> The given item's XmlNode to create it's children. </param>
        /// <param name="parent"> The parent of the given item's XmlNode. </param>
        /// <param name="isFunction"> Keep track of function items. </param>
        /// <returns></returns>
        public static List<Item> CreateChildren(XmlNode inXsdNode, GroupItem parent, bool isFunction)
        {
            List<Item> list = null;

            // Check.
            if (!inXsdNode.HasChildNodes) return null;

            list = new List<Item>(inXsdNode.ChildNodes.Count);

            foreach (XmlNode x in inXsdNode.ChildNodes)
            {
                switch (x.LocalName)
                {
                    case "element":
                        if (IsElementItem(x))
                            list.Add(new ElementItem(x, parent, isFunction));
                        else
                            list.Add(new GroupItem(x, parent, isFunction));
                        break;
                    case "complexType":     // CHECK: Hardcoded XSD sequence.
                        foreach (XmlNode xc in x.ChildNodes)
                        {
                            if (xc.LocalName == "element")
                                if (IsElementItem(xc))
                                    list.Add(new ElementItem(xc, parent, isFunction));
                                else
                                    list.Add(new GroupItem(xc, parent, isFunction));
                            else if (xc.LocalName == "sequence" || xc.LocalName == "all" || xc.LocalName == "choice")
                                foreach (XmlNode xcc in xc.ChildNodes)
                                {
                                    if (xcc.LocalName == "element")
                                        if (IsElementItem(xcc))
                                            list.Add(new ElementItem(xcc, parent, isFunction));
                                        else
                                            list.Add(new GroupItem(xcc, parent, isFunction));
                                }
                        }
                        break;
                    case "key":
                        var referenceListName = "";

                        // Check valid syntax.
                        Debug.Assert(x.ChildNodes != null && x.ChildNodes != null,
                            "XML Handling - XSD Parser - CreateChildren - Found a 'key' without child elements.");

                        // Get the referenced item path.
                        foreach (var xc in x.ChildNodes.Cast<XmlElement>().Where(xc => xc.LocalName == "selector"))
                        {
                            Debug.Assert(xc.Attributes != null && xc.Attributes["xpath"] != null,
                            "XML Handling - XSD Parser - CreateChildren - Found a 'key' and child 'selector' without xpath.");
                            referenceListName = xc.Attributes["xpath"].Value.Trim();
                        }

                        // Check valid syntax.
                        Debug.Assert(!string.IsNullOrEmpty(referenceListName),
                            "XML Handling - XSD Parser - CreateChildren - Found a 'key' without a 'selector' child.");

                        // Get the name of the referenced element and create a reference list.
                        referenceListName = referenceListName.Substring(referenceListName.LastIndexOf('/')+1);
                        Structure.Structure.AddReferenceList(referenceListName);
                        break;
                    case "annotation":
                        break;
                    case "keyref":
                        break;
                    default:
                        throw new Exception("Stopped at XSD PARSING...\n Unhandled element: " + x.LocalName);
                }
            }
            return list;
        }
Beispiel #7
0
        // Recursive function that hides/shows the controls of the element viewer.
        private void UpdateElementViewerControls(GroupItem selectedRoot, GroupItem root)
        {
            // Iterate this element's children and show/hide each control.
            foreach (var child in root.Children.Where(child => child.Control != null && child.Control.CurrentControl != null))
            {
                // Recursive call on the group items that have a child with value.
                if (child.IsGroupItem)
                {
                    var item = child as GroupItem;
                    var groupControl = child.Control.CurrentControl as ControlGroup;

                    // Check.
                    if (item == null || groupControl == null) continue;

                    // Recursive function.
                    UpdateElementViewerControls(selectedRoot, item);
                }

                ShowOrHideControl(child, checkBoxTreeShowHidden.Checked, selectedRoot);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Encapsulates the Show or Hide control logic.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="showAll"></param>
        /// <param name="selectedRoot"></param>
        private void ShowOrHideControl(Item item, bool showAll, GroupItem selectedRoot)
        {
            var show = false;

            // Show the Element if it has a value or show all option is enabled.
            if ((item.IsElementItem) && (selectedRoot.InnerChildren.Contains(item) ||
                selectedRoot == item))
            {
                if (item.IsRequired || (showAll || item.Control.HasNewValue))
                    show = true;
            }
            // Show the Group if it has any children Element and that child has a value or show all option is enabled.
            else if ((item.IsGroupItem) && (selectedRoot.InnerChildren.Contains(item) ||
                selectedRoot == item || ((GroupItem)item).InnerChildren.Contains(selectedRoot)))
            {
                var groupItem = (GroupItem)item;
                var groupControl = ((ControlGroup)groupItem.Control.CurrentControl);

                if (groupControl.HasChildrenOfElementItem() && (groupControl.IsRequired ||
                    (showAll || groupControl.HasNewValue())))
                    show = true;
            }

            if (show) item.Control.CurrentControl.Show();
            else item.Control.CurrentControl.Hide();
        }
Beispiel #9
0
        // Recursive function that populates the element viewer with the appropriate elements.
        private void PopulateElementViewer(GroupItem root, Control parent)
        {
            foreach (var child in root.Children)
            {
                // Check for Controls.
                if (child.Control == null || child.Control.CurrentControl == null) continue;

                // Do ElementItem specific actions.
                if (child.IsElementItem)
                {
                    var item = child as ElementItem;

                    // Check.
                    if (item == null) continue;

                    // Add reference options in the reference controls (must be done after the XML is read)
                    if (item.Control.CurrentControl is ControlReference)
                    {
                        var options = Structure.Structure.FindReferenceListOptions(item.Name);
                        (item.Control.CurrentControl as ControlReference).SetOptions(options);
                    }
                }

                // Append the item's Control in the Element Viewer.
                // Append the GroupItem's Control too, to allow a better view
                // of the elements' position in the hierarchy in the Element Viewer.
                parent.Controls.Add(child.Control.CurrentControl);

                // Do GroupItem specific actions.
                if (child.IsGroupItem)
                {
                    var item = child as GroupItem;
                    var groupControl = child.Control.CurrentControl as ControlGroup;

                    // Check.
                    if (item == null || groupControl == null) continue;

                    // Recursive function.
                    PopulateElementViewer(item, groupControl.GetPanel());
                }

                // If the item is optional (not required) hide it.
                ShowOrHideControl(child, checkBoxTreeShowHidden.Checked, root);
            }
        }
Beispiel #10
0
        public static void SetRoot(GroupItem newRoot)
        {
            StructureRoot = newRoot;

            foreach (var innerChild in newRoot.InnerChildren)
            {
                Add(innerChild);
            }
        }