void CreateDefaultPages() { IDocumentService doc = ServiceLocator.Current.GetInstance <IDocumentService>(); if (doc.Document == null) { doc.NewDocument(DocumentType.Standard); } RootNode.UpdateDocument(doc.Document); if (doc.Document.DocumentType == DocumentType.Library) { INodeViewModel defaultNode = RootNode.Add(GetNextDataName(TreeNodeType.Page)); _ListEventAggregator.GetEvent <OpenNormalPageEvent>().Publish(defaultNode.Guid); defaultNode.IsSelected = true; } else { INodeViewModel homeNode = RootNode.Add("Home"); _ListEventAggregator.GetEvent <OpenNormalPageEvent>().Publish(homeNode.Guid); homeNode.IsSelected = true; homeNode.AddChild(GetNextDataName(TreeNodeType.Page)); homeNode.AddChild(GetNextDataName(TreeNodeType.Page)); homeNode.AddChild(GetNextDataName(TreeNodeType.Page)); } doc.Document.IsDirty = false; }
public static string PrintHierarchy(this INodeViewModel node, int indentation = 0) { var builder = new StringBuilder(); PrintHierarchyInternal(node, 0, builder); return(builder.ToString()); }
public void DuplicateChild(INodeViewModel parent) { if (_document == null) { return; } ITreeNode treeNode = parent.TreeNodeObject.AddChild(NodeType); if (this.NodeType == TreeNodeType.Page) { IDocumentPage sourcePage = this.TreeNodeObject.AttachedObject; IDocumentPage newPage = _document.DuplicatePage(sourcePage.Guid); treeNode.AttachedObject = newPage; _document.AddPage(newPage); } else { treeNode.Name = this.Name; } var idx = IndexInParent; NodeViewModel newNode = new NodeViewModel(_document, _undoManager, treeNode, parent); parent.Children.Insert(idx, newNode); newNode.IsExpanded = true; foreach (var item in Children) { item.DuplicateChild(newNode); } }
private static void PrintHierarchyInternal(INodeViewModel node, int indentation, StringBuilder builder) { PrintIndentation(indentation, builder); builder.Append(node.Name ?? "<untitled>"); if (!node.Index.IsEmpty) { builder.Append("["); builder.Append(node.Index); builder.Append("]"); } builder.Append(": ["); builder.Append(node.Type.Name); builder.Append("] = "); builder.Append(node.Value?.ToString().Replace(Environment.NewLine, " ") ?? "(null)"); if (node.Commands.Any()) { builder.Append("Cmd: "); foreach (var command in node.Commands) { builder.Append("("); builder.Append(((NodeCommandWrapperBase)command).Name); builder.Append(")"); } } builder.AppendLine(); foreach (var child in node.Children) { PrintHierarchyInternal(child, indentation + 4, builder); } }
private static void DisplayStructure(INodeViewModel root, int depth = 0) { Console.Write($"{new string(' ', depth)} {root.GetType().Name} {root.NodeType} {root.Value} "); var vNode = root.As <NodeValidationDecorator>(); if (vNode != null && vNode.ValidationState != null) { var lastColor = Console.ForegroundColor; Console.ForegroundColor = vNode.ValidationState.IsValid ? ConsoleColor.Green : ConsoleColor.Red; Console.Write($"{vNode.ValidationState.IsValid} \"{vNode.ValidationState.Message}\""); Console.ForegroundColor = lastColor; } Console.WriteLine(); foreach (var child in root.Children) { DisplayStructure(child, depth + 1); } }
public INodeViewModel Create(INodeViewModel parent, string nodeType) { var node = _decoratedFactory.Create(parent, nodeType); var result = new NodeIntDecorator(node); return(result); }
public void DragTo(NodeViewModel beDrag, NodeViewModel parent, NodeViewModel previousBrother) { NodeViewModel Node = beDrag; INodeViewModel oldParent = Node.Parent; int oldIndex = Node.IndexInParent; if (parent == null) { parent = RootNode; } var newIndex = 0; if (previousBrother != null) { ///如果前一个同级节点为空,那么index则为0 ///否则进入此处逻辑判断 if (previousBrother == Node) { ///如果要拖动到的前一个同级节点就是自己 ///那么index不改变 newIndex = Node.IndexInParent; } else { ///否则如果拖动到的前一个同级节点和自己在同一个父节点下面 if (previousBrother.Parent == Node.Parent) { if (Node.IndexInParent <= previousBrother.IndexInParent) { newIndex = previousBrother.IndexInParent; } else { newIndex = previousBrother.IndexInParent + 1; } } else { newIndex = previousBrother.IndexInParent + 1; } } } if (parent == oldParent && newIndex == oldIndex) { Debug.WriteLine("not changed"); } else { Node.DragTo(parent, newIndex); PageTreeChanged(); } MovePageCommand cmd = new MovePageCommand(Node, Node.Parent, Node.IndexInParent, oldParent, oldIndex); _undoManager.Push(cmd); }
public DragMessage(INodeViewModel _node, double x, double y) { node = _node; deltaX = x; deltaY = y; //Debug.WriteLine(string.Format("DragMessage Construction @ DX/DY ({0}, {0})", x.ToString(), y.ToString())); }
public IValidationResult Validate(INodeViewModel node, ITreeConductor <INodeViewModel> conductor) { var length = node.Value.Length; return((length >= _min && length <= _max) ? ValidationResult.Valid : new ValidationResult(false, "Value length is not in allowed range")); }
public CreatePageCommand(PageListViewModel pageListVM, INodeViewModel node, INodeViewModel parent, int indexInParent, TreeView tree) { _tree = tree; _pageListVM = pageListVM; _node = node; _parent = parent; _indexInParent = indexInParent; }
public INodeViewModel CreateSection(INodeViewModel parent, NodeType nodeType) { var section = _nodeFactory.Create(parent, nodeType); CreateRowInternal(section, NodeType.DocumentRow); return(section); }
public MovePageCommand(INodeViewModel node, INodeViewModel newParent, int indexInNewParent, INodeViewModel oldParent, int indexInOldParent) { _node = node; _newParent = newParent; _indexInNewParent = indexInNewParent; _oldParent = oldParent; _indexInOldParent = indexInOldParent; }
public void InsertChild(INodeViewModel node, int index) { _treeNodeObject.InsertChild(node.TreeNodeObject, index); AddPage(node); IsExpanded = true; Children.Insert(index, node); RefreshInfoCount(1); }
public INodeViewModel CreateBody(INodeViewModel doc) { var body = _nodeFactory.Create(doc, NodeType.DocumentBody); var drawing = _assemblyDrawingFactory.CreateAssemblyDrawing(body); var section = _sectionFactory.CreateSection(drawing, NodeType.AssemblyUnitSection); _rowFactory.CreateRow(section); return(body); }
public static void AssertHierarchy(this INodeViewModel node) { foreach (var child in node.Children) { if (child.Parent != node) { throw new Exception("Parent/Children mismatch"); } AssertHierarchy(child); } }
//move brother node to child node public void Indent() { var idx = Parent.Children.IndexOf(this); if (idx > 0) { INodeViewModel parentNode = Parent.Children.ElementAt(idx - 1); Move(parentNode, 0); parentNode.IsExpanded = true; } }
private void DaletePageExecute(object cmdParameter) { if ((!GetOperationNode().IsRootNode) && _bVisible) { INodeViewModel Node = NodeInfo.SelectedNode; INodeViewModel parent = Node.Parent; int index = Node.IndexInParent; Node.Remove(); PageTreeChanged(); if (index >= 0) { DeletePageCommand cmd = new DeletePageCommand(this, Node, parent, index, _pageTree); _undoManager.Push(cmd); } } else if (this._isMultiSelected) { var multiSelected = GetAllNodes(RootNode).Where(n => n.IsMultiSelected); if (multiSelected.Count() > 0) { var cmds = new Naver.Compass.InfoStructure.CompositeCommand(); var multiSelectedClone = multiSelected.ToList(); foreach (var node in multiSelectedClone) { var _node = node; var _parent = node.Parent; var _index = node.IndexInParent; if (_index >= 0) { var cmd = new DeletePageCommand(this, _node, _parent, _index, _pageTree); cmds.AddCommand(cmd); } } foreach (var node in multiSelectedClone) { node.Remove(); } PageTreeChanged(); _undoManager.Push(cmds); this.ClearMultiSelected(); } } if (_pageTree != null) { _pageTree.Focus(); } }
public Node(double scale, INodeViewModel viewModel) { //TODO WEAK EVENT HANDLERS this.scale = scale; this.path = new DrawingVisual(); this.DataContext = viewModel; // Seems useless since we do not do databinding this.viewModel = viewModel; this.Loaded += this.OnLoaded; this.Unloaded += this.OnUnloaded; this.InitializeComponent(); }
public IEnumerable <INodeViewModel> GetAllNodes(INodeViewModel root) { foreach (var child in root.Children) { yield return(child); foreach (var subnode in GetAllNodes(child)) { yield return(subnode); } } }
public TreeViewModel_ISOHierarchie_Test() { rootMock = new Mock <ISerializableObject>(); childMock = new Mock <ISerializableObject>(); var childGUID = Guid.NewGuid(); childMock.Setup(c => c.Rowguid).Returns(childGUID); gc1Mock = new Mock <ISerializableObject>(); gc2Mock = new Mock <ISerializableObject>(); rootVMMock = new Mock <IISOViewModel>(); rootVMMock.Setup(v => v.Parent).Returns(() => null); rootVMMock.Setup(v => v.ISO).Returns(rootMock.Object); rootVMMock.Setup(v => v.Name).Returns(rootName); rootVMMock.Setup(v => v.Rowguid).Returns(Guid.NewGuid()); childVMMock = new Mock <IISOViewModel>(); childVMMock.Setup(v => v.Parent).Returns(rootMock.Object); childVMMock.Setup(v => v.Children).Returns(enumerableChildren()); childVMMock.Setup(v => v.ISO).Returns(childMock.Object); childVMMock.Setup(v => v.Name).Returns(childName); childVMMock.Setup(v => v.Rowguid).Returns(childGUID); gc1VMMock = new Mock <IISOViewModel>(); gc1VMMock.Setup(v => v.Parent).Returns(childMock.Object); gc1VMMock.Setup(v => v.Children).Returns(Enumerable.Empty <ISerializableObject>()); gc1VMMock.Setup(v => v.Name).Returns(gcName); gc1VMMock.Setup(v => v.ISO).Returns(gc1Mock.Object); gc1VMMock.Setup(v => v.Rowguid).Returns(Guid.NewGuid()); gc2VMMock = new Mock <IISOViewModel>(); gc2VMMock.Setup(v => v.Parent).Returns(childMock.Object); gc2VMMock.Setup(v => v.Children).Returns(Enumerable.Empty <ISerializableObject>()); gc2VMMock.Setup(v => v.ISO).Returns(gc2Mock.Object); gc2VMMock.Setup(v => v.Name).Returns(gcName); gc2VMMock.Setup(v => v.Rowguid).Returns(Guid.NewGuid()); storeMock = new Mock <IISOViewModelStore>(); storeMock.Setup(s => s.addOrRetrieveVMForISO(rootMock.Object)).Returns(rootVMMock.Object); storeMock.Setup(s => s.addOrRetrieveVMForISO(childMock.Object)).Returns(childVMMock.Object); storeMock.Setup(s => s.addOrRetrieveVMForISO(gc1Mock.Object)).Returns(gc1VMMock.Object); storeMock.Setup(s => s.addOrRetrieveVMForISO(gc2Mock.Object)).Returns(gc2VMMock.Object); tree = new TreeViewModel(storeMock.Object); tree.addGenerator(childVMMock.Object); root = tree.Roots.First(); child = root.Children.First(); }
private void AddChildExecute(object cmdParameter) { INodeViewModel Node = GetOperationNode().AddChild(GetNextDataName(TreeNodeType.Page)); Node.IsSelected = true; Node.IsNodeEditable = true; PageTreeChanged(); CreatePageCommand cmd = new CreatePageCommand(this, Node, Node.Parent, Node.IndexInParent, _pageTree); _undoManager.Push(cmd); }
private void AddPageRequestExecute(Guid cmdParameter) { if (cmdParameter == Guid.Empty) { INodeViewModel Node = GetOperationNode().Add(GetNextDataName(TreeNodeType.Page)); Node.IsSelected = true; CreatePageCommand cmd = new CreatePageCommand(this, Node, Node.Parent, Node.IndexInParent, _pageTree); _undoManager.Push(cmd); this._ListEventAggregator.GetEvent <AddNewPageEvent>().Publish(Node.Guid); } }
private bool CanExecuteDown(object cmdParameter) { INodeViewModel node = GetOperationNode(); if (node.IsRootNode) { return(false); } int index = node.IndexInParent; int count = node.Parent.Children.Count(); return((index < count - 1) && _bVisible && !this._isMultiSelected); }
public INodeViewModel CreateHeader(INodeViewModel doc) { var fields = new List <INodeViewModel>(); var header = _nodeFactory.Create(doc, NodeType.DocumentHeader); fields.Add(_nodeFactory.Create(header, NodeType.DocumentNumber)); fields.Add(_nodeFactory.Create(header, NodeType.ProductChipher)); fields.Add(_nodeFactory.Create(header, NodeType.ArrayChipher)); fields.Add(_nodeFactory.Create(header, NodeType.Kc)); fields.Add(_nodeFactory.Create(header, NodeType.DocumentDate)); return(header); }
public void ProcessNode(INodeViewModel node, IEnumerable <IValidationRule> rules) { var validNode = node.As <NodeValidationDecorator>(); if (validNode == null) { return; } var results = rules.Select(rule => rule.Validate(node, _treeConductor)).ToArray(); validNode.ValidationState = new CollectionValidationResult(results); }
/// <summary> /// Select page in pagelist treeview /// </summary> /// <param name="parent"></param> /// <param name="pageGuid"> page guid which is select in editview</param> private void SelectPage(INodeViewModel parent, Guid pageGuid) { foreach (var item in parent.Children) { if (item.Guid == pageGuid) { _pageTree.Focus(); item.IsSelected = true; return; } SelectPage(item, pageGuid); } }
internal static bool IsDescent(INodeViewModel root, INodeViewModel node) { if (node == null) { return(false); } else if (root == node || node.Parent == root) { return(true); } else { return(IsDescent(root, node.Parent)); } }
public void Move(INodeViewModel newParentNode, int index) { _treeNodeObject.Move(newParentNode.TreeNodeObject, index); if (Parent != null) { Parent.Children.Remove(this); RefreshInfoCount(-1); } IsSelected = false; newParentNode.Children.Insert(index, this); this.Parent = newParentNode; IsSelected = true; }
public void OnCanvasClick(object e) { var eventArgs = e as RoutedEventArgs; var button = eventArgs.OriginalSource as Button; Point a = Mouse.GetPosition(button); if (a != null) { Point relPoint = button.TranslatePoint(a, button); INodeViewModel newNode = _viewModelProvider.GetNodeViewModel(_modelProvider.GetNode(a.X - button.ActualWidth, a.Y - button.ActualHeight)); Nodes.Add(newNode); } }
public TreeViewModel_ISOHierarchie_Test() { rootMock = new Mock<ISerializableObject>(); childMock = new Mock<ISerializableObject>(); var childGUID = Guid.NewGuid(); childMock.Setup(c => c.Rowguid).Returns(childGUID); gc1Mock = new Mock<ISerializableObject>(); gc2Mock = new Mock<ISerializableObject>(); rootVMMock = new Mock<IISOViewModel>(); rootVMMock.Setup(v => v.Parent).Returns(() => null); rootVMMock.Setup(v => v.ISO).Returns(rootMock.Object); rootVMMock.Setup(v => v.Name).Returns(rootName); rootVMMock.Setup(v => v.Rowguid).Returns(Guid.NewGuid()); childVMMock = new Mock<IISOViewModel>(); childVMMock.Setup(v => v.Parent).Returns(rootMock.Object); childVMMock.Setup(v => v.Children).Returns(enumerableChildren()); childVMMock.Setup(v => v.ISO).Returns(childMock.Object); childVMMock.Setup(v => v.Name).Returns(childName); childVMMock.Setup(v => v.Rowguid).Returns(childGUID); gc1VMMock = new Mock<IISOViewModel>(); gc1VMMock.Setup(v => v.Parent).Returns(childMock.Object); gc1VMMock.Setup(v => v.Children).Returns(Enumerable.Empty<ISerializableObject>()); gc1VMMock.Setup(v => v.Name).Returns(gcName); gc1VMMock.Setup(v => v.ISO).Returns(gc1Mock.Object); gc1VMMock.Setup(v => v.Rowguid).Returns(Guid.NewGuid()); gc2VMMock = new Mock<IISOViewModel>(); gc2VMMock.Setup(v => v.Parent).Returns(childMock.Object); gc2VMMock.Setup(v => v.Children).Returns(Enumerable.Empty<ISerializableObject>()); gc2VMMock.Setup(v => v.ISO).Returns(gc2Mock.Object); gc2VMMock.Setup(v => v.Name).Returns(gcName); gc2VMMock.Setup(v => v.Rowguid).Returns(Guid.NewGuid()); storeMock = new Mock<IISOViewModelStore>(); storeMock.Setup(s => s.addOrRetrieveVMForISO(rootMock.Object)).Returns(rootVMMock.Object); storeMock.Setup(s => s.addOrRetrieveVMForISO(childMock.Object)).Returns(childVMMock.Object); storeMock.Setup(s => s.addOrRetrieveVMForISO(gc1Mock.Object)).Returns(gc1VMMock.Object); storeMock.Setup(s => s.addOrRetrieveVMForISO(gc2Mock.Object)).Returns(gc2VMMock.Object); tree = new TreeViewModel(storeMock.Object); tree.addGenerator(childVMMock.Object); root = tree.Roots.First(); child = root.Children.First(); }
public void ArrangeNodes() { if (Nodes.All(x => x.Visual != null)) { var loadedNodes = nodes.Where(x => x.Visual != null).ToList(); //check if nodes have uniform height bool uniformNodeHeights = loadedNodes.Select(x => x.Height).Distinct().Count() == 1; var visuals = loadedNodes.Select(x => x.Visual).ToList(); bool uniformVisualHeights = visuals.Select(x => x.Height).Distinct().Count() == 1; double tallestNodeHeight = loadedNodes.Max(x => x.Height); INodeViewModel tallestNode = loadedNodes.First(x => x.Height == tallestNodeHeight); double tallestVisualHeight = visuals.Max(x => x.ActualHeight); var tallestVisual = visuals.First(x => x.ActualHeight == tallestVisualHeight); var totalHeight = tallestNodeHeight / 2 + tallestVisualHeight; double xPos = 0; foreach (var node in loadedNodes) { node.X = xPos; if (!uniformNodeHeights && !uniformVisualHeights) { node.Y = tallestNodeHeight / 2 - node.Height / 2; } else if (!uniformVisualHeights) { if (node.Visual == tallestVisual) { node.Y = 0; } else { node.Y = 0; } } else if (!uniformNodeHeights) { } else { node.Y = 0; } xPos = node.RightEdgeViewModel.X + node.RightEdgeViewModel.Width; } } UpdateVisual(); }
public static T As <T>(this INodeViewModel node) where T : class, INodeViewModel { var findNode = node as T; if (findNode == null) { var decoratedNode = node as IDecoratedNode; if (decoratedNode == null) { return(null); } return(decoratedNode.Node.As <T>()); } return(findNode); }
private void OnLoaded(object sender, RoutedEventArgs e) { this.CreateConnectorVisual(); this.AddVisualChild(this.path); this.PreviewMouseLeftButtonDown -= this.Clicked; this.PreviewMouseLeftButtonDown += this.Clicked; this.parentViewModel.PropertyChanged -= this.InvalidateOnChanges; this.parentViewModel.PropertyChanged += this.InvalidateOnChanges; this.viewModel.PropertyChanged -= this.InvalidateOnChanges; this.viewModel.PropertyChanged += this.InvalidateOnChanges; if (this.viewModel.StartNode != null) { this.start = this.viewModel.StartNode; this.viewModel.StartNode.PropertyChanged -= this.InvalidateOnChanges; this.viewModel.StartNode.PropertyChanged += this.InvalidateOnChanges; } if (this.viewModel.StopNode != null) { this.stop = this.viewModel.StopNode; this.viewModel.StopNode.PropertyChanged -= this.InvalidateOnChanges; this.viewModel.StopNode.PropertyChanged += this.InvalidateOnChanges; } }
/// <summary> /// Adds the node. /// </summary> /// <param name="node">The node.</param> private void AddNode(INodeViewModel node) { Items.Add(node); SelectedItem = node; }