/// <summary> /// Accepts a drop event /// </summary> /// <param name="sourceNode"></param> public override void AcceptDrop(BaseTreeNode sourceNode) { base.AcceptDrop(sourceNode); if (sourceNode is ParagraphTreeNode) { ParagraphTreeNode paragraph = sourceNode as ParagraphTreeNode; Item.Name = paragraph.Item.FullId; RefreshNode(); } }
/// <summary> /// Accepts a drop event /// </summary> /// <param name="SourceNode"></param> public override void AcceptDrop(BaseTreeNode SourceNode) { base.AcceptDrop(SourceNode); if (SourceNode is SpecificationView.ParagraphTreeNode) { SpecificationView.ParagraphTreeNode paragraph = SourceNode as SpecificationView.ParagraphTreeNode; Item.Name = paragraph.Item.FullId; RefreshNode(); } }
/// <summary> /// Handles a drop event /// </summary> /// <param name="SourceNode"></param> public override void AcceptDrop(BaseTreeNode SourceNode) { if (SourceNode is SpecificationView.ParagraphTreeNode) { SpecificationView.ParagraphTreeNode paragraphTreeNode = (SpecificationView.ParagraphTreeNode)SourceNode; CreateReqRef(paragraphTreeNode.Item.FullId); } else if (SourceNode is ReqRefTreeNode) { ReqRefTreeNode reqRefTreeNode = (ReqRefTreeNode)SourceNode; CreateReqRef(reqRefTreeNode.Item.Paragraph.FullId); } }
/// <summary> /// Handles a double click event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void DoubleClickHandler(object sender, EventArgs e) { MouseEventArgs args = e as MouseEventArgs; if (args != null) { Selected = GetNodeAt(new Point(args.X, args.Y)) as BaseTreeNode; } if (Selected != null) { Selected.DoubleClickHandler(); } }
/// <summary> /// Provides the node which corresponds to the model element provided /// </summary> /// <param name="model"></param> /// <param name="buildSubNodes"></param> /// <returns></returns> public BaseTreeNode FindNode(IModelElement model, bool buildSubNodes) { BaseTreeNode retVal = null; foreach (BaseTreeNode node in Nodes) { retVal = InnerFindNode(node, model, buildSubNodes); if (retVal != null) { break; } } return(retVal); }
/// <summary> /// Called when the drop operation is performed on this text box /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void DragDropHandler(object sender, DragEventArgs e) { if (e.Data.GetDataPresent("WindowsForms10PersistentObject", false)) { BaseTreeNode SourceNode = (BaseTreeNode)e.Data.GetData("WindowsForms10PersistentObject"); if (SourceNode != null) { BaseTreeNode node = EnclosingForm.TreeView.Selected; if (node != null) { node.AcceptDrop(SourceNode); } } } }
/// <summary> /// Provides the node which corresponds to the model element provided /// </summary> /// <param name="model"></param> /// <returns></returns> public BaseTreeNode FindNode(Utils.IModelElement model) { BaseTreeNode retVal = null; foreach (BaseTreeNode node in Nodes) { retVal = InnerFindNode(node, model); if (retVal != null) { break; } } return(retVal); }
/// <summary> /// Selects the next node whose error level corresponds to the levelEnum provided /// </summary> /// <param name="current">the model element that is currently displayed</param> /// <param name="node">the node from which the selection process must begin</param> /// <param name="levelEnum"></param> /// <param name="considerThisOne">Indicates that the current node should be considered by the search</param> /// <returns>The node which corresponds to the search criteria, null otherwise</returns> private BaseTreeNode RecursivelySelectNext(IModelElement current, BaseTreeNode node, ElementLog.LevelEnum levelEnum, bool considerThisOne) { BaseTreeNode retVal = null; if (current != null) { IModelElement model = node.Model; if (considerThisOne && (node.Parent == null || node.Model != ((BaseTreeNode)node.Parent).Model)) { if (levelEnum == ElementLog.LevelEnum.Error && (model.MessagePathInfo & MessageInfoEnum.Error) != 0) { retVal = node; } else if (levelEnum == ElementLog.LevelEnum.Warning && (model.MessagePathInfo & MessageInfoEnum.Warning) != 0) { retVal = node; } else if (levelEnum == ElementLog.LevelEnum.Info && (model.MessagePathInfo & MessageInfoEnum.Info) != 0) { retVal = node; } } if (retVal == null) { if (levelEnum == ElementLog.LevelEnum.Error && (model.MessagePathInfo & MessageInfoEnum.PathToError) != 0) { retVal = InnerSelectNext(current, node, levelEnum); } else if (levelEnum == ElementLog.LevelEnum.Warning && (model.MessagePathInfo & MessageInfoEnum.PathToWarning) != 0) { retVal = InnerSelectNext(current, node, levelEnum); } else if (levelEnum == ElementLog.LevelEnum.Info && (model.MessagePathInfo & MessageInfoEnum.PathToInfo) != 0) { retVal = InnerSelectNext(current, node, levelEnum); } } } return(retVal); }
/// <summary> /// Handles a drop event /// </summary> /// <param name="sourceNode"></param> public override void AcceptDrop(BaseTreeNode sourceNode) { ParagraphTreeNode paragraphTreeNode = sourceNode as ParagraphTreeNode; if (paragraphTreeNode != null) { Item.FindOrCreateReqRef(paragraphTreeNode.Item); } else { ReqRefTreeNode reqRefTreeNode = sourceNode as ReqRefTreeNode; if (reqRefTreeNode != null) { Item.FindOrCreateReqRef(reqRefTreeNode.Item.Paragraph); } } }
/// <summary> /// Allows to refresh the view, when the information message changed /// </summary> /// <param name="modelElement"></param> /// <returns>True if the view should be refreshed</returns> public virtual bool HandleInfoMessageChange(IModelElement modelElement) { bool retVal = ShouldUpdateColoring(modelElement); if (retVal) { if (modelElement != null) { // Find the first displayed tree node to be colorized BaseTreeNode displayedNode = null; while (displayedNode == null && modelElement != null) { displayedNode = TreeView.FindNode(modelElement, false); modelElement = modelElement.Enclosing as IModelElement; } if (displayedNode != null) { while (displayedNode != null) { bool changed = displayedNode.UpdateColor(); if (changed) { displayedNode = displayedNode.Parent as BaseTreeNode; } else { displayedNode = null; } } } } else { // When no model element is provided, the complete tree should be recolored foreach (BaseTreeNode node in TreeView.Nodes) { node.RecursiveUpdateNodeColor(); } } } return(retVal); }
/// <summary> /// Called when the drop operation is performed on this text box /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void DragDropHandler(object sender, DragEventArgs e) { if (e.Data.GetDataPresent("WindowsForms10PersistentObject", false)) { BaseTreeNode SourceNode = (BaseTreeNode)e.Data.GetData("WindowsForms10PersistentObject"); if (SourceNode != null) { DataDictionaryView.VariableTreeNode variableNode = SourceNode as DataDictionaryView.VariableTreeNode; if (variableNode != null) { StringBuilder text = new StringBuilder(); text.Append(StripUseless(SourceNode.Model.FullName, EnclosingForm.Selected) + " <- "); DataDictionary.Variables.Variable variable = variableNode.Item; DataDictionary.Types.Structure structure = variable.Type as DataDictionary.Types.Structure; if (structure != null) { text.Append(StripUseless(structure.FullName, EnclosingForm.Selected) + "{\n"); bool first = true; foreach (DataDictionary.Types.StructureElement element in structure.Elements) { if (!first) { text.Append(",\n"); } insertElement(element, text, 4); first = false; } text.Append("}\n"); } else { text.Append(variable.DefaultValue.FullName); } SelectedText = text.ToString(); } else { SelectedText = StripUseless(SourceNode.Model.FullName, EnclosingForm.Selected); } } } }
/// <summary> /// Selects the node which references the element provided /// </summary> /// <param name="element"></param> /// <param name="getFocus">Indicates whether the focus should be given to the enclosing form</param> /// <returns>the selected node</returns> public BaseTreeNode Select(Utils.IModelElement element, bool getFocus = false) { BaseTreeNode retVal = null; retVal = FindNode(element); if (retVal != null) { Selected = retVal; if (getFocus) { Form form = GUIUtils.EnclosingFinder <Form> .find(this); form.BringToFront(); } } return(retVal); }
/// <summary> /// Handles a drop event /// </summary> /// <param name="SourceNode"></param> public override void AcceptDrop(BaseTreeNode SourceNode) { base.AcceptDrop(SourceNode); if (SourceNode is SpecificationView.ParagraphTreeNode) { if (HandleRequirements && ReqReferences == null) { ReqReferences = new ReqRefsTreeNode(Item); Nodes.Add(ReqReferences); } if (ReqReferences != null) { SpecificationView.ParagraphTreeNode paragraphTreeNode = (SpecificationView.ParagraphTreeNode)SourceNode; ReqReferences.CreateReqRef(paragraphTreeNode.Item.FullId); } } }
/// <summary> /// Builds the subnodes if needed, then try to select the next Error/Warning/Info /// </summary> /// <param name="current">the model element that is currently displayed</param> /// <param name="node">the node from which the selection process must begin</param> /// <param name="levelEnum"></param> /// <returns>The node which corresponds to the search criteria, null otherwise</returns> private BaseTreeNode InnerSelectNext(IModelElement current, BaseTreeNode node, ElementLog.LevelEnum levelEnum) { BaseTreeNode retVal = null; if (!node.SubNodesBuilt) { node.BuildOrRefreshSubNodes(null); } foreach (BaseTreeNode subNode in node.Nodes) { retVal = RecursivelySelectNext(current, subNode, levelEnum, true); if (retVal != null) { break; } } return(retVal); }
/// <summary> /// Refreshes the model of the tree view /// </summary> /// <param name="modifiedElement">The element that has been modified</param> public void RefreshModel(IModelElement modifiedElement) { BaseTreeNode selected = Selected; Util.DontNotify(() => { try { SuspendLayout(); // Ensure the root nodes are correct List <BaseTreeNode> rootNodes = BuildModel(); if (rootNodes.Count != Nodes.Count) { Nodes.Clear(); foreach (BaseTreeNode node in rootNodes) { Nodes.Add(node); } } // Refresh the selected node foreach (BaseTreeNode node in Nodes) { if (modifiedElement == null || (node.Model != null && node.Model.IsParent(modifiedElement))) { node.BuildOrRefreshSubNodes(modifiedElement); } } if (selected != null) { Select(selected.Model); } } finally { ResumeLayout(true); } }); }
/// <summary> /// Finds the node which references the element provided /// </summary> /// <param name="node"></param> /// <param name="element"></param> /// <returns></returns> private BaseTreeNode InnerFindNode(BaseTreeNode node, Utils.IModelElement element) { BaseTreeNode retVal = null; if (node.Model == element) { retVal = node; } else { foreach (BaseTreeNode subNode in node.Nodes) { retVal = InnerFindNode(subNode, element); if (retVal != null) { break; } } } return(retVal); }
/// <summary> /// Selects the next node whose error level corresponds to the levelEnum provided /// </summary> /// <param name="levelEnum"></param> public void SelectNext(ElementLog.LevelEnum levelEnum) { BaseTreeNode node = Selected; BaseTreeNode toSelect; if (node != null) { IModelElement current = node.Model; toSelect = RecursivelySelectNext(current, node, levelEnum, false); while (toSelect == null && node != null) { while (node != null && node.NextNode == null) { node = node.Parent as BaseTreeNode; } if (node != null) { node = node.NextNode as BaseTreeNode; toSelect = RecursivelySelectNext(current, node, levelEnum, true); } } } else { toSelect = RecursivelySelectNext(null, Nodes[0] as BaseTreeNode, levelEnum, true); } if (toSelect != null) { EfsSystem.Instance.Context.SelectElement(toSelect.Model, toSelect, Context.SelectionCriteria.DoubleClick); } else { MessageBox.Show( Resources.BaseTreeView_SelectNext_No_more_element_found, Resources.BaseTreeView_SelectNext_End_of_selection); } }
/// <summary> /// Called when the drop operation is performed on a node /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DragDropHandler(object sender, DragEventArgs e) { if (e.Data.GetDataPresent("WindowsForms10PersistentObject", false)) { Point pt = ((TreeView)sender).PointToClient(new Point(e.X, e.Y)); BaseTreeNode destinationNode = (BaseTreeNode)((BaseTreeView)sender).GetNodeAt(pt); object data = e.Data.GetData("WindowsForms10PersistentObject"); BaseTreeNode sourceNode = data as BaseTreeNode; if (sourceNode != null && destinationNode != null) { if ((e.KeyState & Ctrl) != 0) { destinationNode.AcceptCopy(sourceNode); } else if ((e.KeyState & Alt) != 0) { destinationNode.AcceptMove(sourceNode); } else { destinationNode.AcceptDrop(sourceNode); if (Refactor && Settings.Default.AllowRefactor) { NameSpace nameSpace = EnclosingFinder <NameSpace> .find(sourceNode.Model, true); if (nameSpace != null) { // Only apply refactoring when dropping Model Element items // This is useless for Requirements, and test related elements RefactorAndRelocateOperation refactorAndRelocate = new RefactorAndRelocateOperation(sourceNode.Model as ModelElement); refactorAndRelocate.ExecuteUsingProgressDialog(GuiUtils.MdiWindow, "Refactoring", false); } } } } } }
/// <summary> /// Called when the drop operation is performed on a node /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void DragDropHandler(object sender, DragEventArgs e) { if (e.Data.GetDataPresent("WindowsForms10PersistentObject", false)) { Point pt = ((TreeView)sender).PointToClient(new Point(e.X, e.Y)); BaseTreeNode DestinationNode = (BaseTreeNode)((BaseTreeView)sender).GetNodeAt(pt); BaseTreeNode SourceNode = (BaseTreeNode)e.Data.GetData("WindowsForms10PersistentObject"); if (DestinationNode != null) { if ((e.KeyState & CTRL) != 0) { DestinationNode.AcceptCopy(SourceNode); } else if ((e.KeyState & ALT) != 0) { DestinationNode.AcceptMove(SourceNode); } else { DestinationNode.AcceptDrop(SourceNode); } } } }