//TODO: FIXME - This method is a royal mess!
        public override bool Visit(ElementWalker walker, ModelElement modelElement)
        {
            var result = base.Visit(walker, modelElement);

            if (walker.InternalElementList.Last() == modelElement)
            {
                var typesNode = this.treeView.Nodes[0].Nodes[0];
                typesNode.Text = "Models";
                foreach (ModelElementTreeNode classNode in typesNode.Nodes)
                {
                    var originalNodes = classNode.Nodes.OfType <RoleGroupTreeNode>().ToArray();
                    foreach (RoleGroupTreeNode roleGroupNode in originalNodes)
                    {
                        var toRemove = new List <ModelElementTreeNode>();
                        foreach (ModelElementTreeNode propNode in roleGroupNode.Nodes)
                        {
                            toRemove.Add(propNode);
                        }

                        foreach (var node in toRemove)
                        {
                            roleGroupNode.Nodes.Remove(node);
                            this.TreeContainer.InsertTreeNode(classNode.Nodes, node);
                        }
                    }
                    foreach (TreeNode node in originalNodes)
                    {
                        classNode.Nodes.Remove(node);
                    }
                }
                typesNode.Expand();
            }
            return(result);
        }
        public void TestWalkProperties()
        {
            Kml kml = new Kml();
            kml.Feature = new Folder(); // This will not be added to the Children collection

            Assert.That(ElementWalker.Walk(kml).Count(), Is.EqualTo(2));
        }
        //TODO: FIXME - This method is a royal mess! 
        public override  bool Visit(ElementWalker walker, ModelElement modelElement)
        {
            var result = base.Visit(walker, modelElement);
            if (walker.InternalElementList.Last() == modelElement)
            {
                var typesNode = this.treeView.Nodes[0].Nodes[0];
                typesNode.Text = "Models";
                foreach (ModelElementTreeNode classNode in typesNode.Nodes)
                {
                    var originalNodes = classNode.Nodes.OfType<RoleGroupTreeNode>().ToArray();
                    foreach (RoleGroupTreeNode roleGroupNode in originalNodes)
                    {
                        var toRemove = new List<ModelElementTreeNode>();
                        foreach (ModelElementTreeNode propNode in roleGroupNode.Nodes)
                        {
                            toRemove.Add(propNode);
                        }

                        foreach (var node in toRemove)
                        {
                            roleGroupNode.Nodes.Remove(node);
                            this.TreeContainer.InsertTreeNode(classNode.Nodes, node);
                        }
                    }
                    foreach (TreeNode node in originalNodes) classNode.Nodes.Remove(node);
                }
                typesNode.Expand();
            }
            return result;
        }
 public bool Visit(ElementWalker walker, ModelElement element)
 {
     if (element is T)
     {
         elementList.Add(element);
     }
     return(true);
 }
        /// <summary>
        /// Provides a way to iterate over all children <see cref="Element"/>s
        /// contained by this instance.
        /// </summary>
        /// <param name="element">The class instance.</param>
        /// <returns>An IEnumerable&lt;Element&gt; for specified element.</returns>
        /// <exception cref="ArgumentNullException">element is null.</exception>
        public static IEnumerable <Element> Flatten(this Element element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            return(ElementWalker.Walk(element));
        }
Beispiel #6
0
 /// <summary>
 /// Calls <see cref="MultiShapeUtility.ShouldVisitOnDelete"/> to determine if the relationship should be visited
 /// and to reconfigure any links
 /// </summary>
 /// <param name="walker">The current <see cref="ElementWalker"/></param>
 /// <param name="sourceElement">The <see cref="ModelElement"/> being deleted</param>
 /// <param name="sourceRoleInfo">The role information</param>
 /// <param name="domainRelationshipInfo">The relationship information</param>
 /// <param name="targetRelationship">The other <see cref="ModelElement"/> in the relationship</param>
 /// <returns>Whether to visit the relationship</returns>
 public override VisitorFilterResult ShouldVisitRelationship(ElementWalker walker, ModelElement sourceElement, DomainRoleInfo sourceRoleInfo, DomainRelationshipInfo domainRelationshipInfo, ElementLink targetRelationship)
 {
     if (MultiShapeUtility.ShouldVisitOnDelete(walker, sourceElement, sourceRoleInfo, domainRelationshipInfo, targetRelationship))
     {
         return(base.ShouldVisitRelationship(walker, sourceElement, sourceRoleInfo, domainRelationshipInfo, targetRelationship));
     }
     else
     {
         return(VisitorFilterResult.Never);
     }
 }
