/// <summary> /// Creates a Link object and connects the tail port and head /// port of the link. /// </summary> /// <param name="cmdTarget">Parent node to add the link to</param> /// <returns>true if successful, otherwise false</returns> /// <remarks> /// If the <see cref="Syncfusion.Windows.Forms.Diagram.LinkCmd.Link"/> /// property is null when this method is called, then a new Link object /// is created by invoking the /// <see cref="Syncfusion.Windows.Forms.Diagram.LinkCmd.LinkFactory"/> /// delegate. The Link object is then added to the node passed in the /// cmdTarget parameter. Next, the tail of the link is connected to the /// <see cref="Syncfusion.Windows.Forms.Diagram.LinkCmd.SourcePort"/> /// and the head of the link is connected to the /// <see cref="Syncfusion.Windows.Forms.Diagram.LinkCmd.TargetPort"/>. /// <seealso cref="Syncfusion.Windows.Forms.Diagram.LinkCmd.LinkFactory"/> /// </remarks> public bool Do(object cmdTarget) { bool success = false; ICompositeNode parentNode = null; int childIdx; if (this.link == null) { this.link = this.linkFactory(this.points); } if (this.link != null) { parentNode = cmdTarget as ICompositeNode; if (parentNode != null) { childIdx = parentNode.AppendChild(this.link); if (this.sourcePort != null) { this.link.ConnectTail(this.sourcePort); } if (this.targetPort != null) { this.link.ConnectHead(this.targetPort); } success = true; } } return(success); }
/// <summary> /// /// </summary> /// <param name="cmdTarget"></param> /// <returns></returns> public override bool Do(object cmdTarget) { bool success = false; ICompositeNode parentNode = cmdTarget as ICompositeNode; if (parentNode != null) { foreach (INode curNode in this.Nodes) { int childIdx = parentNode.GetChildIndex(curNode); int newIdx; int childCount; if (childIdx >= 0) { parentNode.RemoveChild(childIdx); } switch (this.updType) { case ZOrderUpdate.Front: parentNode.AppendChild(curNode); break; case ZOrderUpdate.Back: parentNode.InsertChild(curNode, 0); break; case ZOrderUpdate.Forward: childCount = parentNode.ChildCount; newIdx = (childIdx < childCount) ? (childIdx + 1) : (childCount); parentNode.InsertChild(curNode, newIdx); break; case ZOrderUpdate.Backward: newIdx = (childIdx > 0) ? (childIdx - 1) : (0); parentNode.InsertChild(curNode, newIdx); break; } } } return(success); }
/// <summary> /// /// </summary> /// <param name="cmdTarget"></param> /// <returns></returns> public override bool Do(object cmdTarget) { bool success = false; ICompositeNode parentNode = null; Group curGroup; ICompositeNode curParent; int childIdx; int newIdx; INode curChild; parentNode = cmdTarget as ICompositeNode; if (parentNode != null) { IEnumerator nodeEnum = this.Nodes.GetEnumerator(); while (nodeEnum.MoveNext()) { curGroup = nodeEnum.Current as Group; if (curGroup != null) { curParent = curGroup.Parent; if (curParent != null) { childIdx = curParent.GetChildIndex(curGroup); if (childIdx >= 0) { curParent.RemoveChild(childIdx); } } for (childIdx = 0; childIdx < curGroup.ChildCount; childIdx++) { curChild = curGroup.GetChild(childIdx); newIdx = parentNode.AppendChild(curChild); } } } success = true; } return(success); }
/// <summary> /// Destroys the group created by executing the command and restores /// the nodes to their original parent. /// </summary> /// <returns>true if successful, otherwise false</returns> public override bool Undo() { bool success = false; if (this.group != null && this.groupParent != null) { NodeCollection groupMembers = new NodeCollection(); for (int childIdx = 0; childIdx < this.group.ChildCount; childIdx++) { INode curChild = this.group.GetChild(childIdx); if (curChild != null) { groupMembers.Add(curChild); } } int groupChildIdx = this.groupParent.GetChildIndex(this.group); if (groupChildIdx >= 0) { this.groupParent.RemoveChild(groupChildIdx); } this.group.RemoveAllChildren(); this.group = null; foreach (INode curChild in groupMembers) { ICompositeNode curParent = null; if (this.parentMap.Contains(curChild)) { curParent = (ICompositeNode)this.parentMap[curChild]; curParent.AppendChild(curChild); } } success = true; } return(success); }