/// <summary> /// Method will execute when AddRightChildCommand executed /// </summary> /// <param name="param"> /// The param. /// </param> private void AddRightChildCommandExecute(object param) { BrainstormingNodeVM node = this.CreateChild("right"); ((this.SelectedItems as SelectorViewModel).Nodes as ObservableCollection <object>).Clear(); node.IsSelected = true; }
/// <summary> /// Adding xmlelement to xml document based on the child element /// </summary> private void SerializeChild(BrainstormingNodeVM nodeVM, XmlDocument doc, XmlElement id) { String prefix = "bs"; String testNamespace = "http://schemas.microsoft.com/visio/2003/brainstorming"; int i = 1; foreach (IConnector connector in (nodeVM.Info as INodeInfo).OutConnectors) { BrainstormingNodeVM node = connector.TargetNode as BrainstormingNodeVM; XmlElement id1 = doc.CreateElement(prefix, "topic", testNamespace); var attribute1 = doc.CreateAttribute(prefix, "TopicID", testNamespace); attribute1.InnerText = id.Attributes[0].InnerText + "." + i; id1.SetAttributeNode(attribute1); XmlElement name1 = doc.CreateElement(prefix, "text", testNamespace); //name1.InnerText = ((node.Annotations as AnnotationCollection)[0] as TextAnnotationViewModel).Text; ; name1.InnerText = ((node.Annotations as List <IAnnotation>)[0] as LabelVM).Content.ToString(); id1.AppendChild(name1); id.AppendChild(id1); if (node.ChildCount > 0) { SerializeChild(node, doc, id1); } i++; } }
/// <summary> /// The create peer command child. /// </summary> internal void CreatePeerCommandChild() { BrainstormingNodeVM SelectedNode = this.GetFirstSelectedItem(); BrainstormingNodeVM childNode = null; if (!SelectedNode.Type.Equals("root")) { if (SelectedNode.Level == 1) { this.addChildAtLeft = this.addChildAtLeft ? false : true; string type = this.addChildAtLeft ? "left" : "right"; childNode = this.CreateNode(this.Rootnode, type); this.Updatebowtielayout(type); } else { IConnector inEdge = (SelectedNode.Info as INodeInfo).InConnectors.First(); if (inEdge != null) { BrainstormingNodeVM parentNode = inEdge.SourceNode as BrainstormingNodeVM; childNode = this.CreateNode(parentNode, SelectedNode.Type); this.Updatebowtielayout(SelectedNode.Type); } } } if (childNode != null) { ((this.SelectedItems as SelectorViewModel).Nodes as ObservableCollection <object>).Clear(); childNode.IsSelected = true; } }
/// <summary> /// This method will delete the all the child layout for the node /// </summary> /// <param name="SelectedNode"> /// </param> private void DeleteNode(BrainstormingNodeVM SelectedNode) { if ((SelectedNode.Info as INodeInfo).OutNeighbors != null && (SelectedNode.Info as INodeInfo).OutNeighbors.Count() > 0) { for (int i = (SelectedNode.Info as INodeInfo).OutNeighbors.Count() - 1; (SelectedNode.Info as INodeInfo).OutNeighbors.Count() - 1 >= i && i >= 0; i--) { BrainstormingNodeVM c = (SelectedNode.Info as INodeInfo).OutNeighbors.ElementAt(i) as BrainstormingNodeVM; this.DeleteNode(c); } } if ((SelectedNode.Info as INodeInfo).InOutConnectors != null) { for (int i = (SelectedNode.Info as INodeInfo).InOutConnectors.Count() - 1; (SelectedNode.Info as INodeInfo).InOutConnectors.Count() - 1 >= i && i >= 0; i--) { BrainstormingConnectorVM con = (SelectedNode.Info as INodeInfo).InOutConnectors.ElementAt(i) as BrainstormingConnectorVM; (this.Connectors as ObservableCollection <BrainstormingConnectorVM>).Remove(con); } } (this.Nodes as ObservableCollection <BrainstormingNodeVM>).Remove(SelectedNode); }
/// <summary> /// The update quick commands visibility. /// </summary> /// <param name="node"> /// The node. /// </param> private void UpdateQuickCommandsVisibility(BrainstormingNodeVM node) { if (node.Type != null && this.QuickCommands_Delete != null) { // Work around : Quick Command related things. if (node.Type.Equals("root")) { if (node.ChildCount == 0) { this.addChildAtLeft = false; } this.QuickCommands_Delete.VisibilityMode = VisibilityMode.Connector; this.QuickCommands_Left.VisibilityMode = VisibilityMode.Node; this.QuickCommands_Right.VisibilityMode = VisibilityMode.Node; } else if (node.Type.Contains("left")) { this.QuickCommands_Delete.VisibilityMode = VisibilityMode.Node; this.QuickCommands_Delete.Margin = new Thickness(22, 0, 0, 0); this.QuickCommands_Delete.OffsetX = 1; this.QuickCommands_Left.VisibilityMode = VisibilityMode.Node; this.QuickCommands_Right.VisibilityMode = VisibilityMode.Connector; } else if (node.Type.Contains("right")) { this.QuickCommands_Delete.VisibilityMode = VisibilityMode.Node; this.QuickCommands_Delete.Margin = new Thickness(-22, 0, 0, 0); this.QuickCommands_Delete.OffsetX = 0; this.QuickCommands_Left.VisibilityMode = VisibilityMode.Connector; this.QuickCommands_Right.VisibilityMode = VisibilityMode.Node; } } }
/// <summary> /// Adding RootNode /// </summary> /// <returns> /// The <see cref="BrainstormingNodeVM" />. /// </returns> internal BrainstormingNodeVM AddRootNode() { BrainstormingNodeVM n = new BrainstormingNodeVM(); n.Shape = resourceDictionary["Oval"]; n.ShapeName = "Oval"; n.Level = 0; // n.OffsetX = 500; // n.OffsetY = 200; n.UnitWidth = 192; n.UnitHeight = 96; n.Type = "root"; n.Constraints &= ~(NodeConstraints.InheritDraggable | NodeConstraints.InheritResizable | NodeConstraints.InheritRotatable); n.Constraints |= (NodeConstraints.ResizeEast | NodeConstraints.ResizeWest | NodeConstraints.ExcludeFromLayout); ((n.Annotations as List <IAnnotation>)[0] as LabelVM).Content = "Main Topic"; (this.Nodes as ObservableCollection <BrainstormingNodeVM>).Add(n); this.Rootnode = n; // Rootnode.IsSelected = true; // AddContextMenutoNode(Rootnode); return(n); }
/// <summary> /// Adding new element when execute Import command /// </summary> /// <param name="SelectedNode"> /// The Selected Node. /// </param> /// <param name="xmlNode"> /// The xml Node. /// </param> private void DeSerializeChild(BrainstormingNodeVM SelectedNode, XmlNode xmlNode) { BrainstormingNodeVM newParentNode = null; // SubTopicCommand.Execute(subtopic); foreach (XmlNode att in xmlNode.ChildNodes) { if (att.LocalName.Equals("text")) { this.SubTopicCommand.Execute(att.InnerText); ((this.SelectedDiagram.SelectedItems as SelectorViewModel).Nodes as ObservableCollection <object>) .Clear(); newParentNode = (this.SelectedDiagram.Nodes as ObservableCollection <BrainstormingNodeVM>).Last(); BrainstormingNodeVM parentNode = (newParentNode.Info as INodeInfo).InNeighbors.First() as BrainstormingNodeVM; parentNode.IsSelected = true; } if (att.LocalName.Equals("topic")) { ((this.SelectedDiagram.SelectedItems as SelectorViewModel).Nodes as ObservableCollection <object>) .Clear(); newParentNode.IsSelected = true; this.DeSerializeChild(newParentNode, att); } } }
/// <summary> /// This mehtod will create new child and connect it to related parent /// </summary> /// <param name="ptype"> /// </param> /// <returns> /// The <see cref="BrainstormingNodeVM"/>. /// </returns> private BrainstormingNodeVM CreateChild(string ptype = null) { BrainstormingNodeVM n = null; if ((this.SelectedItems as SelectorViewModel).Nodes != null) { BrainstormingNodeVM SelectedNode = this.GetFirstSelectedItem(); if (SelectedNode is BrainstormingNodeVM) { if (SelectedNode.Type.Equals("root")) { n = this.CreateNode(SelectedNode, ptype); } else { if (SelectedNode.Type.Equals("right") || SelectedNode.Type.Equals("subright")) { n = this.CreateNode(SelectedNode, "subright"); ptype = "right"; } else { n = this.CreateNode(SelectedNode, "subleft"); ptype = "left"; } } } this.Updatebowtielayout(ptype); } return(n); }
/// <summary> /// Adding Content Menu to Node /// </summary> private void AddContextMenutoNode(BrainstormingNodeVM node) { if (node != null) { if (node.Menu == null) { node.Menu = new DiagramMenu(); node.Menu.MenuItems = new ObservableCollection <DiagramMenuItem>(); } DiagramMenuItem mi = new DiagramMenuItem() { Content = "Add Subtopic", Command = SubTopicCommand }; DiagramMenuItem mi1 = new DiagramMenuItem() { Content = "Add Peer Topic", Command = PeerCommand }; DiagramMenuItem mi2 = new DiagramMenuItem() { Content = "Add Multiple Subtopics", Command = MultipleSubTopicCommand }; DiagramMenuItem mi3 = new DiagramMenuItem() { Content = "Change Topic Shapes", Command = ChangeTopicCommand }; (node.Menu.MenuItems as ICollection <DiagramMenuItem>).Add(mi); if (node != (SelectedDiagram as Brainstorming.ViewModel.BrainstormingVM).Rootnode) { (node.Menu.MenuItems as ICollection <DiagramMenuItem>).Add(mi1); } (node.Menu.MenuItems as ICollection <DiagramMenuItem>).Add(mi2); (node.Menu.MenuItems as ICollection <DiagramMenuItem>).Add(mi3); DiagramMenuItem mi4 = new DiagramMenuItem() { Content = "Edit Text", Command = (SelectedDiagram as BrainstormingVM).EditText }; DiagramMenuItem mi5 = new DiagramMenuItem() { Content = "Delete", Command = (SelectedDiagram as BrainstormingVM).ItemDeletingCommand }; (node.Menu.MenuItems as ICollection <DiagramMenuItem>).Add(mi4); if (node != (SelectedDiagram as BrainstormingVM).Rootnode) { (node.Menu.MenuItems as ICollection <DiagramMenuItem>).Add(mi5); } node.Constraints = node.Constraints | NodeConstraints.Menu; node.Constraints = node.Constraints & ~NodeConstraints.InheritMenu; } }
/// <summary> /// The connect. /// </summary> /// <param name="SelectedNode"> /// The selected node. /// </param> /// <param name="n"> /// The n. /// </param> /// <returns> /// The <see cref="BrainstormingConnectorVM"/>. /// </returns> private BrainstormingConnectorVM Connect(BrainstormingNodeVM SelectedNode, BrainstormingNodeVM n) { BrainstormingConnectorVM conn = new BrainstormingConnectorVM(); (this.Connectors as ObservableCollection <BrainstormingConnectorVM>).Add(conn); conn.SourceNode = SelectedNode; conn.TargetNode = n; return(conn); }
/// <summary> /// The node changed command execute. /// </summary> /// <param name="param"> /// The param. /// </param> private void NodeChangedCommandExecute(object param) { ChangeEventArgs <object, NodeChangedEventArgs> args = param as ChangeEventArgs <object, NodeChangedEventArgs>; if (args.NewValue.InteractionState == NodeChangedInteractionState.Resized) { BrainstormingNodeVM node = args.Item as BrainstormingNodeVM; this.Updatebowtielayout(node.Type); } }
/// <summary> /// Method will execute when ItemSelectedCommand executed /// </summary> /// <param name="param"> /// </param> private void ItemSelectedCommandExecute(object param) { DiagramEventArgs args = param as DiagramEventArgs; if (args.Item is BrainstormingNodeVM) { BrainstormingNodeVM node = args.Item as BrainstormingNodeVM; this.UpdateQuickCommandsVisibility(this.Rootnode.IsSelected ? this.Rootnode : node); } }
/// <summary> /// The edit text execute. /// </summary> /// <param name="param"> /// The param. /// </param> private void EditTextExecute(object param) { BrainstormingNodeVM SelectedNode = this.GetFirstSelectedItem(); if (SelectedNode != null) { IAnnotation annotation = (SelectedNode.Annotations as List <IAnnotation>).First(); annotation.Mode = ContentEditorMode.Edit; } }
/// <summary> /// Method will execute when PeerCommand executed /// </summary> private void PeerCommandExecute(object param) { BrainstormingNodeVM SelectedNode = (SelectedDiagram as Brainstorming.ViewModel.BrainstormingVM).GetFirstSelectedItem(); if (SelectedNode == null) { OpenCloseWindowBehavior.OpenMessageBoxWindow = true; } else { (SelectedDiagram as Brainstorming.ViewModel.BrainstormingVM).CreatePeerCommandChild(); } }
/// <summary> /// Method will execute when MultipleSubTopicCommand executed /// </summary> private void MultipleSubTopicCommandExecute(object param) { BrainstormingNodeVM SelectedNode = (SelectedDiagram as Brainstorming.ViewModel.BrainstormingVM).GetFirstSelectedItem(); if (SelectedNode == null) { OpenCloseWindowBehavior.OpenMessageBoxWindow = true; } else { OpenCloseWindowBehavior.OpenMultipleSubTopicWindow = true; } }
/// <summary> /// Method will execute when SubTopicCommand executed /// </summary> /// <param name="param"> /// The param. /// </param> private void SubTopicCommandExecute(object param) { BrainstormingNodeVM SelectedNode = (this.SelectedDiagram as BrainstormingVM).GetFirstSelectedItem(); if (SelectedNode == null) { this.OpenCloseWindowBehavior.OpenMessageBoxWindow = true; } else { (this.SelectedDiagram as BrainstormingVM).CreateSubTopicCommandChild(param); } }
/// <summary> /// The expand collapse command execute. /// </summary> /// <param name="param"> /// The param. /// </param> private void ExpandCollapseCommandExecute(object param) { BrainstormingNodeVM selectedNode = this.GetFirstSelectedItem(); // selectedNode.IsExpanded = selectedNode.IsExpanded ? false : true; // Updatebowtielayout(selectedNode.Type); ExpandCollapseParameter parameter = new ExpandCollapseParameter { Node = selectedNode, IsUpdateLayout = true }; (this.Info as IGraphInfo).Commands.ExpandCollapse.Execute(parameter); }
/// <summary> /// Adding child elements when executing Multiple Subtopics command /// </summary> /// <param name="mulipleSubtopics"></param> internal void AddMultipleSubTopics(string mulipleSubtopics, ICommand SubTopicCommand) { List <string> subtopics = Regex.Split(mulipleSubtopics, "\r\n|\r|\n").ToList(); BrainstormingNodeVM SelectedNode = GetFirstSelectedItem(); foreach (string subtopic in subtopics) { if (!string.IsNullOrEmpty(subtopic)) { CreateSubTopicCommandChild(subtopic, false); } } ((this.SelectedItems as SelectorViewModel).Nodes as ObservableCollection <object>).Clear(); BrainstormingNodeVM lastnewNode = (this.Nodes as ObservableCollection <BrainstormingNodeVM>).Last() as BrainstormingNodeVM; lastnewNode.IsSelected = true; }
/// <summary> /// Method will execute when ItemDeletedCommand executed /// </summary> /// <param name="param"> /// </param> private void ItemDeletedCommandExecute(object param) { ItemDeletedEventArgs args = param as ItemDeletedEventArgs; if (args.Item is BrainstormingConnectorVM) { BrainstormingConnectorVM connectorVM = args.Item as BrainstormingConnectorVM; BrainstormingNodeVM sourceNode = connectorVM.SourceNode as BrainstormingNodeVM; if (sourceNode != null) { sourceNode.ChildCount--; } } else if (args.Item is BrainstormingNodeVM && args.Item != this.Rootnode) { this.Updatebowtielayout((args.Item as BrainstormingNodeVM).Type); } }
/// <summary> /// Method will execute when DeleteChildCommand executed /// </summary> private void DeleteChildCommandExecute(object param) { for (int i = 0; i < ((this.SelectedItems as SelectorViewModel).Nodes as ObservableCollection <object>).Count();) { BrainstormingNodeVM selectedNode = ((this.SelectedItems as SelectorViewModel).Nodes as ObservableCollection <object>)[i] as BrainstormingNodeVM; if (selectedNode != Rootnode) { DeleteNode(selectedNode); Updatebowtielayout(selectedNode.Type); } else { i++; } } if (Rootnode.IsSelected) { UpdateQuickCommandsVisibility(Rootnode); } }
/// <summary> /// The create sub topic command child. /// </summary> /// <param name="param"> /// The param. /// </param> /// <param name="selectNewNode"> /// The select new node. /// </param> internal void CreateSubTopicCommandChild(object param, bool selectNewNode = true) { BrainstormingNodeVM SelectedNode = this.GetFirstSelectedItem(); BrainstormingNodeVM n; if (SelectedNode.Type.Equals("root")) { if (SelectedNode.ChildCount == 0) { this.addChildAtLeft = false; } else { this.addChildAtLeft = this.addChildAtLeft ? false : true; } string type = this.addChildAtLeft ? "left" : "right"; n = this.CreateChild(type); if (param != null && !(param is IGestureParameter)) { ((n.Annotations as List <IAnnotation>)[0] as LabelVM).Content = param.ToString(); } } else { n = this.CreateChild(); if (param != null && !(param is IGestureParameter)) { ((n.Annotations as List <IAnnotation>)[0] as LabelVM).Content = param.ToString(); } } if (selectNewNode) { ((this.SelectedItems as SelectorViewModel).Nodes as ObservableCollection <object>).Clear(); n.IsSelected = true; } }
/// <summary> /// Method will execute when ItemDeletingCommand executed /// </summary> /// <param name="param"> /// </param> private void ItemDeletingCommandExecute(object param) { ItemDeletingEventArgs args = param as ItemDeletingEventArgs; if (args != null) { if (args.Item is BrainstormingNodeVM) { if (args.Item == this.Rootnode) { args.Cancel = true; } else { this.DeleteNode(args.Item as BrainstormingNodeVM); } } } else { BrainstormingNodeVM SelectedNode = this.GetFirstSelectedItem(); this.DeleteNode(SelectedNode); } }
/// <summary> /// This mehtod will create new child and connect it to related parent /// </summary> /// <param name="SelectedNode"> /// The Selected Node. /// </param> /// <param name="type"> /// The type. /// </param> /// <returns> /// The <see cref="BrainstormingNodeVM"/>. /// </returns> private BrainstormingNodeVM CreateNode(BrainstormingNodeVM SelectedNode, string type) { if (!SelectedNode.IsExpanded) { this.ExecuteExpandCollapseCommand(SelectedNode); } BrainstormingNodeVM n = new BrainstormingNodeVM(); n.UnitWidth = 120; n.UnitHeight = 30; n.Type = type; n.Constraints &= ~(NodeConstraints.InheritDraggable | NodeConstraints.InheritResizable | NodeConstraints.InheritRotatable); if (type.Contains("right")) { n.Constraints |= NodeConstraints.ResizeEast; } else if (type.Contains("left")) { n.Constraints |= NodeConstraints.ResizeWest; } // AddAnnotation(n); ((n.Annotations as List <IAnnotation>)[0] as LabelVM).Content = "New Topic"; (this.Nodes as ObservableCollection <BrainstormingNodeVM>).Add(n); if (SelectedNode != null) { this.Connect(SelectedNode, n); SelectedNode.ChildCount++; n.Level = SelectedNode.Level + 1; } // AddContextMenutoNode(n); n.Ports = new ObservableCollection <IPort> { new NodePortVM { NodeOffsetX = 0, NodeOffsetY = 1, Displacement = new Thickness(0, -8, 0, 0) }, new NodePortVM { NodeOffsetX = 0, NodeOffsetY = 0.4 }, new NodePortVM { NodeOffsetX = 1, NodeOffsetY = 0.05 }, new NodePortVM { NodeOffsetX = 1, NodeOffsetY = 1, Displacement = new Thickness(0, -8, 0, 0) } }; if (n.Level < 4) { n.ShapeName = this.LevelStyles[n.Level].Item1; n.ThemeStyleId = this.LevelStyles[n.Level].Item2; } else { n.ShapeName = this.LevelStyles[3].Item1; n.ThemeStyleId = this.LevelStyles[3].Item2; } return(n); }