Beispiel #7
0
        /// <summary>
        /// Included relative and nested shapes in a default copy closure.
        /// The core design surface model does not do this in VS2010.
        /// </summary>
        public override VisitorFilterResult ShouldVisitRelationship(ElementWalker walker, ModelElement sourceElement, DomainRoleInfo sourceRoleInfo, DomainRelationshipInfo domainRelationshipInfo, ElementLink targetRelationship)
        {
            Guid roleId = sourceRoleInfo.Id;

            if (roleId == ParentShapeHasRelativeChildShapes.ParentShapeDomainRoleId ||
                roleId == ParentShapeContainsNestedChildShapes.ParentShapeDomainRoleId)
            {
                return(VisitorFilterResult.Yes);
            }
            return(base.ShouldVisitRelationship(walker, sourceElement, sourceRoleInfo, domainRelationshipInfo, targetRelationship));
        }
Beispiel #8
0
        /// <summary>
        /// Included relative and nested shapes in a default copy closure.
        /// The core design surface model does not do this in VS2010.
        /// </summary>
        public override VisitorFilterResult ShouldVisitRolePlayer(ElementWalker walker, ModelElement sourceElement, ElementLink elementLink, DomainRoleInfo targetDomainRole, ModelElement targetRolePlayer)
        {
            Guid roleId = targetDomainRole.Id;

            if (roleId == ParentShapeHasRelativeChildShapes.RelativeChildShapesDomainRoleId ||
                roleId == ParentShapeContainsNestedChildShapes.NestedChildShapesDomainRoleId)
            {
                return(VisitorFilterResult.Yes);
            }
            return(base.ShouldVisitRolePlayer(walker, sourceElement, elementLink, targetDomainRole, targetRolePlayer));
        }
        public void TestWalkChildren()
        {
            const int Depth = 50;

            Folder parent = new Folder();
            Folder root = parent;
            for (int i = 0; i < Depth; ++i)
            {
                Folder child = new Folder();
                parent.AddFeature(child); // Added to the Children collection
                parent = child;
            }

            Assert.That(ElementWalker.Walk(root).Count(), Is.EqualTo(Depth + 1)); // Depth + 1 to allow for root itself
        }
Beispiel #10
0
        public virtual VisitorFilterResult ShouldVisitRolePlayer(
            ElementWalker walker,
            ModelElement sourceElement,
            ElementLink elementLink,
            DomainRoleInfo targetDomainRole,
            ModelElement targetRolePlayer)
        {
            Guard.ArgumentNotNull(targetDomainRole, "targetDomainRole");

            if (targetDomainRole.IsEmbedding)
            {
                return(VisitorFilterResult.DoNotCare);
            }

            return(VisitorFilterResult.Yes);
        }
		public virtual VisitorFilterResult ShouldVisitRolePlayer(
			ElementWalker walker, 
			ModelElement sourceElement, 
			ElementLink elementLink, 
			DomainRoleInfo targetDomainRole, 
			ModelElement targetRolePlayer)
		{
			Guard.ArgumentNotNull(targetDomainRole, "targetDomainRole");

			if(targetDomainRole.IsEmbedding)
			{
				return VisitorFilterResult.DoNotCare;
			}

			return VisitorFilterResult.Yes;
		}
Beispiel #12
0
        public void TestWalkCustomElements()
        {
            const int Count = 10;
            CoordinateCollection coordinates = new CoordinateCollection();
            for (int i = 0; i < Count; ++i)
            {
                coordinates.Add(new Vector());
            }
            Assert.That(ElementWalker.Walk(coordinates).Count(), Is.EqualTo(1));

            // This class uses a private class deriving from ICustomElement as a child
            // Make sure it's not included.
            ItemIcon icon = new ItemIcon();
            icon.State = ItemIconStates.Open | ItemIconStates.Error;
            Assert.That(ElementWalker.Walk(icon).Count(), Is.EqualTo(1));
        }
Beispiel #13
0
        /// <summary>
        /// Creates a KmlFie from the specified <see cref="Element"/> hierarchy.
        /// </summary>
        /// <param name="root">The root <c>Element</c> of the file.</param>
        /// <param name="duplicates">
        /// true to allow duplicate <see cref="KmlObject.Id"/> values (newer
        /// values will overwrite existing values); false to throw an exception
        /// for duplicate values.
        /// </param>
        /// <returns>
        /// A new KmlFile with the specified <c>Element</c> as the root.
        /// </returns>
        /// <exception cref="ArgumentNullException">root is null.</exception>
        /// <exception cref="InvalidOperationException">
        /// A object has already been registered with the same Id and the
        /// duplicates argument is set to false.
        /// </exception>
        public static KmlFile Create(Element root, bool duplicates)
        {
            Check.IsNotNull(root, nameof(root));

            var file = new KmlFile
            {
                strict = !duplicates,
            };

            foreach (Element element in ElementWalker.Walk(root))
            {
                file.OnElementAdded(element);
            }

            file.Root = root;
            return(file);
        }
Beispiel #14
0
        /// <summary>
        /// Creates a KmlFie from the specified <see cref="Element"/> hierarchy.
        /// </summary>
        /// <param name="root">The root <c>Element</c> of the file.</param>
        /// <param name="duplicates">
        /// true to allow duplicate <see cref="KmlObject.Id"/> values (newer
        /// values will overwrite existing values); false to throw an exception
        /// for duplicate values.
        /// </param>
        /// <returns>
        /// A new KmlFile with the specified <c>Element</c> as the root.
        /// </returns>
        /// <exception cref="ArgumentNullException">root is null.</exception>
        /// <exception cref="InvalidOperationException">
        /// A object has already been registered with the same Id and the
        /// duplicates argument is set to false.
        /// </exception>
        public static KmlFile Create(Element root, bool duplicates)
        {
            if (root == null)
            {
                throw new ArgumentNullException("root");
            }

            KmlFile file = new KmlFile();

            file.strict = !duplicates;

            foreach (var element in ElementWalker.Walk(root))
            {
                file.OnElementAdded(element);
            }

            file.Root = root;
            return(file);
        }
		public virtual VisitorFilterResult ShouldVisitRelationship(
			ElementWalker walker, 
			ModelElement sourceElement, 
			DomainRoleInfo sourceRoleInfo, 
			DomainRelationshipInfo domainRelationshipInfo, 
			ElementLink targetRelationship)
		{
			Guard.ArgumentNotNull(sourceElement, "sourceElement");
			Guard.ArgumentNotNull(domainRelationshipInfo, "domainRelationshipInfo");
			Guard.ArgumentNotNull(targetRelationship, "targetRelationship");

			if(!(sourceElement is ShapeElement))
			{
				foreach(DomainRoleInfo info in domainRelationshipInfo.DomainRoles)
				{
					if(info.GetRolePlayer(targetRelationship) == sourceElement)
					{
						return VisitorFilterResult.Yes;
					}
				}
			}

			return VisitorFilterResult.DoNotCare;
		}
Beispiel #16
0
        public virtual VisitorFilterResult ShouldVisitRelationship(
            ElementWalker walker,
            ModelElement sourceElement,
            DomainRoleInfo sourceRoleInfo,
            DomainRelationshipInfo domainRelationshipInfo,
            ElementLink targetRelationship)
        {
            Guard.ArgumentNotNull(sourceElement, "sourceElement");
            Guard.ArgumentNotNull(domainRelationshipInfo, "domainRelationshipInfo");
            Guard.ArgumentNotNull(targetRelationship, "targetRelationship");

            if (!(sourceElement is ShapeElement))
            {
                foreach (DomainRoleInfo info in domainRelationshipInfo.DomainRoles)
                {
                    if (info.GetRolePlayer(targetRelationship) == sourceElement)
                    {
                        return(VisitorFilterResult.Yes);
                    }
                }
            }

            return(VisitorFilterResult.DoNotCare);
        }
Beispiel #17
0
 /// <summary>
 /// Called when traversal begins.
 /// </summary>
 public void StartTraverse(ElementWalker walker)
 {
 }
Beispiel #18
0
        /// <summary>
        /// Provides a way to iterate over all children <see cref="Element"/>s
        /// contained by this instance.
        /// </summary>
        /// <param name="element">The class instance.</param>
        /// <returns>An IEnumerable&lt;Element&gt; for specified element.</returns>
        /// <exception cref="ArgumentNullException">element is null.</exception>
        public static IEnumerable <Element> Flatten(this Element element)
        {
            Check.IsNotNull(element, nameof(element));

            return(ElementWalker.Walk(element));
        }
Beispiel #19
0
		/// <summary>
		/// Calls <see cref="MultiShapeUtility.ShouldVisitOnDelete"/> to determine if the relationship should be visited
		/// and to reconfigure any links
		/// </summary>
		/// <param name="walker">The current <see cref="ElementWalker"/></param>
		/// <param name="sourceElement">The <see cref="ModelElement"/> being deleted</param>
		/// <param name="sourceRoleInfo">The role information</param>
		/// <param name="domainRelationshipInfo">The relationship information</param>
		/// <param name="targetRelationship">The other <see cref="ModelElement"/> in the relationship</param>
		/// <returns>Whether to visit the relationship</returns>
		public override VisitorFilterResult ShouldVisitRelationship(ElementWalker walker, ModelElement sourceElement, DomainRoleInfo sourceRoleInfo, DomainRelationshipInfo domainRelationshipInfo, ElementLink targetRelationship)
		{
			if (MultiShapeUtility.ShouldVisitOnDelete(walker, sourceElement, sourceRoleInfo, domainRelationshipInfo, targetRelationship))
			{
				return base.ShouldVisitRelationship(walker, sourceElement, sourceRoleInfo, domainRelationshipInfo, targetRelationship);
			}
			else
			{
				return VisitorFilterResult.Never;
			}
		}
Beispiel #20
0
		/// <summary>
		/// Included relative and nested shapes in a default copy closure.
		/// The core design surface model does not do this in VS2010.
		/// </summary>
		public override VisitorFilterResult ShouldVisitRolePlayer(ElementWalker walker, ModelElement sourceElement, ElementLink elementLink, DomainRoleInfo targetDomainRole, ModelElement targetRolePlayer)
		{
			Guid roleId = targetDomainRole.Id;
			if (roleId == ParentShapeHasRelativeChildShapes.RelativeChildShapesDomainRoleId ||
				roleId == ParentShapeContainsNestedChildShapes.NestedChildShapesDomainRoleId)
			{
				return VisitorFilterResult.Yes;
			}
			return base.ShouldVisitRolePlayer(walker, sourceElement, elementLink, targetDomainRole, targetRolePlayer);
		}
Beispiel #21
0
		/// <summary>
		/// Included relative and nested shapes in a default copy closure.
		/// The core design surface model does not do this in VS2010.
		/// </summary>
		public override VisitorFilterResult ShouldVisitRelationship(ElementWalker walker, ModelElement sourceElement, DomainRoleInfo sourceRoleInfo, DomainRelationshipInfo domainRelationshipInfo, ElementLink targetRelationship)
		{
			Guid roleId = sourceRoleInfo.Id;
			if (roleId == ParentShapeHasRelativeChildShapes.ParentShapeDomainRoleId ||
				roleId == ParentShapeContainsNestedChildShapes.ParentShapeDomainRoleId)
			{
				return VisitorFilterResult.Yes;
			}
			return base.ShouldVisitRelationship(walker, sourceElement, sourceRoleInfo, domainRelationshipInfo, targetRelationship);
		}
		/// <summary>
		/// Called when traversal begins. 
		/// </summary>
		public void StartTraverse(ElementWalker walker) { }
		/// <summary>
		/// Called when traversal ends. 
		/// </summary>
		public void EndTraverse(ElementWalker walker) { }
		/// <summary>
		/// Called for each element in the traversal.
		/// </summary>
		public bool Visit(ElementWalker walker, ModelElement element)
		{
			this.elementList.Add(element);
			return true;
		}
Beispiel #25
0
 /// <summary>
 /// Called when traversal ends.
 /// </summary>
 public void EndTraverse(ElementWalker walker)
 {
 }
Beispiel #26
0
 /// <summary>
 /// Called for each element in the traversal.
 /// </summary>
 public bool Visit(ElementWalker walker, ModelElement element)
 {
     this.elementList.Add(element);
     return(true);
 }